* 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)
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
// Create a new error. Errors are pushed into an array so they can be
|
|
// queued. We're doing a bit of timestamp trickery here so each error
|
|
// is shown for exactly one second before being dropped. Probably
|
|
// useful for real world scenarios; especially when coupled to
|
|
// fancy CSS animation thingies
|
|
|
|
// Each error is displayed 1 second
|
|
const ERROR_TIMEOUT = 1000
|
|
|
|
module.exports = {
|
|
namespace: 'app',
|
|
state: {
|
|
errors: [],
|
|
errorTimeDone: 0,
|
|
triggerTime: null
|
|
},
|
|
reducers: {
|
|
setError: function (state, data) {
|
|
return {
|
|
errors: state.errors.concat(data.message),
|
|
errorTimeDone: data.errorTimeDone
|
|
}
|
|
},
|
|
'delError': function (state, data) {
|
|
state.errors.shift()
|
|
return { errors: state.errors }
|
|
}
|
|
},
|
|
effects: {
|
|
error: function (err, state, send, done) {
|
|
const timeDone = state.errorTimeDone
|
|
const now = Date.now()
|
|
|
|
const timeStamp = (timeDone && timeDone >= now)
|
|
? timeDone + ERROR_TIMEOUT
|
|
: now + ERROR_TIMEOUT
|
|
|
|
const timeout = timeStamp - now
|
|
|
|
const errAction = {
|
|
message: err.message,
|
|
errorTimeDone: timeStamp
|
|
}
|
|
send('app:setError', errAction, function (err) {
|
|
if (err) return done(err)
|
|
setTimeout(function () {
|
|
send('app:delError', done)
|
|
}, timeout)
|
|
})
|
|
}
|
|
}
|
|
}
|