Skip to content

Commit

Permalink
fix: do not update instance if it was realigned
Browse files Browse the repository at this point in the history
Closes: #90
  • Loading branch information
cristinecula committed Oct 30, 2019
1 parent 1076b2e commit 7cc1b8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 0 additions & 7 deletions cosmoz-data-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,6 @@ class CosmozDataNav extends translatable(mixinBehaviors([IronResizableBehavior],
return;
}

renderedElement.item = item;
const instance = renderedElement.__instance,
props = Object.assign({ [this.as]: item }, this._getBaseProps(index));

Object.keys(props).forEach(key => instance._setPendingProperty(key, props[key]));
instance._flushProperties();

this.splice('_elements', renderedIndex, 1);
this.splice('_elements', elementIndex, 0, renderedElement);
}
Expand Down
12 changes: 12 additions & 0 deletions test/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@
expect(selectedSlide(nav).textContent).to.equal('id: d,index: 1');
});

it('realigns element if already rendered', () => {
nav.items = [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }];
nav.selected = 1;
flushRenderQueue(nav);
expect(selectedSlide(nav).textContent).to.equal('id: b,index: 1');

nav.items = [{ id: 'a' }, { id: 'c' }, { id: 'd' }];
expect(nav.selected).to.equal(1);
flushRenderQueue(nav);
expect(selectedSlide(nav).textContent).to.equal('id: c,index: 1');
});

it('updates `selected` if there are not enough items', () => {
nav.items = [{id: 'a'}, {id: 'e'}];
nav.selected = 1;
Expand Down

0 comments on commit 7cc1b8d

Please sign in to comment.