From bba9ef4d4628fadcba7bc258f737d95961392f2f Mon Sep 17 00:00:00 2001 From: timwis Date: Sat, 2 Jul 2016 21:05:38 -0400 Subject: [PATCH 1/3] Rename action param -> data in docs --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7e70363..f3829df 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ can be called to modify it: app.model({ state: { title: 'Set the title' }, reducers: { - update: (action, state) => ({ title: action.value }) + update: (data, state) => ({ title: data.value }) } }) ``` @@ -173,7 +173,7 @@ const app = choo() app.model({ state: { title: 'Set the title' }, reducers: { - update: (action, state) => ({ title: action.value }) + update: (data, state) => ({ title: data.value }) } }) @@ -203,9 +203,9 @@ sources of data. `effects` react to changes, perform an `action` and can then post the results. `reducers` take data, modify it, and update the internal `state`. -Communication of data is done using objects called `actions`. Each `action` has -any number of properties for data, and a unique `type` that can trigger -properties on the models. +Communication of data is done using objects called `actions`. Each `action` +consists of a unique `actionName` and an optional payload of `data`, which can +be any value. When a `reducer` modifies `state`, the `router` is called, which in turn calls `views`. `views` take `state` and return [DOM][dom] nodes which are then @@ -256,7 +256,7 @@ app.model({ namespace: 'todos', state: { todos: [] }, reducers: { - add: (action, state) => ({ todos: state.todos.concat(action.payload) }) + add: (data, state) => ({ todos: state.todos.concat(data.payload) }) } }) ``` @@ -302,7 +302,7 @@ app.model({ (send) => setInterval(() => send('app:print', { payload: 'dog?' }), 1000) ], effects: { - print: (action, state) => console.log(action.payload) + print: (data, state) => console.log(data.payload) } }) ``` @@ -368,7 +368,7 @@ app.model({ } }) -function getJson (state, action, send) { +function getJson (state, data, send) { http.get('/my-endpoint', { json: true }, function (err, res, body) { if (err) return send('app:error', { payload: err.message }) if (res.statusCode !== 200 || !body) { @@ -378,7 +378,7 @@ function getJson (state, action, send) { }) } -function postJson (state, action, send) { +function postJson (state, data, send) { const body = { foo: 'bar' } http.post('/my-endpoint', { json: body }, function (err, res, body) { if (err) return send('app:error', { payload: err.message }) @@ -389,7 +389,7 @@ function postJson (state, action, send) { }) } -function httpDelete (state, action, send) { +function httpDelete (state, data, send) { const body = { foo: 'bar' } http.del('/my-endpoint', { json: body }, function (err, res, body) { if (err) return send('app:error', { payload: err.message }) @@ -499,15 +499,15 @@ function view (params, state, send) { ` function onSubmit (event) { - send('login', { data: new FormData(event.target) }) + send('login', new FormData(event.target)) event.preventDefault() } } app.model({ effects: { - login: (action, state, send) => { - http.post('/login', { body: action.data }, (err, res, body) => { + login: (data, state, send) => { + http.post('/login', { body: data }, (err, res, body) => { send('authorize', { payload: body }) }) } @@ -642,9 +642,9 @@ arguments: in-namespace only. - __state:__ object. Key value store of initial values - __reducers:__ object. Syncronous functions that modify state. Each function - has a signature of `(action, state)` + has a signature of `(data, state)` - __effects:__ object. Asyncronous functions that perform IO. Each function has - a signature of `(action, state, send)` where `send` is a reference to + a signature of `(data, state, send)` where `send` is a reference to `app.send()` ### app.router(params, state, send) From 6954bc50843f663a153869fb6c8e7dc28b69b546 Mon Sep 17 00:00:00 2001 From: timwis Date: Sat, 2 Jul 2016 21:05:52 -0400 Subject: [PATCH 2/3] Rename action param -> data in index.js --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7826ff5..872e066 100644 --- a/index.js +++ b/index.js @@ -79,8 +79,8 @@ function choo (opts) { // update the DOM after every state mutation // (obj, obj, obj, str, fn) -> null - function render (action, state, prev, name, createSend) { - if (opts.onState) opts.onState(action, state, prev, name, createSend) + function render (data, state, prev, name, createSend) { + if (opts.onState) opts.onState(data, state, prev, name, createSend) if (state === prev) return const newTree = _router(state.location.pathname, state, prev) @@ -133,8 +133,8 @@ function appInit (opts) { const loc = document.location const state = { pathname: (opts.hash) ? hashMatch(loc.hash) : loc.href } const reducers = { - setLocation: function setLocation (action, state) { - return { pathname: action.location.replace(/#.*/, '') } + setLocation: function setLocation (data, state) { + return { pathname: data.location.replace(/#.*/, '') } } } // if hash routing explicitly enabled, subscribe to it From d19e67322a0911f44996acae61f4bf33fda96c8e Mon Sep 17 00:00:00 2001 From: timwis Date: Sat, 2 Jul 2016 21:09:08 -0400 Subject: [PATCH 3/3] Rename action param -> data in examples --- examples/http/client.js | 6 +++--- examples/http/models/api.js | 8 ++++---- examples/http/models/error.js | 8 ++++---- examples/sse/client.js | 6 +++--- examples/title/client.js | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/http/client.js b/examples/http/client.js index 44974b3..6c6e6fb 100644 --- a/examples/http/client.js +++ b/examples/http/client.js @@ -10,12 +10,12 @@ const app = choo({ const send = createSend('onError: ') send('app:error', err) }, - onAction: function (action, state, name, caller, createSend) { + onAction: function (data, state, name, caller, createSend) { console.groupCollapsed(`Action: ${caller} -> ${name}`) - console.log(action) + console.log(data) console.groupEnd() }, - onState: function (action, state, prev, createSend) { + onState: function (data, state, prev, createSend) { console.groupCollapsed('State') console.log(prev) console.log(state) diff --git a/examples/http/models/api.js b/examples/http/models/api.js index e7bd2c0..9fd5826 100644 --- a/examples/http/models/api.js +++ b/examples/http/models/api.js @@ -6,13 +6,13 @@ module.exports = { title: 'Button pushing machine 3000' }, reducers: { - set: (action, state) => ({ 'title': action.data }) + set: (data, state) => ({ 'title': data }) }, effects: { - good: function (action, state, send, done) { + good: function (data, state, send, done) { request('/good', send, done) }, - bad: (action, state, send, done) => request('/bad', send, done) + bad: (data, state, send, done) => request('/bad', send, done) } } @@ -26,6 +26,6 @@ function request (uri, send, done) { return done(new Error(message)) } if (!body) return done(new Error('fatal: no body received')) - send('api:set', { data: body.message || body.title }, done) + send('api:set', body.message || body.title, done) }) } diff --git a/examples/http/models/error.js b/examples/http/models/error.js index b3e0cea..bd1620a 100644 --- a/examples/http/models/error.js +++ b/examples/http/models/error.js @@ -15,13 +15,13 @@ module.exports = { triggerTime: null }, reducers: { - setError: function (action, state) { + setError: function (data, state) { return { - errors: state.errors.concat(action.message), - errorTimeDone: action.errorTimeDone + errors: state.errors.concat(data.message), + errorTimeDone: data.errorTimeDone } }, - 'delError': function (action, state) { + 'delError': function (data, state) { state.errors.shift() return { errors: state.errors } } diff --git a/examples/sse/client.js b/examples/sse/client.js index e014f4f..6f606d8 100644 --- a/examples/sse/client.js +++ b/examples/sse/client.js @@ -35,13 +35,13 @@ function createModel () { } ], reducers: { - 'print': (action, state) => { - return ({ msg: state.msg + ' ' + action.payload }) + 'print': (data, state) => { + return ({ msg: state.msg + ' ' + data.payload }) } }, effects: { close: () => stream.close(), - error: (action, state) => console.error(`error: ${action.payload}`) + error: (data, state) => console.error(`error: ${data.payload}`) } } } diff --git a/examples/title/client.js b/examples/title/client.js index 3ea603d..35f4dc8 100644 --- a/examples/title/client.js +++ b/examples/title/client.js @@ -8,10 +8,10 @@ app.model({ title: 'my demo app' }, reducers: { - update: (action, state) => ({ title: action.payload }) + update: (data, state) => ({ title: data.payload }) }, effects: { - update: (action, state, send) => (document.title = action.payload) + update: (data, state, send) => (document.title = data.payload) } })