Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
[NG] Page size change was not triggering a state change (#1752)
Browse files Browse the repository at this point in the history
StateDebouncer calls added to the size setter.

Signed-off-by: Ivan Donchev <[email protected]>
  • Loading branch information
Jinnie authored and Shijir committed Nov 15, 2018
1 parent fb1da9b commit 8f92a8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/clr-angular/data/datagrid/datagrid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ export default function(): void {
expect(context.testComponent.nbRefreshed).toBe(1);
});

it('emits once when the page size changes', function() {
context.testComponent.nbRefreshed = 0;
const page: Page = context.getClarityProvider(Page);
page.size = 2;
context.detectChanges();
expect(context.testComponent.nbRefreshed).toBe(1);
page.size = 5;
context.detectChanges();
expect(context.testComponent.nbRefreshed).toBe(2);
page.resetPageSize();
expect(context.testComponent.nbRefreshed).toBe(3);
});

it('emits the complete state of the datagrid', function() {
context.testComponent.items = [1, 2, 3, 4, 5, 6];
context.detectChanges();
Expand Down
2 changes: 2 additions & 0 deletions src/clr-angular/data/datagrid/providers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class Page {
public set size(size: number) {
const oldSize = this._size;
if (size !== oldSize) {
this.stateDebouncer.changeStart();
this._size = size;
if (size === 0) {
this._current = 1;
Expand All @@ -34,6 +35,7 @@ export class Page {
// the size changing means the items inside the page are different
this._change.next(this._current);
this._sizeChange.next(this._size);
this.stateDebouncer.changeDone();
}
}

Expand Down

0 comments on commit 8f92a8c

Please sign in to comment.