git ssb

2+

mixmix / ticktack



Commit 17b2f7bb97825fb0650e466902418fcf8442c5fd

refactor state/obs getter to be more early-return pattern

mix irving committed on 8/17/2017, 4:14:10 AM
Parent: 2f3728d62f4995c91fc3de4f0ca6b5a08ceccfb7

Files changed

state/obs.jschanged
state/obs.jsView
@@ -52,23 +52,22 @@
5252 //value recovered from localStorage
5353 initial
5454 )
5555
56- var getting = {}, g= 0, t = 0
56+ var getting = {}, g = 0, t = 0
5757 var maybe = {}
5858 obs(function (state) {
59- if(state.effect) {
60- var effect = state.effect
61- state.effect = null
62- if(!getting[effect.key]) {
63- getting[effect.key] = true
64- api.sbot.async.get(effect.key, function (err, msg) {- console.log('g', g, ++t)
65- if(msg) {
66- obs.set(reduce(obs.value, {key: effect.key, value: msg}))
67- }
68- })
69- }
70- }
59+ var effect = state.effect
60+ if(!effect) return
61+
62+ state.effect = null
63+ if(getting[effect.key]) return
64+
65+ getting[effect.key] = true
66+ api.sbot.async.get(effect.key, (err, msg) => {
67+ if (!msg) return
68+ obs.set(reduce(obs.value, {key: effect.key, value: msg}))
69+ })
7170 })
7271
7372 //stream live messages. this *should* work.
7473 //there is no back pressure on new events

Built with git-ssb-web