Skip to content

Commit ca2fa97

Browse files
feat(overmind-devtools): update getter values as well
1 parent 6bc269c commit ca2fa97

File tree

7 files changed

+43
-18
lines changed

7 files changed

+43
-18
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ensureApp,
2929
addClientMessages,
3030
updateOperatorAsync,
31+
runGetterMutation,
3132
} from './operators'
3233

3334
export const onInitialize: OnInitialize = async ({
@@ -64,6 +65,7 @@ const handleClientMessage: Operator<Message, any> = pipe(
6465
[ExecutionType.OPERATOR_END]: updateOperator,
6566
[ExecutionType.ACTION_END]: updateAction,
6667
[ExecutionType.OPERATOR_ASYNC]: updateOperatorAsync,
68+
[ExecutionType.GETTER]: runGetterMutation,
6769
})
6870
)
6971

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
AsyncOperatorMessage,
2323
EventType,
2424
Effect,
25+
GetterMessage,
2526
} from './types'
2627
import {
2728
createApp,
@@ -39,6 +40,16 @@ export const ensureCurrentApp: Operator<Message> = action(
3940
}
4041
)
4142

43+
export const runGetterMutation: Operator<GetterMessage> = action(
44+
({ value: message, state }) => {
45+
runMutation(state.apps[message.appName].state)({
46+
method: 'set',
47+
path: message.data.path,
48+
args: [message.data.value],
49+
})
50+
}
51+
)
52+
4253
export const setPortExists: Operator<any> = action(({ state }) => {
4354
state.error = 'PORT_EXISTS'
4455
})

packages/node_modules/overmind-devtools/src/overmind/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export enum ExecutionType {
160160
OPERATOR_END = 'operator:end',
161161
OPERATOR_ASYNC = 'operator:async',
162162
ACTION_END = 'action:end',
163+
GETTER = 'getter',
163164
}
164165

165166
export enum AppMessageType {
@@ -177,6 +178,11 @@ export type InitMessage = AppMessage<{
177178
state: object
178179
}>
179180

181+
export type GetterMessage = AppMessage<{
182+
path: string
183+
value: any
184+
}>
185+
180186
export type FlushMessage = AppMessage<
181187
Execution & {
182188
flushId: number

packages/node_modules/overmind/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ export class Overmind<Config extends Configuration> implements Configuration {
157157
{
158158
devmode: !IS_PRODUCTION,
159159
dynamicWrapper: (_, path, func) => func(eventHub, proxyStateTree, path),
160+
onGetter: (path, value) =>
161+
this.eventHub.emit(EventType.GETTER, {
162+
path,
163+
value: safeValue(value),
164+
}),
160165
}
161166
)
162167

packages/node_modules/overmind/src/internalTypes.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ export enum EventType {
3737
EFFECT = 'effect',
3838
DERIVED = 'derived',
3939
DERIVED_DIRTY = 'derived:dirty',
40-
REACTION_ADD = 'reaction:add',
41-
REACTION_UPDATE = 'reaction:update',
42-
REACTION_REMOVE = 'reaction:remove',
4340
COMPONENT_ADD = 'component:add',
4441
COMPONENT_UPDATE = 'component:update',
4542
COMPONENT_REMOVE = 'component:remove',
43+
GETTER = 'getter',
4644
}
4745

4846
export type Execution = {
@@ -99,21 +97,9 @@ export interface Events {
9997
error: string
10098
effectId: number
10199
}
102-
[EventType.REACTION_ADD]: {
100+
[EventType.GETTER]: {
103101
path: string
104-
statePath: string
105-
updateCount: number
106-
}
107-
[EventType.REACTION_UPDATE]: {
108-
path: string
109-
statePath: string
110-
updateCount: number
111-
flushId: number
112-
}
113-
[EventType.REACTION_REMOVE]: {
114-
path: string
115-
statePath: string
116-
updateCount: number
102+
value: any
117103
}
118104
[EventType.COMPONENT_ADD]: {
119105
componentId: number | string

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,21 @@ export class Proxifier {
258258
const descriptor = Object.getOwnPropertyDescriptor(target, prop)
259259

260260
if (descriptor && 'get' in descriptor) {
261-
return descriptor.get.call(proxifier.getProxyFromCache(path))
261+
const value = descriptor.get.call(
262+
proxifier.getProxyFromCache(path)
263+
)
264+
265+
if (
266+
proxifier.tree.master.options.devmode &&
267+
proxifier.tree.master.options.onGetter
268+
) {
269+
proxifier.tree.master.options.onGetter(
270+
proxifier.concat(path, prop),
271+
value
272+
)
273+
}
274+
275+
return value
262276
}
263277

264278
const trackingTree = proxifier.getTrackingTree()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface ITrackStateTree<T extends object> {
6464
export interface IOptions {
6565
devmode?: boolean
6666
dynamicWrapper?: Function
67+
onGetter?: Function
6768
}
6869

6970
export interface IFlushCallback {

0 commit comments

Comments
 (0)