Commit 0e246ce681989f1a94e5ee1e8c1a6042d587c004
map: fix cleaning up of old listeners when list gets shorter
Matt McKegg committed on 9/7/2016, 1:28:07 PMParent: f69a37d1862b7bc2b9590d1514f049129243de67
Files changed
map.js | changed |
map.js | ||
---|---|---|
@@ -1,6 +1,7 @@ | ||
1 | 1 | var resolve = require('./resolve') |
2 | 2 | var LazyWatcher = require('./lib/lazy-watcher') |
3 | +var isReferenceType = require('./lib/is-reference-type') | |
3 | 4 | |
4 | 5 | module.exports = Map |
5 | 6 | |
6 | 7 | function Map (obs, lambda, opts) { |
@@ -61,8 +62,9 @@ | ||
61 | 62 | while (releases.length) { |
62 | 63 | releases.pop()() |
63 | 64 | } |
64 | 65 | rebindAll() |
66 | + lastValues.clear() | |
65 | 67 | } |
66 | 68 | |
67 | 69 | function update () { |
68 | 70 | var changed = false |
@@ -89,12 +91,14 @@ | ||
89 | 91 | } |
90 | 92 | |
91 | 93 | if (changed) { |
92 | 94 | // clean up cache |
95 | + var oldLength = items.length | |
93 | 96 | Array.from(lastValues.keys()).filter(notIncluded, obs).forEach(deleteEntry, lastValues) |
94 | 97 | items.length = getLength(obs) |
95 | 98 | 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++) { | |
97 | 101 | rebind(index) |
98 | 102 | } |
99 | 103 | } |
100 | 104 | |
@@ -122,9 +126,9 @@ | ||
122 | 126 | } |
123 | 127 | |
124 | 128 | function updateItem (i) { |
125 | 129 | var item = get(obs, i) |
126 | - if (typeof item === 'object') { | |
130 | + if (isReferenceType(item)) { | |
127 | 131 | raw[i] = lambda(item) |
128 | 132 | } else { |
129 | 133 | if (!lastValues.has(item)) { |
130 | 134 | lastValues.set(item, lambda(item)) |
Built with git-ssb-web