git ssb

2+

mixmix / ticktack



Commit fd90a69c5a2931ed4ec735c57c4b2ebb42bcfe42

minimal chunking function

mix irving committed on 8/8/2017, 5:18:32 AM
Parent: 815a0b039bd2ce2cfe6eeec00539945cb5660fd1

Files changed

app/html/thread.jschanged
app/html/thread.mcsschanged
app/page/private.jschanged
main.jschanged
app/html/thread.jsView
@@ -1,7 +1,9 @@
11 const nest = require('depnest')
2-const { h } = require('mutant')
2+const { h, Array: MutantArray, map } = require('mutant')
33 const pull = require('pull-stream')
4+const last = require('lodash/last')
5+const get = require('lodash/last')
46
57 exports.gives = nest('app.html.thread')
68
79 exports.needs = nest({
@@ -12,12 +14,57 @@
1214 return nest('app.html.thread', thread)
1315
1416 function thread (source) {
1517 // location here can expected to be: { page: 'home' }
18+
19+ const chunkedThread = buildChunkedThreadObs(source)
20+
1621 const { goTo } = api.app.sync
22+ const threadView = h('Thread',
23+ map(chunkedThread, chunk => {
24+ return h('div' , [
25+ h('div', '---'),
1726
18- return h('Thread', [
19- 'thread content'
20- ])
27+ map(chunk, msg => {
28+ return h('div', {style: { margin: '10px', background: 'white' }}, msg.value.content.text) // TODO (mix): use lodash/get
29+ })
30+ ])
31+ })
32+ )
33+
34+ return threadView
2135 }
2236 }
2337
38+function buildChunkedThreadObs (source) {
39+ var chunkedThread = MutantArray()
40+
41+ var _chunk = null
42+ var _lastMsg = null
43+
44+ pull(
45+ source,
46+ pull.drain(msg => {
47+ if (!_lastMsg || !isSameAuthor(_lastMsg, msg))
48+ createNewChunk(msg)
49+ else
50+ _chunk.push(msg)
51+
52+ _lastMsg = msg
53+ })
54+ )
55+
56+ function createNewChunk (msg) {
57+ const newChunk = MutantArray()
58+ newChunk.push(msg)
59+ chunkedThread.push(newChunk)
60+ _chunk = newChunk
61+ }
62+
63+ return chunkedThread
64+}
65+
66+function isSameAuthor (msgA, msgB) {
67+ // TODO (mix) use lodash/get
68+ return msgA.value.author === msgB.value.author
69+}
70+
app/html/thread.mcssView
@@ -1,4 +1,5 @@
11 Thread {
2- background-color: lightblue
2+ background-color: lightgrey
3+ padding: 1rem
34 }
45
app/page/private.jsView
@@ -1,7 +1,10 @@
11 const nest = require('depnest')
22 const { h } = require('mutant')
33
4+const pull = require('pull-stream')
5+const dummyThread = require('../../test/fixtures/thread')
6+
47 exports.gives = nest('app.page.private')
58
69 exports.needs = nest({
710 'app.sync.goTo': 'first',
@@ -14,9 +17,11 @@
1417 function private (location) {
1518 // location here can expected to be an ssb-message
1619 const { goTo } = api.app.sync
1720
18- const thread = api.app.html.thread()
21+ // TODO (mix) : swap for actual source, derived from location
22+ const source = pull.values(dummyThread)
23+ const thread = api.app.html.thread(source)
1924
2025 return h('div', [
2126 h('h1', 'Private message'),
2227 h('div', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'),
main.jsView
@@ -12,9 +12,8 @@
1212 const sockets = combine(
1313 ticktack,
1414 patchcore
1515 )
16-debugger
1716
1817 const api = entry(sockets, nest('app.html.app', 'first'))
1918
2019 const app = api.app.html.app()

Built with git-ssb-web