Fixing consistency of signatures.
This commit is contained in:
@@ -492,9 +492,9 @@ There are several `hooks` that are picked up by `choo`:
|
|||||||
- __onError(err, state, createSend):__ called when an `effect` or
|
- __onError(err, state, createSend):__ called when an `effect` or
|
||||||
`subscription` emit an error. If no handler is passed, the default handler
|
`subscription` emit an error. If no handler is passed, the default handler
|
||||||
will `throw` on each error.
|
will `throw` on each error.
|
||||||
- __onAction(action, state, name, caller, createSend):__ called when an
|
- __onAction(data, state, name, caller, createSend):__ called when an
|
||||||
`action` is fired.
|
`action` is fired.
|
||||||
- __onStateChange(action, state, prev, caller, createSend):__ called after a
|
- __onStateChange(data, state, prev, caller, createSend):__ called after a
|
||||||
reducer changes the `state`.
|
reducer changes the `state`.
|
||||||
|
|
||||||
__:warning: Warning :warning:: plugins should only be used as a last resort.
|
__:warning: Warning :warning:: plugins should only be used as a last resort.
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ test('state is immutable', function (t) {
|
|||||||
state: state,
|
state: state,
|
||||||
namespace: 'test',
|
namespace: 'test',
|
||||||
reducers: {
|
reducers: {
|
||||||
'no-reducer-mutate': (action, state) => {
|
'no-reducer-mutate': (data, state) => {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
'mutate-on-return': (action, state) => {
|
'mutate-on-return': (data, state) => {
|
||||||
delete action.type
|
delete data.type
|
||||||
return action
|
return data
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
effects: {
|
effects: {
|
||||||
'triggers-reducers': (action, state, send, done) => {
|
'triggers-reducers': (data, state, send, done) => {
|
||||||
send('test:mutate-on-return', {beep: 'barp'}, done)
|
send('test:mutate-on-return', {beep: 'barp'}, done)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ test('hooks', function (t) {
|
|||||||
onError: function (err) {
|
onError: function (err) {
|
||||||
t.equal(err.message, 'effect error', 'onError: receives err')
|
t.equal(err.message, 'effect error', 'onError: receives err')
|
||||||
},
|
},
|
||||||
onAction: function (action, state, name, caller, createSend) {
|
onAction: function (data, state, name, caller, createSend) {
|
||||||
if (name === 'explodes') return
|
if (name === 'explodes') return
|
||||||
t.deepEqual(action, {foo: 'bar'}, 'onAction: action data')
|
t.deepEqual(data, {foo: 'bar'}, 'onAction: action data')
|
||||||
t.equal(state.clicks, 0, 'onAction: current state: 0 clicks')
|
t.equal(state.clicks, 0, 'onAction: current state: 0 clicks')
|
||||||
t.equal(name, 'click', 'onAction: action name')
|
t.equal(name, 'click', 'onAction: action name')
|
||||||
t.equal(caller, 'view: /', 'onAction: caller name')
|
t.equal(caller, 'view: /', 'onAction: caller name')
|
||||||
t.equal(typeof createSend, 'function', 'onAction: createSend fn')
|
t.equal(typeof createSend, 'function', 'onAction: createSend fn')
|
||||||
},
|
},
|
||||||
onStateChange: function (action, state, prev, createSend) {
|
onStateChange: function (data, state, prev, createSend) {
|
||||||
t.deepEqual(action, {foo: 'bar'}, 'onState: action data')
|
t.deepEqual(data, {foo: 'bar'}, 'onState: action data')
|
||||||
t.deepEqual(state.clicks, 1, 'onState: new state: 1 clicks')
|
t.deepEqual(state.clicks, 1, 'onState: new state: 1 clicks')
|
||||||
t.deepEqual(prev.clicks, 0, 'onState: prev state: 0 clicks')
|
t.deepEqual(prev.clicks, 0, 'onState: prev state: 0 clicks')
|
||||||
}
|
}
|
||||||
@@ -30,10 +30,10 @@ test('hooks', function (t) {
|
|||||||
clicks: 0
|
clicks: 0
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
click: (action, state) => ({clicks: state.clicks + 1})
|
click: (data, state) => ({clicks: state.clicks + 1})
|
||||||
},
|
},
|
||||||
effects: {
|
effects: {
|
||||||
explodes: (action, state, send, done) => {
|
explodes: (data, state, send, done) => {
|
||||||
setTimeout(() => done(new Error('effect error')), 5)
|
setTimeout(() => done(new Error('effect error')), 5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ test('routing', function (t) {
|
|||||||
user: null
|
user: null
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
set: (action, state) => ({user: action.id})
|
set: (data, state) => ({user: data.id})
|
||||||
},
|
},
|
||||||
effects: {
|
effects: {
|
||||||
open: function (action, state, send, done) {
|
open: function (data, state, send, done) {
|
||||||
t.deepEqual(action, {id: 1})
|
t.deepEqual(data, {id: 1})
|
||||||
send('set', {id: 1}, function (err) {
|
send('set', {id: 1}, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
history.broadcast('https://foo.com/users/1')
|
history.broadcast('https://foo.com/users/1')
|
||||||
@@ -74,10 +74,10 @@ test('routing', function (t) {
|
|||||||
user: null
|
user: null
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
set: (action, state) => ({user: action.id})
|
set: (data, state) => ({user: data.id})
|
||||||
},
|
},
|
||||||
effects: {
|
effects: {
|
||||||
open: function (action, state, send, done) {
|
open: function (data, state, send, done) {
|
||||||
send('set', {id: 1}, function (err) {
|
send('set', {id: 1}, function (err) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
hash.broadcast('#users/1')
|
hash.broadcast('#users/1')
|
||||||
|
|||||||
Reference in New Issue
Block a user