Commit 17b2f7bb97825fb0650e466902418fcf8442c5fd
refactor state/obs getter to be more early-return pattern
mix irving committed on 8/17/2017, 4:14:10 AMParent: 2f3728d62f4995c91fc3de4f0ca6b5a08ceccfb7
Files changed
state/obs.js | changed |
state/obs.js | ||
---|---|---|
@@ -52,23 +52,22 @@ | ||
52 | 52 | //value recovered from localStorage |
53 | 53 | initial |
54 | 54 | ) |
55 | 55 | |
56 | - var getting = {}, g= 0, t = 0 | |
56 | + var getting = {}, g = 0, t = 0 | |
57 | 57 | var maybe = {} |
58 | 58 | 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 | + }) | |
71 | 70 | }) |
72 | 71 | |
73 | 72 | //stream live messages. this *should* work. |
74 | 73 | //there is no back pressure on new events |
Built with git-ssb-web