Commit e3dfe163bff09f8ef2d3a5f6da4544ac33f96c9c
refactor thread obs into it's own thing
Dominic Tarr committed on 8/11/2017, 11:08:48 AMParent: c150758bf6e1b53d32f0c670914cc96ff228b33b
Files changed
app/page/home.js | changed |
app/page/home.js | ||
---|---|---|
@@ -6,12 +6,12 @@ | ||
6 | 6 | const isString = require('lodash/isString') |
7 | 7 | const last = require('lodash/last') |
8 | 8 | const get = require('lodash/get') |
9 | 9 | const More = require('hypermore') |
10 | -exports.gives = nest('app.page.home') | |
11 | 10 | const morphdom = require('morphdom') |
12 | -const Next = require('pull-next') | |
13 | 11 | |
12 | +exports.gives = nest('app.page.home') | |
13 | + | |
14 | 14 | exports.needs = nest({ |
15 | 15 | 'about.html.image': 'first', |
16 | 16 | 'about.obs.name': 'first', |
17 | 17 | 'app.html.nav': 'first', |
@@ -19,9 +19,10 @@ | ||
19 | 19 | 'history.sync.push': 'first', |
20 | 20 | 'keys.sync.id': 'first', |
21 | 21 | 'message.sync.unbox': 'first', |
22 | 22 | 'message.html.markdown': 'first', |
23 | - 'translations.sync.strings': 'first' | |
23 | + 'translations.sync.strings': 'first', | |
24 | + 'state.obs.threads': 'first' | |
24 | 25 | }) |
25 | 26 | |
26 | 27 | function firstLine (text) { |
27 | 28 | if(text.length < 80 && !~text.indexOf('\n')) return text |
@@ -123,37 +124,14 @@ | ||
123 | 124 | } |
124 | 125 | return groupEl |
125 | 126 | } |
126 | 127 | |
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() | |
131 | 129 | |
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, | |
154 | 132 | function render (threads) { |
155 | - update(threads) | |
133 | + console.log('RENDER', JSON.stringify(threads).length) | |
156 | 134 | morphdom(container, |
157 | 135 | h('div.container', [ |
158 | 136 | //private section |
159 | 137 | h('section.updates -directMessage', [ |
@@ -194,17 +172,18 @@ | ||
194 | 172 | ]) |
195 | 173 | ]) |
196 | 174 | ) |
197 | 175 | return container |
198 | - }, | |
199 | - initial | |
176 | + } | |
200 | 177 | ) |
201 | 178 | |
179 | + | |
202 | 180 | return h('Page -home', [ |
203 | 181 | h('h1', 'Home'), |
204 | 182 | 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]) | |
207 | 185 | ]) |
208 | 186 | }) |
209 | 187 | } |
210 | 188 | |
189 | + |
Built with git-ssb-web