Skip to content

Commit 89a9abb

Browse files
feat(overmind): expose mutation listeners and reaction on context
1 parent b7d365e commit 89a9abb

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

packages/node_modules/overmind/src/Overmind.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ export class Overmind<ThisConfig extends IConfiguration>
374374
proxyStateTree: this.proxyStateTreeInstance,
375375
effects: this.trackEffects(this.effects, execution),
376376
addNamespace: this.addNamespace.bind(this),
377+
reaction: this.reaction.bind(this),
378+
addMutationListener: this.addMutationListener.bind(this),
379+
addFlushListener: this.addFlushListener.bind(this),
377380
}
378381
}
379382
private addNamespace(

packages/node_modules/overmind/src/operator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ export function createOperator<ThisConfig extends IConfiguration>(
194194
effects: context.effects,
195195
actions: context.actions,
196196
execution: context.execution,
197+
addFlushListener: context.addFlushListener,
198+
addMutationListener: context.addMutationListener,
199+
reaction: context.reaction,
197200
},
198201
context.value,
199202
(err, value, options = {}) => {
@@ -298,6 +301,9 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
298301
effects: context.effects,
299302
actions: context.actions,
300303
execution: context.execution,
304+
addFlushListener: context.addFlushListener,
305+
addMutationListener: context.addMutationListener,
306+
reaction: context.reaction,
301307
},
302308
process.env.NODE_ENV === 'production'
303309
? context.value

packages/node_modules/overmind/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ResolveAction, ContextFunction } from './internalTypes'
22
import { IS_OPERATOR } from './utils'
3+
import { IMutationCallback, IFlushCallback } from 'proxy-state-tree'
34

45
/** ===== PUBLIC API
56
*/
@@ -19,6 +20,9 @@ export type IContext<T extends IConfiguration> = {
1920
state: T['state']
2021
actions: { [K in keyof T['actions']]: ResolveAction<T['actions'][K]> }
2122
effects: T['effects']
23+
reaction: IReaction<{ state: T['state'] }>
24+
addMutationListener: (cb: IMutationCallback) => () => void
25+
addFlushListener: (cb: IFlushCallback) => () => void
2226
}
2327

2428
export interface IAction<I, O> extends ContextFunction<I, O> {}
@@ -27,7 +31,7 @@ export interface IOperator<I, O> extends ContextFunction<I, O> {
2731
[IS_OPERATOR]: true
2832
}
2933

30-
export interface IReaction<T extends IContext<any>> {
34+
export interface IReaction<T extends { state?: IState }> {
3135
<O>(
3236
stateCallback: (state: T['state']) => O,
3337
updateCallback: (value: O) => void,

0 commit comments

Comments
 (0)