Skip to content

Commit

Permalink
fix: do not reset items when different input is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
daelmaak committed Feb 7, 2024
1 parent 0aec0f7 commit 834a23e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions libs/gallery/src/lib/components/gallery/gallery.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ describe('GalleryComponent', () => {
expect().nothing();
});

it('should not reset items when they are already set and different @Input() is changed', () => {
component.items = [{ src: 'src1' }, { src: 'src2' }];
fixture.detectChanges();

const items = component.items;
componentRef.setInput('thumbs', false);
fixture.detectChanges();

expect(component.items).toBe(items);
});

describe('emitters', () => {
beforeEach(fakeAsync(() => {
component.items = [{ src: 'src1' }, { src: 'src2' }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class GalleryComponent implements OnChanges {
}

ngOnChanges({ items }: StrictSimpleChanges<GalleryComponent>) {
if (!items?.currentValue) {
if (items && !items.currentValue) {
this.items = [];
}
}
Expand Down

0 comments on commit 834a23e

Please sign in to comment.