git ssb

2+

mixmix / ticktack



Commit 00f38454d156756289d50eaf84d0c5b276f702b3

extract history, move rendering into app.html.app

mix irving committed on 8/9/2017, 8:04:37 AM
Parent: e73bff8390f085ab1944c5d9ac4c514cbbacf355

Files changed

app/html/app.jschanged
index.jschanged
main.jschanged
package-lock.jsonchanged
package.jsonchanged
history/index.jsdeleted
history/obs/store.jsdeleted
history/sync/back.jsdeleted
history/sync/push.jsdeleted
app/html/app.jsView
@@ -5,8 +5,11 @@
55 exports.gives = nest('app.html.app')
66
77 exports.needs = nest({
88 'history.sync.push': 'first',
9+ 'history.obs.location': 'first',
10+ 'history.obs.store': 'first',
11+ 'router.sync.router': 'first',
912 'styles.css': 'first'
1013 })
1114
1215 exports.create = (api) => {
@@ -15,7 +18,26 @@
1518 function app () {
1619 const css = values(api.styles.css()).join('\n')
1720 insertCss(css)
1821
19- return api.history.sync.push({ page: 'home' })
22+ api.history.obs.location()(render)
23+ api.history.sync.push({ page: 'home' })
2024 }
25+
26+ function render (location) {
27+ const newView = api.router.sync.router(location)
28+
29+ if (!newView) {
30+ api.history.obs.store().pop() // remove bogus location
31+ return
32+ }
33+
34+ const oldView = document.body.firstChild
35+ oldView
36+ ? document.body.replaceChild(newView, oldView)
37+ : document.body.appendChild(newView)
38+ }
2139 }
40+
41+
42+
43+
index.jsView
@@ -1,8 +1,7 @@
11 const ticktack = {
22 app: require('./app'),
33 blob: require('./blob'),
4- history: require('./history'),
54 router: require('./router'),
65 styles: require('./styles')
76 }
87
main.jsView
@@ -1,22 +1,20 @@
11 const combine = require('depject')
22 const entry = require('depject/entry')
33 const nest = require('depnest')
44
5-const ticktack = require('./')
6-const patchcore = require('patchcore')
7-
85 // polyfills
96 require('setimmediate')
107
118 // from more specialized to more general
129 const sockets = combine(
13- ticktack,
14- patchcore
10+ require('./'),
11+ require('patch-history'),
12+ require('patchcore')
1513 )
1614
1715 const api = entry(sockets, nest('app.html.app', 'first'))
1816
1917 const app = api.app.html.app()
2018
21-// TODO (mix) : once goTo/ router is swapping pages, attach the app to the page here
19+// TODO (mix) : once app has swapping pages, attach the app to the page here
2220 // document.body.appendChild(app)
package-lock.jsonView
@@ -1039,8 +1039,19 @@
10391039 "pull-reader": "1.2.9",
10401040 "pull-through": "1.0.18"
10411041 }
10421042 },
1043+ "patch-history": {
1044+ "version": "1.0.0",
1045+ "resolved": "https://registry.npmjs.org/patch-history/-/patch-history-1.0.0.tgz",
1046+ "integrity": "sha512-lWc3U5awYkuZIBLiRcDgagtilCEQwb2IN3UAorVrIzdp4+MkyrVH3MQmVazx4YLV4w9AkVUy5Fdyz3yn8v32iw==",
1047+ "requires": {
1048+ "depject": "4.1.0",
1049+ "depnest": "1.3.0",
1050+ "lodash": "4.17.4",
1051+ "mutant": "3.21.2"
1052+ }
1053+ },
10431054 "patchcore": {
10441055 "version": "1.9.0",
10451056 "resolved": "https://registry.npmjs.org/patchcore/-/patchcore-1.9.0.tgz",
10461057 "integrity": "sha512-d9bJ7oivSS9uLknOZxnpJMDWTGVSyLmUt38mOTrL0LD1YEAAmThhi+6i/+mPXhm6605DFbYzWtxBVmXQ2t2SjQ==",
package.jsonView
@@ -22,8 +22,9 @@
2222 "libnested": "^1.2.1",
2323 "lodash": "^4.17.4",
2424 "micro-css": "^2.0.1",
2525 "mutant": "^3.21.2",
26+ "patch-history": "^1.0.0",
2627 "patchcore": "^1.9.0",
2728 "pull-stream": "^3.6.0",
2829 "read-directory": "^2.1.0",
2930 "setimmediate": "^1.0.5"
history/index.jsView
@@ -1,10 +1,0 @@
1-module.exports ={
2- obs: {
3- store: require('./obs/store'),
4- },
5- sync: {
6- push: require('./sync/push'),
7- back: require('./sync/back')
8- }
9-}
10-
history/obs/store.jsView
@@ -1,11 +1,0 @@
1-const nest = require('depnest')
2-const { Array: MutantArray } = require('mutant')
3-
4-exports.gives = nest('history.obs.store')
5-
6-var _store = MutantArray()
7-
8-exports.create = (api) => {
9- return nest('history.obs.store', () => _store)
10-}
11-
history/sync/back.jsView
@@ -1,31 +1,0 @@
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-}
history/sync/push.jsView
@@ -1,30 +1,0 @@
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-}

Built with git-ssb-web