* location: change url on location:setLocation - [ ] don't break hashing - [ ] allow not changing the url fixup! move fns around fixup! add search string * app.start: clean * walk: add * location: update arg calls * fixup! location: update * uri-wrap: fix thunking * router: update to latest sheet-router (#239) * router: update to latest sheet-router * tests: fix for latest version * tests: fix SSR * tests: fix history * tests: spruce up * docs: update example * examples: update * deps: bump sheet-router * 4.0.0-0 * chore(changelog): 4.0.0 (#211) * feat(api:) arg order (#268) * s/data, state/state, data/ * feat(api): swap arguments * fix(href): fix routing (#271) * feat(http): remove (#269) * feat(router): enable hash routing (#273) * deps: fix mount * 4.0.0-1 * feat(mount): copy {script,link} tags * 4.0.0-2 * fix(mount): forEach -> for Lol can't use forEach * fix(router): use state.location.href (#282) * fix(mount): use deep node clone * 4.0.0-3 * fix(deps): remove hash-match * 4.0.0-4 * fix(mount): return node * 4.0.0-5 * fix(router): check if a hash is a valid selector (#339) * 4.0.0-6 * fix(router): pass params on newstate (#343) * 4.0.0-7 * feat(docs): update for 4.0.0 (#320) * feat(docs): update for 4.0.0 * docs: update router example in readme (#337) * chore(changelog): update for v4 (#351)
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
const append = require('append-child')
|
|
const test = require('tape')
|
|
|
|
const choo = require('../../')
|
|
const html = require('../../html')
|
|
|
|
test('state is immutable', function (t) {
|
|
t.plan(4)
|
|
|
|
const app = choo()
|
|
const state = {
|
|
foo: 'baz',
|
|
beep: 'boop'
|
|
}
|
|
|
|
app.model({
|
|
state: state,
|
|
namespace: 'test',
|
|
reducers: {
|
|
'no-reducer-mutate': (state, data) => {
|
|
return {}
|
|
},
|
|
'mutate-on-return': (state, data) => {
|
|
delete data.type
|
|
return data
|
|
}
|
|
},
|
|
effects: {
|
|
'triggers-reducers': (state, data, send, done) => {
|
|
send('test:mutate-on-return', {beep: 'barp'}, done)
|
|
}
|
|
}
|
|
})
|
|
|
|
let loop = -1
|
|
|
|
const asserts = [
|
|
(state) => t.deepEqual(state, {foo: 'baz', beep: 'boop'}, 'intial state'),
|
|
(state) => t.deepEqual(state, {foo: 'baz', beep: 'boop'}, 'no change in state'),
|
|
(state) => t.deepEqual(state, {foo: 'oof', beep: 'boop'}, 'change in state from reducer'),
|
|
(state) => t.deepEqual(state, {foo: 'oof', beep: 'barp'}, 'change in state from effect')
|
|
]
|
|
|
|
const triggers = [
|
|
(send) => send('test:no-reducer-mutate'),
|
|
(send) => send('test:mutate-on-return', {foo: 'oof'}),
|
|
(send) => send('test:triggers-reducers')
|
|
]
|
|
|
|
app.router([
|
|
['/', function (state, prev, send) {
|
|
++loop
|
|
asserts[loop] && asserts[loop](state.test)
|
|
setTimeout(() => triggers[loop] && triggers[loop](send), 5)
|
|
return html`
|
|
<div><span class="test">${state.foo}:${state.beep}</span></div>
|
|
`
|
|
}]
|
|
])
|
|
|
|
const tree = app.start()
|
|
t.on('end', append(tree))
|
|
})
|