deps: bump to barracks 8

This commit is contained in:
Yoshua Wuyts
2016-07-05 17:55:17 +02:00
parent dc1a2b25e1
commit 4ad3dc9b72
5 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ const app = choo({
console.log(data) console.log(data)
console.groupEnd() console.groupEnd()
}, },
onState: function (data, state, prev, createSend) { onStateChange: function (data, state, prev, createSend) {
console.groupCollapsed('State') console.groupCollapsed('State')
console.log(prev) console.log(prev)
console.log(state) console.log(state)
+6 -4
View File
@@ -17,7 +17,7 @@ module.exports = choo
function choo (opts) { function choo (opts) {
opts = opts || {} opts = opts || {}
const _store = start._store = barracks(xtend(opts, { onState: render })) const _store = start._store = barracks(xtend(opts, { onStateChange: render }))
var _router = start._router = null var _router = start._router = null
var _defaultRoute = null var _defaultRoute = null
var _rootNode = null var _rootNode = null
@@ -36,7 +36,7 @@ function choo (opts) {
serverState = serverState || {} serverState = serverState || {}
assert.equal(typeof route, 'string', 'choo.app.toString: route must be a string') assert.equal(typeof route, 'string', 'choo.app.toString: route must be a string')
assert.equal(typeof serverState, 'object', 'choo.app.toString: serverState must be an object') assert.equal(typeof serverState, 'object', 'choo.app.toString: serverState must be an object')
_store.start({ noSubscriptions: true, noReducers: true, noEffects: true }) _store.start({ subscriptions: false, reducers: false, effects: false })
const state = _store.state({ state: serverState }) const state = _store.state({ state: serverState })
const router = createRouter(_defaultRoute, _routes, createSend) const router = createRouter(_defaultRoute, _routes, createSend)
@@ -81,7 +81,9 @@ function choo (opts) {
// update the DOM after every state mutation // update the DOM after every state mutation
// (obj, obj, obj, str, fn) -> null // (obj, obj, obj, str, fn) -> null
function render (data, state, prev, name, createSend) { function render (data, state, prev, name, createSend) {
if (opts.onState) opts.onState(data, state, prev, name, createSend) if (opts.onStateChange) {
opts.onStateChange(data, state, prev, name, createSend)
}
const newTree = _router(state.location.pathname, state, prev) const newTree = _router(state.location.pathname, state, prev)
_rootNode = yo.update(_rootNode, newTree) _rootNode = yo.update(_rootNode, newTree)
@@ -119,7 +121,7 @@ function choo (opts) {
return function chooWrap (params, state) { return function chooWrap (params, state) {
const nwPrev = prev const nwPrev = prev
const nwState = prev = xtend(state, { params: params }) const nwState = prev = xtend(state, { params: params })
if (!opts.noFreeze) Object.freeze(nwState) if (opts.freeze !== false) Object.freeze(nwState)
return child(nwState, nwPrev, send) return child(nwState, nwPrev, send)
} }
} }
+1 -1
View File
@@ -24,7 +24,7 @@
], ],
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"barracks": "^7.0.3", "barracks": "^8.0.0",
"document-ready": "~1.0.2", "document-ready": "~1.0.2",
"global": "^4.3.0", "global": "^4.3.0",
"hash-match": "^1.0.2", "hash-match": "^1.0.2",
+1 -1
View File
@@ -25,7 +25,7 @@ test('freeze (default)', function (t) {
test('noFreeze', function (t) { test('noFreeze', function (t) {
t.plan(2) t.plan(2)
const app = choo({noFreeze: true}) const app = choo({freeze: false})
app.model({ app.model({
state: { state: {
+1 -1
View File
@@ -18,7 +18,7 @@ test('hooks', function (t) {
t.equal(caller, '/', 'onAction: caller name') t.equal(caller, '/', 'onAction: caller name')
t.equal(typeof createSend, 'function', 'onAction: createSend fn') t.equal(typeof createSend, 'function', 'onAction: createSend fn')
}, },
onState: function (action, state, prev, createSend) { onStateChange: function (action, state, prev, createSend) {
t.deepEqual(action, {foo: 'bar'}, 'onState: action data') t.deepEqual(action, {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')