Commit 36fd23a2593c35e462fe4c1a3ff057b0a4dafa83
set local state, and batch mode requests
Dominic Tarr committed on 6/5/2017, 11:39:36 AMParent: b1d492d4ce5e4a3cf220de4e978b82450fc9a3df
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -186,17 +186,24 @@ | ||
186 | 186 … | }, |
187 | 187 … | onAppend: function (msg) { |
188 | 188 … | var k = msg.author |
189 | 189 … | //TMP, call a user provided function to decide how to handle this. |
190 | - if(!states[k]) maybeQueue(k, states[k] = S.init(msg.sequence)) | |
190 … | +// if(!states[k]) { | |
191 … | +// console.log('ON_APPEND', msg.author, msg.sequence) | |
192 … | +// maybeQueue(k, states[k] = S.init(msg.sequence)) | |
193 … | +// } | |
194 … | +// | |
191 | 195 … | if(states[k]) { |
192 | 196 … | maybeQueue(k, states[k] = S.appendMessage(states[k], msg)) |
193 | 197 … | checkNote(k) |
194 | 198 … | next() |
195 | 199 … | } |
196 | 200 … | }, |
197 | - request: function (id, seq) { | |
201 … | + //but what if you want to push in a bunch | |
202 … | + //of items but not trigger next just yet? | |
203 … | + request: function (id, seq, isSingle) { | |
198 | 204 … | //only allow updates if it's gonna change the state. |
205 … | + //this section should move into state.js | |
199 | 206 … | if(!states[id]) { |
200 | 207 … | states[id] = S.init(seq) |
201 | 208 … | readyNote[id] = true |
202 | 209 … | } |
@@ -204,14 +211,19 @@ | ||
204 | 211 … | states[id].local.seq == null || |
205 | 212 … | states[id].local.seq == -1 || |
206 | 213 … | (seq === -1 && states[id].local.seq != -1) |
207 | 214 … | ) { |
215 … | + //MUST set the local state, otherwise receiveMessage won't work. | |
216 … | + if(seq >= 0) states[id].local.seq = seq | |
208 | 217 … | states[id].ready = seq |
209 | 218 … | readyNote[id] = true |
210 | - next() | |
219 … | + if(isSingle !== false) { | |
220 … | + next() | |
221 … | + } | |
211 | 222 … | } |
212 | 223 … | }, |
213 | - states: states | |
224 … | + states: states, | |
225 … | + next: next | |
214 | 226 … | } |
215 | 227 … | |
216 | 228 … | if(opts.seqs) { |
217 | 229 … | for(var k in opts.seqs) |
@@ -221,5 +233,4 @@ | ||
221 | 233 … | |
222 | 234 … | } |
223 | 235 … | } |
224 | 236 … | |
225 | - |
Built with git-ssb-web