From 16c0db8d880b491b4b832afc9b8ac354094084d5 Mon Sep 17 00:00:00 2001 From: cipchk Date: Fri, 4 Aug 2023 16:29:13 +0800 Subject: [PATCH 1/3] refactor(abc:st): use `Observable` instead of `Promise` of load - close https://github.com/ng-alain/ng-alain/issues/2233 --- packages/abc/st/st-data-source.ts | 6 +- packages/abc/st/st-td.component.html | 2 +- packages/abc/st/st.component.ts | 167 +++++++++++-------------- packages/abc/st/test/base.spec.ts | 6 +- packages/abc/st/test/st-filter.spec.ts | 3 +- packages/abc/st/test/st.spec.ts | 46 +++---- 6 files changed, 101 insertions(+), 129 deletions(-) diff --git a/packages/abc/st/st-data-source.ts b/packages/abc/st/st-data-source.ts index cc9a5afb0..51080aa7c 100644 --- a/packages/abc/st/st-data-source.ts +++ b/packages/abc/st/st-data-source.ts @@ -40,7 +40,7 @@ export interface STDataSourceOptions { pi: number; ps: number; paginator: boolean; - data: string | STData[] | Observable; + data?: string | STData[] | Observable; total: number; req: STReq; res: STRes; @@ -127,8 +127,8 @@ export class STDataSource { return deepCopy(ret); }) ); - } else if (Array.isArray(data)) { - data$ = of(data); + } else if (data == null || Array.isArray(data)) { + data$ = of(data ?? []); } else { // a cold observable data$ = data; diff --git a/packages/abc/st/st-td.component.html b/packages/abc/st/st-td.component.html index fd2d98af1..18d43d670 100644 --- a/packages/abc/st/st-td.component.html +++ b/packages/abc/st/st-td.component.html @@ -45,7 +45,7 @@ #render [ngTemplateOutlet]="c.__render!" [ngTemplateOutletContext]="{ $implicit: i, index: index, column: c }" -> +/>