git ssb

2+

mixmix / ticktack



Commit 58e30dfb4da48b50f038bbe045e8550cce9429bd

Merge pull request #1 from ticktackim/routes

add basic routing and pages
mix irving authored on 8/7/2017, 10:16:13 PM
GitHub committed on 8/7/2017, 10:16:13 PM
Parent: d289e19ab01386d51d43203044bfd1a56243f8cb
Parent: 94fb17a34b157954144a3e8817557f2f57547095

Files changed

app/html/app.jschanged
app/index.jschanged
app/page/group.jsadded
app/page/home.jsadded
app/sync/goTo.jsadded
index.jschanged
main.jschanged
package-lock.jsonchanged
package.jsonchanged
router/index.jsadded
router/sync/routes.jsadded
app/html/app.jsView
@@ -1,16 +1,15 @@
11 const nest = require('depnest')
2-const { h } = require('mutant')
32
4-
53 exports.gives = nest('app.html.app')
64
5+exports.needs = nest({
6+ 'app.sync.goTo': 'first'
7+})
8+
79 exports.create = (api) => {
810 return nest('app.html.app', app)
911
1012 function app () {
11- return h('h1', 'Hello!')
12-
13-
13+ return api.app.sync.goTo({ page: 'home' })
1414 }
1515 }
16-
app/index.jsView
@@ -1,6 +1,12 @@
11 module.exports = {
22 html: {
33 app: require('./html/app')
4+ },
5+ page: {
6+ group: require('./page/group'),
7+ home: require('./page/home')
8+ },
9+ sync: {
10+ goTo: require('./sync/goTo')
411 }
512 }
6-
app/page/group.jsView
@@ -1,0 +1,25 @@
1+const nest = require('depnest')
2+const { h } = require('mutant')
3+
4+exports.gives = nest('app.page.group')
5+
6+exports.needs = nest({
7+ 'app.sync.goTo': 'first'
8+})
9+
10+exports.create = (api) => {
11+ return nest('app.page.group', group)
12+
13+ function group (location) {
14+ // location here can be the root message of a group : { type: 'group', key }
15+ // TODO show specific group index described by key
16+
17+ const { goTo } = api.app.sync
18+
19+ return h('div', [
20+ h('h1', 'Group'),
21+ h('a', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'),
22+ h('p', `key: ${location.key}`)
23+ ])
24+ }
25+}
app/page/home.jsView
@@ -1,0 +1,23 @@
1+const nest = require('depnest')
2+const { h } = require('mutant')
3+
4+exports.gives = nest('app.page.home')
5+
6+exports.needs = nest({
7+ 'app.sync.goTo': 'first'
8+})
9+
10+exports.create = (api) => {
11+ return nest('app.page.home', home)
12+
13+ function home (location) {
14+ // location here can expected to be: { page: 'home' }
15+ const { goTo } = api.app.sync
16+
17+ return h('div', [
18+ h('h1', 'Home'),
19+ h('div', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'),
20+ h('div', { 'ev-click': () => goTo({ type: 'group', key: '%sadlkjas;lkdjas' }) }, 'Group')
21+ ])
22+ }
23+}
app/sync/goTo.jsView
@@ -1,0 +1,22 @@
1+const nest = require('depnest')
2+
3+exports.gives = nest('app.sync.goTo')
4+
5+exports.needs = nest({
6+ 'router.sync.router': 'first'
7+})
8+
9+exports.create = (api) => {
10+ return nest('app.sync.goTo', goTo)
11+
12+ function goTo (location) {
13+ console.log('goTo', location)
14+ const newView = api.router.sync.router(location)
15+
16+ // TODO (mix) : change once history in place
17+ const oldView = document.body.firstChild
18+ oldView
19+ ? document.body.replaceChild(newView, oldView)
20+ : document.body.appendChild(newView)
21+ }
22+}
index.jsView
@@ -1,5 +1,6 @@
11 const ticktack = {
2- app: require('./app')
2+ app: require('./app'),
3+ router: require('./router')
34 }
45
56 module.exports = ticktack
main.jsView
@@ -16,6 +16,7 @@
1616
1717 const api = entry(sockets, nest('app.html.app', 'first'))
1818
1919 const app = api.app.html.app()
20-document.body.appendChild(app)
2120
21+// TODO (mix) : once goTo/ router is swapping pages, attach the app to the page here
22+// document.body.appendChild(app)
package-lock.jsonView
@@ -991,11 +991,11 @@
991991 "pull-through": "1.0.18"
992992 }
993993 },
994994 "patchcore": {
995- "version": "1.8.2",
996- "resolved": "https://registry.npmjs.org/patchcore/-/patchcore-1.8.2.tgz",
997- "integrity": "sha1-9ajmXxqesof1bC1UTEtzzPNM4Xo=",
995+ "version": "1.9.0",
996+ "resolved": "https://registry.npmjs.org/patchcore/-/patchcore-1.9.0.tgz",
997+ "integrity": "sha512-d9bJ7oivSS9uLknOZxnpJMDWTGVSyLmUt38mOTrL0LD1YEAAmThhi+6i/+mPXhm6605DFbYzWtxBVmXQ2t2SjQ==",
998998 "requires": {
999999 "bulk-require": "1.0.1",
10001000 "bulkify": "1.4.2",
10011001 "color-hash": "1.0.3",
package.jsonView
@@ -17,8 +17,9 @@
1717 "license": "GPL-3.0",
1818 "dependencies": {
1919 "depject": "^4.1.0",
2020 "depnest": "^1.3.0",
21- "patchcore": "^1.8.2",
21+ "mutant": "^3.21.2",
22+ "patchcore": "^1.9.0",
2223 "setimmediate": "^1.0.5"
2324 }
2425 }
router/index.jsView
@@ -1,0 +1,5 @@
1+module.exports = {
2+ sync: {
3+ routes: require('./sync/routes')
4+ }
5+}
router/sync/routes.jsView
@@ -1,0 +1,22 @@
1+const nest = require('depnest')
2+
3+exports.gives = nest('router.sync.routes')
4+
5+exports.needs = nest({
6+ 'app.page.home': 'first',
7+ 'app.page.group': 'first'
8+})
9+
10+exports.create = (api) => {
11+ return nest('router.sync.routes', (sofar = []) => {
12+ const { home, group } = api.app.page
13+
14+ // route format: [ routeValidator, routeFunction ]
15+ const routes = [
16+ [ ({ page }) => page === 'home', home ],
17+ [ ({ type }) => type === 'group', group ]
18+ ]
19+
20+ return [...sofar, ...routes]
21+ })
22+}

Built with git-ssb-web