Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not update instance if it was realigned #101

Merged
merged 3 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cosmoz-data-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,10 @@ 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]));
// update instance's data-nav related props
const instance = renderedElement.__instance;
Object.entries(this._getBaseProps(index))
.forEach(([key, value]) => instance._setPendingProperty(key, value));
instance._flushProperties();

this.splice('_elements', renderedIndex, 1);
Expand Down
17 changes: 15 additions & 2 deletions test/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<script type="module">
/* eslint-disable max-lines-per-function, max-statements, max-nested-callbacks */
import { flushRenderQueue, selectedSlide } from './helpers/utils';
import { flush as syncFlush } from '@polymer/polymer/lib/utils/flush';

describe('cosmoz-data-nav', () => {
describe('constructor', () => {
Expand Down Expand Up @@ -92,12 +93,12 @@

context('properties', () => {
let nav;
beforeEach(done => {
beforeEach(() => {
nav = fixture('basic');
nav._templatesObserver.flush();
nav.items = [{id: 1}, {id: 2}, {id: 3}];
flushRenderQueue(nav);
setTimeout(done, 50);
syncFlush();
});

describe('animating', () => {
Expand Down Expand Up @@ -253,6 +254,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