git ssb

2+

ev / mvd



Commit d783575b5b38608603e2a301844fb73d9d370541

re-modularize routes into views.js

Ev Bogue committed on 5/16/2018, 6:44:41 PM
Parent: 2bf2f02ab2d149f038ff4ecd1e5e19c925b558fd

Files changed

index.jschanged
views.jschanged
index.jsView
@@ -1,112 +1,21 @@
1-var pull = require('pull-stream')
2-var sbot = require('./scuttlebot')
3-var hyperscroll = require('hyperscroll')
4-var More = require('pull-more')
5-var stream = require('hyperloadmore/stream')
61 var h = require('hyperscript')
7-var render = require('./render')
2 +var route = require('./views')
83
9-var ref = require('ssb-ref')
10-
114 document.head.appendChild(h('style', require('./style.css.json')))
125
13-function hash () {
14- return window.location.hash.substring(1)
15-}
16-
176 var content = h('div.content')
187
198 var screen = h('div#screen', {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}})
209
21-function route () {
22- var src = hash()
23-
24- if (ref.isFeed(src)) {
25- var content = h('div.content')
26- var screen = document.getElementById('screen')
27- screen.appendChild(hyperscroll(content))
28- function createStream (opts) {
29- return pull(
30- More(sbot.userStream, opts, ['value', 'sequence']),
31- pull.map(function (msg) {
32- return h('div', render(msg))
33- })
34- )
35- }
36-
37- pull(
38- createStream({old: false, limit: 10, id: src}),
39- stream.top(content)
40- )
41-
42- pull(
43- createStream({reverse: true, live: false, limit: 10, id: src}),
44- stream.bottom(content)
45- )
46-
47-
48- } else if (ref.isMsg(src)) {
49- var content = h('div.content')
50- var screen = document.getElementById('screen')
51- screen.appendChild(hyperscroll(content))
52- sbot.get(src, function (err, data) {
53- if (err) {console.log('could not find message') }
54- data.value = data
55- console.log(data)
56- var root = src
57- if (data.value.content.root)
58- root = data.value.content.root
59- sbot.get(root, function (err, data) {
60- if (err) { console.log('could not find root')}
61- data.value = data
62- data.key = root
63- content.appendChild(h('div', render(data)))
64- pull(
65- sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
66- pull.drain(function (msg) {
67- console.log(msg)
68- if (msg.value)
69- content.appendChild(h('div', render(msg)))
70- })
71- )
72- })
73- })
74- } else {
75- var content = h('div.content')
76- var screen = document.getElementById('screen')
77- screen.appendChild(hyperscroll(content))
78- function createStream (opts) {
79- return pull(
80- More(sbot.createLogStream, opts),
81- pull.map(function (msg) {
82- return h('div', render(msg))
83- })
84- )
85- }
86-
87- pull(
88- createStream({old: false, limit: 10}),
89- stream.top(content)
90- )
91-
92- pull(
93- createStream({reverse: true, live: false, limit: 10}),
94- stream.bottom(content)
95- )
96-
97- }
98-}
99-
10010 document.body.appendChild(screen)
10111 route()
10212
10313 window.onhashchange = function () {
104- //var content = h('div.content')
10514 var screen = document.getElementById('screen')
15 +
10616 var newscreen = h('div#screen', {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}})
10717
108- //if(_screen != null)
10918 console.log(screen)
11019 screen.parentNode.replaceChild(newscreen, screen)
11120 route()
11221 }
views.jsView
@@ -4,141 +4,92 @@
44 var More = require('pull-more')
55 var stream = require('hyperloadmore/stream')
66 var h = require('hyperscript')
77 var render = require('./render')
8 +var ref = require('ssb-ref')
89
910 var compose = require('./compose')
1011
11-var content = h('div.content')
12-function screen () {
13- document.body.appendChild(h('div.screen',
14- {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
15- hyperscroll(content)
16- ))
12 +function hash () {
13 + return window.location.hash.substring(1)
1714 }
1815
19-module.exports.logstream = function () {
20- var opts = {
21- "type": 'post',
22- "placeholder": 'Write a mutable message'
23- }
16 +module.exports = function () {
17 + var src = hash()
2418
25- var content = h('div.content',
26- h('div.message', compose(opts))
27- )
19 + if (ref.isFeed(src)) {
20 + var content = h('div.content')
21 + var screen = document.getElementById('screen')
22 + screen.appendChild(hyperscroll(content))
23 + function createStream (opts) {
24 + return pull(
25 + More(sbot.userStream, opts, ['value', 'sequence']),
26 + pull.map(function (msg) {
27 + return h('div', render(msg))
28 + })
29 + )
30 + }
2831
29- function mainscreen () {
30- document.body.appendChild(h('div.screen',
31- {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
32- hyperscroll(content)
33- ))
34- }
32 + pull(
33 + createStream({old: false, limit: 10, id: src}),
34 + stream.top(content)
35 + )
3536
36- mainscreen()
37-
38- function createStream (opts) {
39- return pull(
40- More(sbot.createLogStream, opts),
41- pull.map(function (msg) {
42- return h('div', render(msg))
43- })
37 + pull(
38 + createStream({reverse: true, live: false, limit: 10, id: src}),
39 + stream.bottom(content)
4440 )
45- }
4641
47- pull(
48- createStream({old: false, limit: 10}),
49- stream.top(content)
50- )
5142
52- pull(
53- createStream({reverse: true, live: false, limit: 10}),
54- stream.bottom(content)
55- )
56-}
43 + } else if (ref.isMsg(src)) {
44 + var content = h('div.content')
45 + var screen = document.getElementById('screen')
46 + screen.appendChild(hyperscroll(content))
47 + sbot.get(src, function (err, data) {
48 + if (err) {console.log('could not find message') }
49 + data.value = data
50 + console.log(data)
51 + var root = src
52 + if (data.value.content.root)
53 + root = data.value.content.root
54 + sbot.get(root, function (err, data) {
55 + if (err) { console.log('could not find root')}
56 + data.value = data
57 + data.key = root
58 + content.appendChild(h('div', render(data)))
59 + pull(
60 + sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
61 + pull.drain(function (msg) {
62 + console.log(msg)
63 + if (msg.value)
64 + content.appendChild(h('div', render(msg)))
65 + })
66 + )
67 + })
68 + })
69 + } else {
70 + var content = h('div.content')
71 + var screen = document.getElementById('screen')
72 + screen.appendChild(hyperscroll(content))
73 + function createStream (opts) {
74 + return pull(
75 + More(sbot.createLogStream, opts),
76 + pull.map(function (msg) {
77 + return h('div', render(msg))
78 + })
79 + )
80 + }
5781
58-var rawJSON = require('patchapp-raw/json')
82 + pull(
83 + createStream({old: false, limit: 10}),
84 + stream.top(content)
85 + )
5986
60-module.exports.rawstream = function () {
61- screen()
62-
63- function createStream (opts) {
64- return pull(
65- More(sbot.createLogStream, opts),
66- pull.filter(function (data) {
67- return 'string' === typeof data.value.content.text
68- }),
69- pull.map(function (msg) {
70- return h('pre.raw__json', {id: msg.key}, rawJSON(msg))
71- })
87 + pull(
88 + createStream({reverse: true, live: false, limit: 10}),
89 + stream.bottom(content)
7290 )
73- }
7491
75- pull(
76- createStream({old: false, limit: 10}),
77- stream.top(content)
78- )
79-
80- pull(
81- createStream({reverse: true, live: false, limit: 10}),
82- stream.bottom(content)
83- )
84-}
85-
86-module.exports.userstream = function (src) {
87- screen()
88-
89- function createStream (opts) {
90- return pull(
91- More(sbot.userStream, opts, ['value', 'sequence']),
92- pull.map(function (msg) {
93- return h('div', render(msg))
94- })
95- )
9692 }
97-
98- pull(
99- createStream({old: false, limit: 10, id: src}),
100- stream.top(content)
101- )
102-
103- pull(
104- createStream({reverse: true, live: false, limit: 10, id: src}),
105- stream.bottom(content)
106- )
107-
10893 }
10994
110-module.exports.get = function (src) {
111- screen()
11295
113- sbot.get(src, function (err, data) {
114- if (err) {console.log('could not find message') }
115- data.value = data
116- console.log(data)
117- var root = src
118- if (data.value.content.root)
119- root = data.value.content.root
120- sbot.get(root, function (err, data) {
121- if (err) { console.log('could not find root')}
122- data.value = data
123- data.key = root
124- content.appendChild(h('div', render(data)))
125- pull(
126- sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
127- pull.drain(function (msg) {
128- console.log(msg)
129- if (msg.value)
130- content.appendChild(h('div', render(msg)))
131- })
132- )
133- })
134- })
135-}
136-
137-module.exports.compose = function () {
138- screen()
139- var opts = {
140- "root": null,
141- "type": "post"
142- }
143- content.appendChild(h('div.message', compose(opts)))
144-}

Built with git-ssb-web