git ssb

2+

mixmix / ticktack



Commit e3dfe163bff09f8ef2d3a5f6da4544ac33f96c9c

refactor thread obs into it's own thing

Dominic Tarr committed on 8/11/2017, 11:08:48 AM
Parent: c150758bf6e1b53d32f0c670914cc96ff228b33b

Files changed

app/page/home.jschanged
app/page/home.jsView
@@ -6,12 +6,12 @@
66 const isString = require('lodash/isString')
77 const last = require('lodash/last')
88 const get = require('lodash/get')
99 const More = require('hypermore')
10-exports.gives = nest('app.page.home')
1110 const morphdom = require('morphdom')
12-const Next = require('pull-next')
1311
12+exports.gives = nest('app.page.home')
13+
1414 exports.needs = nest({
1515 'about.html.image': 'first',
1616 'about.obs.name': 'first',
1717 'app.html.nav': 'first',
@@ -19,9 +19,10 @@
1919 'history.sync.push': 'first',
2020 'keys.sync.id': 'first',
2121 'message.sync.unbox': 'first',
2222 'message.html.markdown': 'first',
23- 'translations.sync.strings': 'first'
23+ 'translations.sync.strings': 'first',
24+ 'state.obs.threads': 'first'
2425 })
2526
2627 function firstLine (text) {
2728 if(text.length < 80 && !~text.indexOf('\n')) return text
@@ -123,37 +124,14 @@
123124 }
124125 return groupEl
125126 }
126127
127- var initial
128- try { initial = JSON.parse(localStorage.threadsState) }
129- catch (_) { }
130- var lastTimestamp = initial ? initial.last : Date.now()
128+ var threadsObs = api.state.obs.threads()
131129
132- var timer
133- function update (threadsState) {
134- clearTimeout(timer)
135- setTimeout(function () {
136- threadsState.last = lastTimestamp
137- localStorage.threadsState = JSON.stringify(threadsState)
138- }, 1000)
139- }
140-
141- var threadsObs = More(
142- threadReduce,
143- pull(
144- Next(function () {
145- return api.sbot.pull.log({reverse: true, limit: 500, lte: lastTimestamp})
146- }),
147- pull.map(function (data) {
148- lastTimestamp = data.timestamp
149- if(isObject(data.value.content)) return data
150- return api.message.sync.unbox(data)
151- }),
152- pull.filter(Boolean)
153- ),
130+ var threadsHtmlObs = More(
131+ threadsObs,
154132 function render (threads) {
155- update(threads)
133+ console.log('RENDER', JSON.stringify(threads).length)
156134 morphdom(container,
157135 h('div.container', [
158136 //private section
159137 h('section.updates -directMessage', [
@@ -194,17 +172,18 @@
194172 ])
195173 ])
196174 )
197175 return container
198- },
199- initial
176+ }
200177 )
201178
179+
202180 return h('Page -home', [
203181 h('h1', 'Home'),
204182 api.app.html.nav(),
205- threadsObs,
206- h('button', {'ev-click': threadsObs.more}, [strings.showMore])
183+ threadsHtmlObs,
184+ h('button', {'ev-click': threadsHtmlObs.more}, [strings.showMore])
207185 ])
208186 })
209187 }
210188
189+

Built with git-ssb-web