git ssb

2+

mixmix / ticktack



Tree: e73bff8390f085ab1944c5d9ac4c514cbbacf355

Files: e73bff8390f085ab1944c5d9ac4c514cbbacf355 / history / sync / back.js

708 bytesRaw
1const nest = require('depnest')
2const last = require('lodash/last')
3
4exports.gives = nest('history.sync.back')
5
6exports.needs = nest({
7 'history.obs.store': 'first',
8 'router.sync.router': 'first'
9})
10
11exports.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
26function 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