diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c343570..4b0895a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 | @@ -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 diff --git a/README.md b/README.md index 118c260f..2fb0cc02 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index add750c7..1ebb34b6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/tests/browser/basic.js b/tests/browser/basic.js index b67e6bee..087310d8 100644 --- a/tests/browser/basic.js +++ b/tests/browser/basic.js @@ -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) } } diff --git a/tests/browser/hooks.js b/tests/browser/hooks.js index 8e2faab2..80de35bf 100644 --- a/tests/browser/hooks.js +++ b/tests/browser/hooks.js @@ -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') } @@ -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) } } diff --git a/tests/browser/routing.js b/tests/browser/routing.js index b1b12a95..4ef2c17b 100644 --- a/tests/browser/routing.js +++ b/tests/browser/routing.js @@ -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('../..', { @@ -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') @@ -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')