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