Skip to content

Commit

Permalink
feat(api): swap arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Oct 7, 2016
1 parent 9514eca commit 039a45b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ we support - while secretly sneaking in some performance upgrades. Enjoy!
- [choo-handbook/upgrading/4.0.0]()

### changes
- slim down server side rendering API |
- :exclamation: slim down server side rendering API |
[issue](https://github.com/yoshuawuyts/choo/issues/191) |
[pull-request](https://github.com/yoshuawuyts/choo/pull/203)
- update router API to be lisp-like | [issue]() | [pull-request]()
- update `router` to use thunking |
- :exclamation: update router API to be lisp-like | [issue]() |
[pull-request]()
- :exclamation: swap `state` and `data` argument order |
[issue](https://github.com/yoshuawuyts/choo/issues/179)
- update `router` to use memoization |
[issue](https://github.com/yoshuawuyts/sheet-router/issues/17) |
[pull-request](https://github.com/yoshuawuyts/sheet-router/pull/34)
- support inline anchor links |
Expand All @@ -27,8 +30,6 @@ we support - while secretly sneaking in some performance upgrades. Enjoy!
- update router API to handle hashes by default
- update `location` state to expose `search` parameters (query strings) |
[issue](https://github.com/yoshuawuyts/sheet-router/issues/31)
- swap `state` and `data` argument order |
[issue](https://github.com/yoshuawuyts/choo/issues/179)

## `3.2.0`
Wooh, `plugins` are a first class citizen now thanks to the `.use()` API. It's
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,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(state, data, name, caller, createSend):__ called when an
`action` is fired.
- __onStateChange(action, state, prev, caller, createSend):__ called after a
- __onStateChange(state, data, prev, caller, createSend):__ called after a
reducer changes the `state`.

__:warning: Warning :warning:: plugins should only be used as a last resort.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"license": "MIT",
"dependencies": {
"barracks": "^8.1.1",
"barracks": "^9.0.0",
"document-ready": "~1.0.2",
"global": "^4.3.0",
"hash-match": "^1.0.2",
Expand All @@ -58,7 +58,7 @@
"es2020": "^1.0.1",
"geval": "~2.1.1",
"gzip-size-cli": "^1.0.0",
"insert-css": "^0.2.0",
"insert-css": "^1.0.0",
"istanbul": "^0.4.4",
"min-document": "~2.18.0",
"pretty-bytes-cli": "^1.0.0",
Expand Down
10 changes: 5 additions & 5 deletions tests/browser/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ test('state is immutable', function (t) {
state: state,
namespace: 'test',
reducers: {
'no-reducer-mutate': (action, state) => {
'no-reducer-mutate': (state, data) => {
return {}
},
'mutate-on-return': (action, state) => {
delete action.type
return action
'mutate-on-return': (state, data) => {
delete data.type
return data
}
},
effects: {
'triggers-reducers': (action, state, send, done) => {
'triggers-reducers': (state, data, send, done) => {
send('test:mutate-on-return', {beep: 'barp'}, done)
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/browser/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (state, data, 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(name, 'click', 'onAction: data 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 (state, data, 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')
}
Expand All @@ -30,10 +30,10 @@ test('hooks', function (t) {
clicks: 0
},
reducers: {
click: (action, state) => ({clicks: state.clicks + 1})
click: (state, data) => ({clicks: state.clicks + 1})
},
effects: {
explodes: (action, state, send, done) => {
explodes: (state, data, send, done) => {
setTimeout(() => done(new Error('effect error')), 5)
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/browser/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const view = require('../../html')

test('routing', function (t) {
t.test('history', function (t) {
t.plan(3)
t.plan(2)

const history = Event()
const choo = proxyquire('../..', {
Expand All @@ -20,11 +20,11 @@ test('routing', function (t) {
user: null
},
reducers: {
set: (action, state) => ({user: action.id})
set: (state, data) => ({user: data.id})
},
effects: {
open: function (action, state, send, done) {
t.deepEqual(action, {id: 1})
open: function (state, data, send, done) {
t.deepEqual(data, {id: 1})
send('set', {id: 1}, function (err) {
if (err) return done(err)
history.broadcast('/users/1')
Expand Down Expand Up @@ -75,10 +75,10 @@ test('routing', function (t) {
// user: null
// },
// reducers: {
// set: (action, state) => ({user: action.id})
// set: (state, data) => ({user: action.id})
// },
// effects: {
// open: function (action, state, send, done) {
// open: function (state, data, send, done) {
// send('set', {id: 1}, function (err) {
// if (err) return done(err)
// hash.broadcast('#users/1')
Expand Down

0 comments on commit 039a45b

Please sign in to comment.