Skip to content

Commit 5adcd15

Browse files
perf(proxy-state-tree): remove proxy cache and cache on the objects
1 parent 089383f commit 5adcd15

File tree

10 files changed

+216
-405
lines changed

10 files changed

+216
-405
lines changed

packages/node_modules/overmind-devtools-client/src/BackendConnector.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,13 @@ class WebsocketConnector {
8585
}
8686

8787
export class BackendConnector extends WebsocketConnector {
88-
buffer = []
89-
onMessageCallback: MessageCallback
90-
constructor() {
91-
super()
92-
requestAnimationFrame(this.loopBufferOnFrame)
93-
}
94-
private loopBufferOnFrame = () => {
95-
if (this.buffer.length) {
96-
const messages = this.buffer.splice(0, 10)
97-
this.onMessageCallback(messages)
98-
}
99-
requestAnimationFrame(this.loopBufferOnFrame)
100-
}
10188
onMessage = (onMessage: MessageCallback) => {
102-
this.onMessageCallback = onMessage
10389
this.on('message', (message) => {
104-
this.buffer.push(message)
90+
onMessage(message)
10591
})
10692
}
10793
onDisconnect = (onDisconnect: (name: string) => void) => {
10894
this.on('disconnect', (name) => {
109-
this.buffer.length = 0
11095
onDisconnect(name)
11196
})
11297
}

packages/node_modules/overmind-devtools-client/src/overmind/actions.ts

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Action, pipe, OnInitialize, Operator, forEach } from 'overmind'
1+
import {
2+
Action,
3+
pipe,
4+
OnInitialize,
5+
Operator,
6+
forEach,
7+
AsyncAction,
8+
} from 'overmind'
29
import {
310
Message,
411
Tab,
@@ -10,32 +17,30 @@ import {
1017
import * as o from './operators'
1118
import { isValidJson, createApp } from './utils'
1219

13-
export const onMessage: Operator<Message[]> = forEach(
14-
pipe(
15-
o.ensureCurrentApp(),
16-
o.ensureApp(),
17-
o.addClientMessages(),
18-
o.getMessages(),
19-
o.forkEachMessage({
20-
[ExecutionType.INIT]: o.addStateAndActions(),
21-
[ExecutionType.RE_INIT]: o.addStateAndActions(),
22-
[ExecutionType.FLUSH]: o.addFlush(),
23-
[ExecutionType.DERIVED]: o.updateDerived(),
24-
[ExecutionType.MUTATIONS]: o.addMutations(),
25-
[ExecutionType.EFFECT]: o.updateEffect(),
26-
[ExecutionType.STATE]: o.updateState(),
27-
[ExecutionType.COMPONENT_ADD]: o.addComponent(),
28-
[ExecutionType.COMPONENT_UPDATE]: o.updateComponent(),
29-
[ExecutionType.COMPONENT_REMOVE]: o.removeComponent(),
30-
[ExecutionType.DERIVED_DIRTY]: o.updateFlushWithDerived(),
31-
[ExecutionType.ACTION_START]: o.addAction(),
32-
[ExecutionType.OPERATOR_START]: o.addOperator(),
33-
[ExecutionType.OPERATOR_END]: o.updateOperator(),
34-
[ExecutionType.ACTION_END]: o.updateAction(),
35-
[ExecutionType.OPERATOR_ASYNC]: o.updateOperatorAsync(),
36-
[ExecutionType.GETTER]: o.runGetterMutation(),
37-
})
38-
)
20+
export const onMessage: Operator<Message> = pipe(
21+
o.ensureCurrentApp(),
22+
o.ensureApp(),
23+
o.addClientMessages(),
24+
o.getMessages(),
25+
o.forkEachMessage({
26+
[ExecutionType.INIT]: o.addStateAndActions(),
27+
[ExecutionType.RE_INIT]: o.addStateAndActions(),
28+
[ExecutionType.FLUSH]: o.addFlush(),
29+
[ExecutionType.DERIVED]: o.updateDerived(),
30+
[ExecutionType.MUTATIONS]: o.addMutations(),
31+
[ExecutionType.EFFECT]: o.updateEffect(),
32+
[ExecutionType.STATE]: o.updateState(),
33+
[ExecutionType.COMPONENT_ADD]: o.addComponent(),
34+
[ExecutionType.COMPONENT_UPDATE]: o.updateComponent(),
35+
[ExecutionType.COMPONENT_REMOVE]: o.removeComponent(),
36+
[ExecutionType.DERIVED_DIRTY]: o.updateFlushWithDerived(),
37+
[ExecutionType.ACTION_START]: o.addAction(),
38+
[ExecutionType.OPERATOR_START]: o.addOperator(),
39+
[ExecutionType.OPERATOR_END]: o.updateOperator(),
40+
[ExecutionType.ACTION_END]: o.updateAction(),
41+
[ExecutionType.OPERATOR_ASYNC]: o.updateOperatorAsync(),
42+
[ExecutionType.GETTER]: o.runGetterMutation(),
43+
})
3944
)
4045

4146
export const setError: Action<string> = ({ state }, error) => {
@@ -198,3 +203,23 @@ export const toggleRuntimeConfig: Action = ({ state }) => {
198203
export const refreshApp: Action = ({ state, effects }) => {
199204
effects.connector.sendMessage(state.currentAppName, 'refresh')
200205
}
206+
207+
export const setAppDataFromStorage: AsyncAction<{
208+
appName: string
209+
actions: string[]
210+
}> = async ({ state, effects }, { appName, actions }) =>
211+
Promise.all([
212+
effects.storage.get<string>(`${appName}.selectedActionQuery`),
213+
effects.storage.get<string>(`${appName}.actionQueryPayload`),
214+
effects.storage.get<Tab>(`${appName}.currentTab`),
215+
]).then(([selectedActionQuery, actionQueryPayload, tab]) => {
216+
const actionQuery =
217+
selectedActionQuery && actions.includes(selectedActionQuery)
218+
? selectedActionQuery
219+
: ''
220+
state.apps[appName].selectedActionQuery = actionQuery
221+
state.apps[appName].actionQueryPayload = actionQuery
222+
? actionQueryPayload
223+
: ''
224+
state.currentTab = tab || state.currentTab
225+
})

packages/node_modules/overmind-devtools-client/src/overmind/operators.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const addFlush: () => Operator<FlushMessage> = () =>
7979
})
8080

8181
export const ensureApp: () => Operator<Message> = () =>
82-
mutate(({ state, effects }, message) => {
82+
mutate(({ state, effects, actions }, message) => {
8383
if (
8484
!state.apps[message.appName] ||
8585
message.messages[0].type === ExecutionType.INIT
@@ -89,21 +89,9 @@ export const ensureApp: () => Operator<Message> = () =>
8989
})
9090

9191
// Do not use await, as it will block further execution, this stuff has to be sync
92-
Promise.all([
93-
effects.storage.get<string>(`${message.appName}.selectedActionQuery`),
94-
effects.storage.get<string>(`${message.appName}.actionQueryPayload`),
95-
effects.storage.get<Tab>(`${message.appName}.currentTab`),
96-
]).then(([selectedActionQuery, actionQueryPayload, tab]) => {
97-
const actionQuery =
98-
selectedActionQuery &&
99-
message.messages[0].data.actions.includes(selectedActionQuery)
100-
? selectedActionQuery
101-
: ''
102-
state.apps[message.appName].selectedActionQuery = actionQuery
103-
state.apps[message.appName].actionQueryPayload = actionQuery
104-
? actionQueryPayload
105-
: ''
106-
state.currentTab = tab || state.currentTab
92+
actions.setAppDataFromStorage({
93+
appName: message.appName,
94+
actions: message.messages[0].data.actions,
10795
})
10896
}
10997
})

packages/node_modules/overmind-devtools-vscode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"displayName": "Overmind Devtools VSCode",
44
"description": "Devtools for Overmind",
55
"publisher": "christianalfoni",
6-
"version": "0.0.11",
6+
"version": "0.0.12",
77
"repository": {
8-
"type" : "git",
9-
"url" : "https://github.com/cerebral/overmind.git"
8+
"type": "git",
9+
"url": "https://github.com/cerebral/overmind.git"
1010
},
1111
"engines": {
1212
"vscode": "^1.35.0"

packages/node_modules/proxy-state-tree/src/MutationTree.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ export class MutationTree<T extends object> implements IMutationTree<T> {
7979
dispose() {
8080
this.isTracking = false
8181
this.mutationCallbacks.length = 0
82-
83-
if (this.proxifier !== this.master.proxifier) {
84-
this.proxifier.dispose()
85-
}
86-
8782
this.proxifier = this.master.proxifier
8883

8984
return this

0 commit comments

Comments
 (0)