|
225 | 225 | } |
226 | 226 | }, |
227 | 227 | procEach: function(name, data, key, initOnly){ |
228 | | - var c, list, getkey, hash, items, nodes, proxyIndex, ns, i$, i, n, j, node, idx, expectedIdx, _, ps, this$ = this; |
| 228 | + var c, list, getkey, keycount, items, usekey, nodes, proxyIndex, ns, consumed, i$, i, n, k, j, node, idx, expectedIdx, _, ps, this$ = this; |
229 | 229 | key == null && (key = null); |
230 | 230 | c = typeof this._ctx === 'function' |
231 | 231 | ? this._ctx({ |
|
243 | 243 | ctxs: this._ctxs |
244 | 244 | }) || []; |
245 | 245 | getkey = this.handler[name].key; |
246 | | - hash = {}; |
| 246 | + keycount = {}; |
247 | 247 | items = []; |
248 | | - if (getkey) { |
249 | | - list.map(function(it){ |
250 | | - return hash[getkey(it)] = it; |
251 | | - }); |
252 | | - } else { |
| 248 | + usekey = !!getkey; |
| 249 | + if (!getkey) { |
253 | 250 | getkey = function(it){ |
254 | 251 | return it; |
255 | 252 | }; |
| 253 | + } else { |
| 254 | + list.map(function(n){ |
| 255 | + var k; |
| 256 | + if (typeof (k = getkey(n)) === 'object') { |
| 257 | + return; |
| 258 | + } |
| 259 | + return keycount[k] = (keycount[k] || 0) + 1; |
| 260 | + }); |
256 | 261 | } |
257 | 262 | nodes = data.nodes.filter(function(it){ |
258 | 263 | return it; |
259 | 264 | }).map(function(n){ |
260 | 265 | var k; |
261 | 266 | k = getkey(n._data); |
262 | | - if ((typeof k !== 'object' && !hash[k]) || (typeof k === 'object' && !in$(n._data, list))) { |
| 267 | + if ((typeof k !== 'object' && !usekey) || (typeof k === 'object' && !in$(n._data, list)) || (usekey && !keycount[k])) { |
263 | 268 | data.container.removeChild(n); |
264 | 269 | n._data = null; |
265 | 270 | } else { |
266 | 271 | items.push(k); |
| 272 | + if (usekey && keycount[k]) { |
| 273 | + keycount[k]--; |
| 274 | + } |
267 | 275 | } |
268 | 276 | return n; |
269 | 277 | }).filter(function(it){ |
|
274 | 282 | proxyIndex = data.container.childNodes.length; |
275 | 283 | } |
276 | 284 | ns = []; |
| 285 | + consumed = {}; |
277 | 286 | for (i$ = list.length - 1; i$ >= 0; --i$) { |
278 | 287 | i = i$; |
279 | 288 | n = list[i]; |
280 | | - if ((j = items.indexOf(getkey(n))) >= 0) { |
| 289 | + k = getkey(n); |
| 290 | + if (usekey && typeof k !== 'object') { |
| 291 | + consumed[k] = (consumed[k] || 0) + 1; |
| 292 | + } |
| 293 | + if ((j = items.indexOf(k)) >= 0) { |
281 | 294 | node = nodes[j]; |
| 295 | + items.splice(j, 1); |
| 296 | + nodes.splice(j, 1); |
282 | 297 | node._data = n; |
283 | 298 | if (!node._obj) { |
284 | 299 | node._obj = { |
|
304 | 319 | ns.splice(0, 0, node); |
305 | 320 | continue; |
306 | 321 | } |
| 322 | + if (usekey && typeof key !== 'object') { |
| 323 | + if (consumed[key] > 1) { |
| 324 | + continue; |
| 325 | + } |
| 326 | + } |
307 | 327 | node = data.node.cloneNode(true); |
308 | 328 | node._data = n; |
309 | 329 | node._obj = { |
|
0 commit comments