Files: e73bff8390f085ab1944c5d9ac4c514cbbacf355 / history / sync / back.js
708 bytesRaw
1 | const nest = require('depnest') |
2 | const last = require('lodash/last') |
3 | |
4 | exports.gives = nest('history.sync.back') |
5 | |
6 | exports.needs = nest({ |
7 | 'history.obs.store': 'first', |
8 | 'router.sync.router': 'first' |
9 | }) |
10 | |
11 | exports.create = (api) => { |
12 | return nest('history.sync.back', back) |
13 | |
14 | function back () { |
15 | const history = api.history.obs.store() |
16 | if (history().length === 1) return false |
17 | |
18 | history.pop() |
19 | const location = last(history()) |
20 | |
21 | const newView = api.router.sync.router(location) |
22 | renderPage(newView) |
23 | } |
24 | } |
25 | |
26 | function renderPage (newView) { |
27 | const oldView = document.body.firstChild |
28 | oldView |
29 | ? document.body.replaceChild(newView, oldView) |
30 | : document.body.appendChild(newView) |
31 | } |
32 |
Built with git-ssb-web