git ssb

1+

Matt McKegg / mutant



Commit 5dfdb498b7d97dce1f07169d43146aa777dd3431

computed: bypass broadcast by returning computed.NO_CHANGE

Matt McKegg committed on 7/20/2016, 4:08:58 AM
Parent: 2225e7077f112ee10318157443adbbdb5748a50e

Files changed

computed.jschanged
computed.jsView
@@ -1,15 +1,18 @@
11 /* A lazy binding take on computed */
22 // - doesn't start watching observables until itself is watched, and then releases if unwatched
33 // - avoids memory/watcher leakage
44 // - attaches to inner observables if these are returned from value
5-// - doesn't broadcast if value is same as last value (and is `value type` or observable, can't make assuptions about reference types)
5 +// - doesn't broadcast if value is same as last value (and is `value type` or observable - can't make assuptions about reference types)
6 +// - doesn't broadcast if value is computed.NO_CHANGE
67
78 var resolve = require('./resolve')
89 var isObservable = require('./is-observable')
910
1011 module.exports = computed
1112
13 +computed.NO_CHANGE = {}
14 +
1215 function computed (observables, lambda) {
1316 if (!Array.isArray(observables)) {
1417 observables = [observables]
1518 }
@@ -97,8 +100,13 @@
97100
98101 if (changed || !initialized) {
99102 initialized = true
100103 var newComputedValue = lambda.apply(null, values)
104 +
105 + if (newComputedValue === computed.NO_CHANGE) {
106 + return false
107 + }
108 +
101109 if (newComputedValue !== computedValue || (isReferenceType(newComputedValue) && !isObservable(newComputedValue))) {
102110 if (releaseInner) {
103111 releaseInner()
104112 inner = releaseInner = null

Built with git-ssb-web