Skip to content

Commit ea17a04

Browse files
feat(overmind): expose addMutationListener and rename existing to addFlushListener
BREAKING CHANGE: addMutationListener is now addFlushListener
1 parent 28be363 commit ea17a04

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

packages/node_modules/overmind-angular/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
7575
name: this.constructor.name || '',
7676
paths: Array.from(paths),
7777
})
78-
this.__listener = overmind.addMutationListener(paths, (flushId) => {
78+
this.__listener = overmind.addFlushListener(paths, (flushId) => {
7979
this.__shouldUpdatePaths = true
8080
if (this.cdr) {
8181
this.cdr.markForCheck()

packages/node_modules/overmind-components/src/Component.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,25 @@ export class Component {
7070
children: this.children.length === 1 ? this.children[0] : this.children,
7171
}) || new Null()
7272
const paths = app.clearTrackState(trackId)
73-
this.mutationListener = app.addMutationListener(
74-
paths,
75-
(flushId, isAsync) => {
76-
app.eventHub.emitAsync('component:update', {
77-
componentId: this.componentId,
78-
componentInstanceId: this.componentInstanceId,
79-
name: this.name,
80-
flushId,
81-
paths: Array.from(paths),
82-
})
83-
84-
if (isAsync && !this.asyncRender) {
85-
this.asyncRender = requestAnimationFrame(() => {
86-
this.asyncRender = null
87-
this.reconcile(this, true)
88-
})
89-
} else if (!isAsync) {
90-
cancelAnimationFrame(this.asyncRender)
73+
this.mutationListener = app.addFlushListener(paths, (flushId, isAsync) => {
74+
app.eventHub.emitAsync('component:update', {
75+
componentId: this.componentId,
76+
componentInstanceId: this.componentInstanceId,
77+
name: this.name,
78+
flushId,
79+
paths: Array.from(paths),
80+
})
81+
82+
if (isAsync && !this.asyncRender) {
83+
this.asyncRender = requestAnimationFrame(() => {
84+
this.asyncRender = null
9185
this.reconcile(this, true)
92-
}
86+
})
87+
} else if (!isAsync) {
88+
cancelAnimationFrame(this.asyncRender)
89+
this.reconcile(this, true)
9390
}
94-
)
91+
})
9592
app.eventHub.emitAsync('component:add', {
9693
componentId: this.componentId,
9794
componentInstanceId: this.componentInstanceId,

packages/node_modules/overmind-react/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const createHook = <A extends Overmind<Configuration>>(overmind: A) => {
7171
const thisComponentInstanceId = componentInstanceId++
7272
setOvermindState({
7373
componentInstanceId: thisComponentInstanceId,
74-
listener: overmind.addMutationListener(paths, (flushId) => {
74+
listener: overmind.addFlushListener(paths, (flushId) => {
7575
overmind.eventHub.emitAsync(EventType.COMPONENT_UPDATE, {
7676
componentId: component.__componentId,
7777
componentInstanceId: thisComponentInstanceId,
@@ -165,7 +165,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
165165
name: Component.name || '',
166166
paths: Array.from(paths),
167167
})
168-
this.__mutationListener = overmind.addMutationListener(
168+
this.__mutationListener = overmind.addFlushListener(
169169
paths,
170170
(flushId) => {
171171
if (this.__isUnmounting) {
@@ -239,7 +239,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
239239
name: Component.name || '',
240240
paths: Array.from(paths),
241241
})
242-
this.__mutationListener = overmind.addMutationListener(
242+
this.__mutationListener = overmind.addFlushListener(
243243
paths,
244244
(flushId) => {
245245
if (this.__isUnmounting) {

packages/node_modules/overmind-vue/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => <
7676
name: componentOptions.name || this.name || '',
7777
paths: Array.from(paths),
7878
})
79-
this.__proxyStateTreeListener = overmind.addMutationListener(
79+
this.__proxyStateTreeListener = overmind.addFlushListener(
8080
paths,
8181
(flushId) => {
8282
overmind.eventHub.emitAsync(EventType.COMPONENT_UPDATE, {

packages/node_modules/overmind/src/derived.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('Derived', () => {
7272
app.state.upperFoo
7373
return app.clearTrackState(trackId)
7474
}
75-
app.addMutationListener(render(), () => {
75+
app.addFlushListener(render(), () => {
7676
renderCount++
7777
})
7878
app.actions.changeFoo()

packages/node_modules/overmind/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,12 @@ export class Overmind<Config extends Configuration> implements Configuration {
463463
clearTrackState(id: number, cb?: () => void) {
464464
return this.proxyStateTree.clearPathsTracking(id, cb)
465465
}
466-
addMutationListener(paths, cb) {
466+
addFlushListener(paths, cb) {
467467
return this.proxyStateTree.addFlushListener(paths, cb)
468468
}
469+
addMutationListener(cb) {
470+
return this.proxyStateTree.addMutationListener(cb)
471+
}
469472
createReactionFactory(prefix: string) {
470473
const reactions: Reaction[] = []
471474
const instance = this

0 commit comments

Comments
 (0)