Browse Source

refactor: split subscription inilitalizers into separate methods

pull/4216/head
Arman Ozak 6 years ago
parent
commit
6e01b27fbf
  1. 44
      npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts

44
npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts

@ -26,6 +26,30 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
this.table.externalSorting = true; this.table.externalSorting = true;
} }
private subscribeToPage() {
const sub = this.table.page.subscribe(({ offset }) => {
this.list.page = offset;
this.table.offset = offset;
});
this.subscription.add(sub);
}
private subscribeToSort() {
const sub = this.table.sort.subscribe(({ sorts: [{ prop, dir }] }) => {
this.list.sortKey = prop;
this.list.sortOrder = dir;
});
this.subscription.add(sub);
}
private subscribeToIsLoading() {
const sub = this.list.isLoading$.subscribe(loading => {
this.table.loadingIndicator = loading;
this.cdRef.markForCheck();
});
this.subscription.add(sub);
}
ngOnChanges({ list }: SimpleChanges) { ngOnChanges({ list }: SimpleChanges) {
if (!list.firstChange) return; if (!list.firstChange) return;
@ -39,22 +63,8 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
} }
ngOnInit() { ngOnInit() {
const subPage = this.table.page.subscribe(({ offset }) => { this.subscribeToPage();
this.list.page = offset; this.subscribeToSort();
this.table.offset = offset; this.subscribeToIsLoading();
});
this.subscription.add(subPage);
const subSort = this.table.sort.subscribe(({ sorts: [{ prop, dir }] }) => {
this.list.sortKey = prop;
this.list.sortOrder = dir;
});
this.subscription.add(subSort);
const subIsLoading = this.list.isLoading$.subscribe(loading => {
this.table.loadingIndicator = loading;
this.cdRef.markForCheck();
});
this.subscription.add(subIsLoading);
} }
} }

Loading…
Cancel
Save