git ssb

1+

Matt McKegg / mutant



Commit 0e246ce681989f1a94e5ee1e8c1a6042d587c004

map: fix cleaning up of old listeners when list gets shorter

Matt McKegg committed on 9/7/2016, 1:28:07 PM
Parent: f69a37d1862b7bc2b9590d1514f049129243de67

Files changed

map.jschanged
map.jsView
@@ -1,6 +1,7 @@
11 var resolve = require('./resolve')
22 var LazyWatcher = require('./lib/lazy-watcher')
3+var isReferenceType = require('./lib/is-reference-type')
34
45 module.exports = Map
56
67 function Map (obs, lambda, opts) {
@@ -61,8 +62,9 @@
6162 while (releases.length) {
6263 releases.pop()()
6364 }
6465 rebindAll()
66+ lastValues.clear()
6567 }
6668
6769 function update () {
6870 var changed = false
@@ -89,12 +91,14 @@
8991 }
9092
9193 if (changed) {
9294 // clean up cache
95+ var oldLength = items.length
9396 Array.from(lastValues.keys()).filter(notIncluded, obs).forEach(deleteEntry, lastValues)
9497 items.length = getLength(obs)
9598 values.length = items.length
96- for (var index = items.length; index < raw.length; index++) {
99+ raw.length = items.length
100+ for (var index = items.length; index < oldLength; index++) {
97101 rebind(index)
98102 }
99103 }
100104
@@ -122,9 +126,9 @@
122126 }
123127
124128 function updateItem (i) {
125129 var item = get(obs, i)
126- if (typeof item === 'object') {
130+ if (isReferenceType(item)) {
127131 raw[i] = lambda(item)
128132 } else {
129133 if (!lastValues.has(item)) {
130134 lastValues.set(item, lambda(item))

Built with git-ssb-web