Commit 5dfdb498b7d97dce1f07169d43146aa777dd3431
computed: bypass broadcast by returning computed.NO_CHANGE
Matt McKegg committed on 7/20/2016, 4:08:58 AMParent: 2225e7077f112ee10318157443adbbdb5748a50e
Files changed
computed.js | changed |
computed.js | ||
---|---|---|
@@ -1,15 +1,18 @@ | ||
1 | 1 … | /* A lazy binding take on computed */ |
2 | 2 … | // - doesn't start watching observables until itself is watched, and then releases if unwatched |
3 | 3 … | // - avoids memory/watcher leakage |
4 | 4 … | // - 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 | |
6 | 7 … | |
7 | 8 … | var resolve = require('./resolve') |
8 | 9 … | var isObservable = require('./is-observable') |
9 | 10 … | |
10 | 11 … | module.exports = computed |
11 | 12 … | |
13 … | +computed.NO_CHANGE = {} | |
14 … | + | |
12 | 15 … | function computed (observables, lambda) { |
13 | 16 … | if (!Array.isArray(observables)) { |
14 | 17 … | observables = [observables] |
15 | 18 … | } |
@@ -97,8 +100,13 @@ | ||
97 | 100 … | |
98 | 101 … | if (changed || !initialized) { |
99 | 102 … | initialized = true |
100 | 103 … | var newComputedValue = lambda.apply(null, values) |
104 … | + | |
105 … | + if (newComputedValue === computed.NO_CHANGE) { | |
106 … | + return false | |
107 … | + } | |
108 … | + | |
101 | 109 … | if (newComputedValue !== computedValue || (isReferenceType(newComputedValue) && !isObservable(newComputedValue))) { |
102 | 110 … | if (releaseInner) { |
103 | 111 … | releaseInner() |
104 | 112 … | inner = releaseInner = null |
Built with git-ssb-web