Merge pull request #237 from pekeler/reducer-signature

Fixing consistency of signatures.
This commit is contained in:
Yoshua Wuyts
2016-08-28 00:03:42 +02:00
committed by GitHub
4 changed files with 18 additions and 18 deletions
+2 -2
View File
@@ -492,9 +492,9 @@ There are several `hooks` that are picked up by `choo`:
- __onError(err, state, createSend):__ called when an `effect` or
`subscription` emit an error. If no handler is passed, the default handler
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.
- __onStateChange(action, state, prev, caller, createSend):__ called after a
- __onStateChange(data, state, prev, caller, createSend):__ called after a
reducer changes the `state`.
__:warning: Warning :warning:: plugins should only be used as a last resort.
+5 -5
View File
@@ -16,16 +16,16 @@ test('state is immutable', function (t) {
state: state,
namespace: 'test',
reducers: {
'no-reducer-mutate': (action, state) => {
'no-reducer-mutate': (data, state) => {
return {}
},
'mutate-on-return': (action, state) => {
delete action.type
return action
'mutate-on-return': (data, state) => {
delete data.type
return data
}
},
effects: {
'triggers-reducers': (action, state, send, done) => {
'triggers-reducers': (data, state, send, done) => {
send('test:mutate-on-return', {beep: 'barp'}, done)
}
}
+6 -6
View File
@@ -10,16 +10,16 @@ test('hooks', function (t) {
onError: function (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
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(name, 'click', 'onAction: action name')
t.equal(caller, 'view: /', 'onAction: caller name')
t.equal(typeof createSend, 'function', 'onAction: createSend fn')
},
onStateChange: function (action, state, prev, createSend) {
t.deepEqual(action, {foo: 'bar'}, 'onState: action data')
onStateChange: function (data, state, prev, createSend) {
t.deepEqual(data, {foo: 'bar'}, 'onState: action data')
t.deepEqual(state.clicks, 1, 'onState: new state: 1 clicks')
t.deepEqual(prev.clicks, 0, 'onState: prev state: 0 clicks')
}
@@ -30,10 +30,10 @@ test('hooks', function (t) {
clicks: 0
},
reducers: {
click: (action, state) => ({clicks: state.clicks + 1})
click: (data, state) => ({clicks: state.clicks + 1})
},
effects: {
explodes: (action, state, send, done) => {
explodes: (data, state, send, done) => {
setTimeout(() => done(new Error('effect error')), 5)
}
}
+5 -5
View File
@@ -20,11 +20,11 @@ test('routing', function (t) {
user: null
},
reducers: {
set: (action, state) => ({user: action.id})
set: (data, state) => ({user: data.id})
},
effects: {
open: function (action, state, send, done) {
t.deepEqual(action, {id: 1})
open: function (data, state, send, done) {
t.deepEqual(data, {id: 1})
send('set', {id: 1}, function (err) {
if (err) return done(err)
history.broadcast('https://foo.com/users/1')
@@ -74,10 +74,10 @@ test('routing', function (t) {
user: null
},
reducers: {
set: (action, state) => ({user: action.id})
set: (data, state) => ({user: data.id})
},
effects: {
open: function (action, state, send, done) {
open: function (data, state, send, done) {
send('set', {id: 1}, function (err) {
if (err) return done(err)
hash.broadcast('#users/1')