Skip to content

Commit 31be0c2

Browse files
feat(overmind): remove reactions
BREAKING CHANGE: reactions are removed
1 parent ea17a04 commit 31be0c2

File tree

14 files changed

+8
-295
lines changed

14 files changed

+8
-295
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ export type TConnect<Config extends Configuration> = {
77
overmind: {
88
state: TApp<Config>['state']
99
actions: TApp<Config>['actions']
10-
reaction: (
11-
name: string,
12-
stateCb: (state: TApp<Config>['state']) => any,
13-
Function
14-
) => void
1510
}
1611
}
1712

@@ -27,15 +22,11 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
2722
const targetNgAfterContentInit = target.prototype.ngAfterContentInit
2823
const targetNgAfterViewInit = target.prototype.ngAfterViewInit
2924
const targetNgAfterViewChecked = target.prototype.ngAfterViewChecked
30-
const reactionFactory = overmind.createReactionFactory(
31-
target.constructor.name
32-
)
3325

3426
target.prototype.ngOnInit = function() {
3527
this.overmind = {
3628
state: overmind.state,
3729
actions: overmind.actions,
38-
reaction: reactionFactory.add,
3930
}
4031
this.__componentInstanceId = componentInstanceId++
4132
this.__shouldUpdatePaths = false
@@ -133,7 +124,6 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
133124
name: this.constructor.name || '',
134125
})
135126
this.__listener.dispose()
136-
this.__reactionFactory.dispose()
137127
}
138128

139129
return target

packages/node_modules/overmind-react/src/index.test.tsx

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -117,58 +117,6 @@ describe('React', () => {
117117
expect(tree2).toMatchSnapshot()
118118
})
119119

120-
test('should connect reactions to components', () => {
121-
expect.assertions(2)
122-
let reactionCount = 0
123-
const doThis: Action = ({ state }) => (state.foo = 'bar2')
124-
125-
const config = {
126-
state: {
127-
foo: 'bar',
128-
},
129-
actions: {
130-
doThis,
131-
},
132-
}
133-
type IConfig = {
134-
state: {
135-
foo: typeof config.state.foo
136-
}
137-
actions: {
138-
doThis: typeof doThis
139-
}
140-
}
141-
142-
const app = new Overmind(config)
143-
144-
type Action<Input = void> = TAction<IConfig, Input>
145-
146-
const connect = createConnect(app)
147-
148-
class Component extends React.Component<TConnect<IConfig>> {
149-
componentDidMount() {
150-
this.props.overmind.reaction(
151-
'my-reaction',
152-
(state) => state.foo,
153-
() => {
154-
reactionCount++
155-
}
156-
)
157-
}
158-
render() {
159-
const { overmind } = this.props
160-
return <h1>{overmind.state.foo}</h1>
161-
}
162-
}
163-
const ConnectedComponent = connect(Component)
164-
const instance = renderer.create(<ConnectedComponent />)
165-
app.actions.doThis()
166-
expect(reactionCount).toBe(1)
167-
instance.unmount()
168-
app.actions.doThis()
169-
expect(reactionCount).toBe(1)
170-
})
171-
172120
test('should preserve component name', () => {
173121
const app = new Overmind({})
174122
const connect = createConnect(app)

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ export type TConnect<Config extends Configuration> = {
2929
overmind: {
3030
state: TApp<Config>['state']
3131
actions: TApp<Config>['actions']
32-
reaction: (
33-
name: string,
34-
stateCb: (state: TApp<Config>['state']) => any,
35-
Function
36-
) => void
3732
}
3833
}
3934

@@ -194,9 +189,6 @@ export const createConnect = <A extends Overmind<Configuration>>(
194189
__isUnmounting: boolean
195190
__componentId: number
196191
__componentInstanceId = componentInstanceId++
197-
__reactionFactory = overmind.createReactionFactory(
198-
Component.name || Component.displayName || 'Component'
199-
)
200192
componentWillUnmount() {
201193
this.__isUnmounting = true
202194
if (this.__mutationListener) {
@@ -207,7 +199,6 @@ export const createConnect = <A extends Overmind<Configuration>>(
207199
})
208200
this.__mutationListener.dispose()
209201
}
210-
this.__reactionFactory.dispose()
211202
}
212203
renderStatelessComponent() {
213204
const trackId = overmind.trackState()
@@ -216,7 +207,6 @@ export const createConnect = <A extends Overmind<Configuration>>(
216207
overmind: {
217208
state: overmind.state,
218209
actions: overmind.actions,
219-
reaction: this.__reactionFactory.add,
220210
__componentInstanceId: this.__componentInstanceId,
221211
},
222212
}),
@@ -264,7 +254,6 @@ export const createConnect = <A extends Overmind<Configuration>>(
264254
overmind: {
265255
state: overmind.state,
266256
actions: overmind.actions,
267-
reaction: this.__reactionFactory.add,
268257
__componentInstanceId: this.__componentInstanceId,
269258
},
270259
}) as any)

packages/node_modules/overmind-vue/src/Index.test.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,4 @@ describe('Vue', () => {
4343
done()
4444
})
4545
})
46-
it('should expose reaction', (done) => {
47-
expect.assertions(1)
48-
let hasReacted = false
49-
const app = new Overmind({
50-
state: {
51-
foo: 'bar',
52-
},
53-
actions: {
54-
changeFoo: ({ state }) => (state.foo = 'bar2'),
55-
},
56-
})
57-
const connect = createConnect(app)
58-
const instance = new Vue(
59-
connect({
60-
el: dom.window.document.createElement('div'),
61-
mounted() {
62-
this.overmind.reaction(
63-
(state) => state.foo,
64-
() => {
65-
hasReacted = true
66-
}
67-
)
68-
},
69-
})
70-
)
71-
Vue.nextTick(() => {
72-
instance.overmind.actions.changeFoo()
73-
expect(hasReacted).toBe(true)
74-
done()
75-
})
76-
})
7746
})

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ export type TConnect<Config extends Configuration> = {
55
overmind: {
66
state: TApp<Config>['state']
77
actions: TApp<Config>['actions']
8-
reaction: (
9-
name: string,
10-
stateCb: (state: TApp<Config>['state']) => any,
11-
Function
12-
) => void
138
}
149
}
1510

@@ -48,14 +43,10 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => <
4843
// the state to the component as "store",
4944
// allowing templates to access it
5045
componentOptions.beforeMount = function() {
51-
this.__reactionFactory = overmind.createReactionFactory(
52-
this.name || this.displayName
53-
)
5446
this.__componentInstanceId = componentInstanceId++
5547
this.overmind = {
5648
state: overmind.state,
5749
actions: overmind.actions,
58-
reaction: this.__reactionFactory.add,
5950
}
6051
this.__trackId = overmind.trackState()
6152
beforeMount && beforeMount.call(this)
@@ -115,7 +106,6 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => <
115106
})
116107

117108
this.__proxyStateTreeListener && this.__proxyStateTreeListener.dispose()
118-
this.__reactionFactory && this.__reactionFactory.dispose()
119109
beforeDestroy && beforeDestroy.call(this)
120110
}
121111

packages/node_modules/overmind/src/index.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
ResolveState,
1111
} from './internalTypes'
1212
import { proxifyEffects } from './proxyfyEffects'
13-
import { Reaction } from './reaction'
1413
import {
1514
Configuration,
1615
TAction,
@@ -377,13 +376,6 @@ export class Overmind<Config extends Configuration> implements Configuration {
377376
},
378377
{}
379378
)
380-
Object.keys(reactions).forEach((name) => {
381-
const reaction = new Reaction(eventHub, proxyStateTree, name)
382-
reaction.create(
383-
reactions[name][0],
384-
this.createAction(name, reactions[name][1])
385-
)
386-
})
387379
}
388380
private getState(configuration: Configuration) {
389381
let state = {}
@@ -469,30 +461,6 @@ export class Overmind<Config extends Configuration> implements Configuration {
469461
addMutationListener(cb) {
470462
return this.proxyStateTree.addMutationListener(cb)
471463
}
472-
createReactionFactory(prefix: string) {
473-
const reactions: Reaction[] = []
474-
const instance = this
475-
return {
476-
add(
477-
name: string,
478-
stateCb: (state: ResolveState<Config['state']>) => any,
479-
cb: Function
480-
) {
481-
const reaction = new Reaction(
482-
instance.eventHub,
483-
instance.proxyStateTree,
484-
prefix + '.' + name
485-
)
486-
reaction.create(stateCb, cb)
487-
488-
reactions.push(reaction)
489-
},
490-
dispose() {
491-
reactions.forEach((reaction) => reaction.destroy())
492-
reactions.length = 0
493-
},
494-
}
495-
}
496464
}
497465

498466
/*

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

Lines changed: 0 additions & 69 deletions
This file was deleted.

packages/node_modules/overmind/src/reaction.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

packages/overmind-website/api/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The base configuration of your application is:
44

5-
`{ state, actions, effects, reactions }`
5+
`{ state, actions, effects }`
66

77
When your application grows it will be necessary to split up your configuration. Overmind provides some helpers allowing you to structure and scale up your configuration.
88

0 commit comments

Comments
 (0)