Skip to content

Commit 8c4df13

Browse files
committed
Add reactor-fns-tests
1 parent e2723f4 commit 8c4df13

File tree

6 files changed

+754
-126
lines changed

6 files changed

+754
-126
lines changed

src/reactor.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { isKeyPath } from './key-path'
55
import { isGetter, fromKeyPath } from './getter'
66
import { toJS } from './immutable-helpers'
77
import { isArray, toFactory } from './utils'
8-
import { ReactorState, ObserverStoreMap } from './reactor/records'
8+
import { ReactorState, ObserverState } from './reactor/records'
99

1010
/**
1111
* State is stored in NuclearJS Reactors. Reactors
@@ -24,7 +24,7 @@ class Reactor {
2424

2525
this.prevReactorState = initialReactorState
2626
this.reactorState = initialReactorState
27-
this.observerStoreMap = new ObserverStoreMap()
27+
this.observerState = new ObserverState()
2828

2929
this.ReactMixin = createReactMixin(this)
3030

@@ -76,10 +76,10 @@ class Reactor {
7676
handler = getter
7777
getter = []
7878
}
79-
let { observerStoreMap, entry } = fns.addObserver(this.observerStoreMap, getter, handler)
80-
this.observerStoreMap = observerStoreMap;
79+
let { observerState, entry } = fns.addObserver(this.observerState, getter, handler)
80+
this.observerState = observerState;
8181
return () => {
82-
this.observerStoreMap = fns.removeObserverByEntry(this.observerStoreMap, entry)
82+
this.observerState = fns.removeObserverByEntry(this.observerState, entry)
8383
}
8484
}
8585

@@ -91,7 +91,7 @@ class Reactor {
9191
throw new Error('Must call unobserve with a Getter')
9292
}
9393

94-
this.observerStoreMap = fns.removeObserver(this.observerStoreMap, getter, handler)
94+
this.observerState = fns.removeObserver(this.observerState, getter, handler)
9595
}
9696

9797
/**
@@ -177,6 +177,7 @@ class Reactor {
177177
const newState = fns.reset(this.reactorState)
178178
this.reactorState = newState
179179
this.prevReactorState = newState
180+
this.observerState = new ObserverState()
180181
}
181182

182183
/**
@@ -196,10 +197,10 @@ class Reactor {
196197

197198
let observerIdsToNotify = Immutable.Set().withMutations(set => {
198199
// notify all observers
199-
set.union(this.observerStoreMap.get('any'))
200+
set.union(this.observerState.get('any'))
200201

201202
dirtyStores.forEach(id => {
202-
const entries = this.observerStoreMap.getIn(['stores', id])
203+
const entries = this.observerState.getIn(['stores', id])
203204
if (!entries) {
204205
return
205206
}
@@ -208,7 +209,7 @@ class Reactor {
208209
})
209210

210211
observerIdsToNotify.forEach((observerId) => {
211-
const entry = this.observerStoreMap.getIn(['observersMap', observerId])
212+
const entry = this.observerState.getIn(['observersMap', observerId])
212213
if (!entry) {
213214
// don't notify here in the case a handler called unobserve on another observer
214215
return
@@ -228,7 +229,7 @@ class Reactor {
228229
}
229230
})
230231

231-
const nextReactorState = this.reactorState.set('dirtyStores', Immutable.Set())
232+
const nextReactorState = fns.resetDirtyStores(this.reactorState)
232233

233234
this.prevReactorState = nextReactorState
234235
this.reactorState = nextReactorState

0 commit comments

Comments
 (0)