Skip to content

Commit

Permalink
Revert "feature(hooks): log initial state (#69)"
Browse files Browse the repository at this point in the history
This reverts commit d57d69a.
  • Loading branch information
yoshuawuyts committed Feb 12, 2017
1 parent 987cac2 commit 0391402
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
3 changes: 0 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ function dispatcher (hooks) {
// state rather than indvidual chunks, so we apply it outside the loop
if (!stateCalled && opts.state !== false) {
_state = wrapHook(_state, initialStateWraps)
if (onStateChangeHooks.length) {
applyHook(onStateChangeHooks, _state, {}, {}, 'init', createSend)
}
}

if (!opts.noSubscriptions) subsCalled = true
Expand Down
40 changes: 11 additions & 29 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,19 +490,13 @@ tape('handlers: subscriptions', (t) => {

tape('hooks: onStateChange', (t) => {
t.test('should be called whenever state changes', (t) => {
t.plan(5)
var called = false
t.plan(4)
const store = barracks({
onStateChange: (state, data, prev, caller, createSend) => {
if (!called) {
t.deepEqual(state, { count: 1 }, 'state is equal on first try')
called = true
} else {
t.deepEqual(data, { count: 3 }, 'action is equal')
t.deepEqual(state, { count: 4 }, 'state is equal')
t.deepEqual(prev, { count: 1 }, 'prev is equal')
t.equal(caller, 'increment', 'caller is equal')
}
t.deepEqual(data, { count: 3 }, 'action is equal')
t.deepEqual(state, { count: 4 }, 'state is equal')
t.deepEqual(prev, { count: 1 }, 'prev is equal')
t.equal(caller, 'increment', 'caller is equal')
}
})

Expand All @@ -519,19 +513,12 @@ tape('hooks: onStateChange', (t) => {
})

t.test('should allow triggering other actions', (t) => {
t.plan(4)
var called = false
t.plan(2)
const store = barracks({
onStateChange: function (state, data, prev, caller, createSend) {
if (!called) {
t.pass('onStateChange called')
t.equal(caller, 'init', "caller was 'init'")
called = true
} else {
t.pass('onStateChange called')
const send = createSend('test:onStateChange', true)
send('foo')
}
t.pass('onStateChange called')
const send = createSend('test:onStateChange', true)
send('foo')
}
})

Expand All @@ -555,15 +542,10 @@ tape('hooks: onStateChange', (t) => {

t.test('previous state should not be mutated', (t) => {
t.plan(2)
var initialized = false
const storeNS = barracks({
onStateChange: (state, data, prev, caller, createSend) => {
if (!initialized) {
initialized = true
} else {
t.equal(state.ns.items.length, 3, 'state was updated')
t.equal(prev.ns.items.length, 0, 'prev was left as-is')
}
t.equal(state.ns.items.length, 3, 'state was updated')
t.equal(prev.ns.items.length, 0, 'prev was left as-is')
}
})

Expand Down

0 comments on commit 0391402

Please sign in to comment.