Skip to content

Commit 8707cd9

Browse files
committed
Fixed issue with array splice on item add in combination with firebase
1 parent 00a77db commit 8707cd9

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

exmg-tbody.html

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@
198198
* Select an item from an event object.
199199
*/
200200
_selectionHandler(e) {
201-
console.log('_selectionHandler', e);
202-
// debugger;
203201
var m = e.path.find(entry => {
204202
return entry.classList && entry.classList.contains('tr');
205203
});
@@ -238,12 +236,9 @@
238236

239237
connectedCallback() {
240238
super.connectedCallback();
241-
242-
console.log('connectedCallback');
243239
if (this._physicalCount === 0) {
244-
this._debounceTemplate(this._render);
240+
this._debounceRender(this._render);
245241
}
246-
247242
}
248243

249244
_debounceRender(cb) {
@@ -277,7 +272,6 @@
277272
* to `items`, splices or updates to a single item.
278273
*/
279274
_itemsChanged(change) {
280-
console.log('_itemsChanged', change);
281275
if (change.path === 'items') {
282276
this.items = this.items || [];
283277
this._physicalCount = this._physicalCount || 0;
@@ -290,7 +284,9 @@
290284
}, this);
291285
this._debounceRender(this._render);
292286
} else {
293-
this._forwardItemPath(change.path, change.value);
287+
if(change.path !== 'items.length') {
288+
this._forwardItemPath(change.path, change.value);
289+
}
294290
}
295291
}
296292

@@ -306,22 +302,16 @@
306302
}
307303
var idx = parseInt(path.substring(0, dot), 10);
308304
var offscreenItem = this._offscreenFocusedItem;
309-
var isIndexRendered = this._isIndexRendered(idx);
310-
var inst = this.modelForElement(this._physicalItems[this._getPhysicalIndex(idx)]);
311305

306+
var inst = this.modelForElement(this._physicalItems[idx]);
307+
312308
if (!inst || inst[this.indexAs] !== idx) {
313309
return;
314310
}
315311
path = path.substring(dot);
316312
path = this.as + (path ? '.' + path : '');
317313
inst._setPendingPropertyOrPath(path, value, false, true);
318314
inst._flushProperties && inst._flushProperties(true);
319-
// TODO(blasten): V1 doesn't do this and it's a bug
320-
if (isIndexRendered) {
321-
this._updateMetrics([idx]);
322-
this._positionItems();
323-
this._updateScrollerSize();
324-
}
325315
}
326316

327317
/**
@@ -330,15 +320,13 @@
330320
* @param {number} size Size of the pool
331321
*/
332322
_createPool(size) {
333-
console.log('_createPool');
334323
var physicalItems = new Array(size);
335324
this._ensureTemplatized();
336325
for (var i = 0; i < size; i++) {
337326
var inst = this.stamp(null);
338327
// First element child is item; Safari doesn't support children[0]
339328
// on a doc fragment.
340329
physicalItems[i] = inst.root.querySelector('*');
341-
console.log('_createPool', physicalItems[i]);
342330
this.shadowRoot.appendChild(inst.root);
343331
}
344332
return physicalItems;
@@ -396,7 +384,6 @@
396384
*/
397385
_assignModels(itemSet) {
398386
var count = 0;
399-
console.log('_assignModels, ', this._physicalItems, this._physicalCount);
400387
this._physicalItems.forEach((el) => {
401388
var inst = this.modelForElement(el);
402389
var item = this.items[count];
@@ -421,7 +408,6 @@
421408

422409
/* Templatizer bindings for v2 */
423410
_forwardHostPropV2(prop, value) {
424-
console.log('_forwardHostPropV2', prop, value);
425411
(this._physicalItems || [])
426412
.concat([this._offscreenFocusedItem, this._focusBackfillItem])
427413
.forEach(function(item) {
@@ -432,7 +418,6 @@
432418
}
433419

434420
_notifyInstancePropV2(inst, prop, value) {
435-
console.log('_notifyInstancePropV2', inst, prop, value);
436421
if (Polymer.Path.matches(this.as, prop)) {
437422
var idx = inst[this.indexAs];
438423
if (prop == this.as) {
@@ -449,7 +434,6 @@
449434
* @param {Object} item The item instance.
450435
*/
451436
selectItem(item) {
452-
console.log('selectItem', item);
453437
return this.selectIndex(this.items.indexOf(item));
454438
}
455439

@@ -460,8 +444,6 @@
460444
* @param {Object} index The item instance.
461445
*/
462446
selectIndex(index) {
463-
464-
console.log('selectIndex', index, this.multiSelection,this.selectedItem);
465447
if (index < 0 || index >= this.items) {
466448
return;
467449
}
@@ -475,7 +457,6 @@
475457
}
476458

477459
this.$.selector.selectIndex(index);
478-
479460
}
480461

481462
/**
@@ -484,7 +465,6 @@
484465
* @method clearSelection
485466
*/
486467
clearSelection() {
487-
console.log('clearSelection');
488468
if(this._physicalItems) {
489469
this._physicalItems.map((el) => {
490470
this.modelForElement(el)[this.selectedAs] = false;
@@ -500,7 +480,6 @@
500480
* @param {Object} item The item instance.
501481
*/
502482
deselectItem(item) {
503-
console.log('deselectItem', item);
504483
return this.deselectIndex(this.items.indexOf(item));
505484
}
506485

@@ -540,10 +519,8 @@
540519
* @param {Object} index The index of the item in the items array.
541520
*/
542521
toggleSelectionForIndex(index) {
543-
console.log('toggleSelectionForIndex', index, this.$.selector.isIndexSelected(index));
544522
var isSelected = this.$.selector.isIndexSelected
545523
? this.$.selector.isIndexSelected(index) : this.$.selector.isSelected(this.items[index]);
546-
console.log('isSelected', isSelected);
547524
isSelected ? this.deselectIndex(index) : this.selectIndex(index);
548525
}
549526

0 commit comments

Comments
 (0)