重构了loadingMore的代码

This commit is contained in:
Xu Chang 2025-07-19 13:09:40 +08:00
parent a702a08e8e
commit b880bc659b
5 changed files with 21 additions and 25 deletions

View File

@ -50,7 +50,6 @@ declare abstract class Node<ED extends EntityDict & BaseEntityDict> extends Feat
private count; private count;
protected executing: boolean; protected executing: boolean;
protected dirty?: boolean; protected dirty?: boolean;
protected loadingMore: boolean;
private extraData; private extraData;
private refreshing; private refreshing;
private refreshCallbacks; private refreshCallbacks;
@ -72,7 +71,6 @@ declare abstract class Node<ED extends EntityDict & BaseEntityDict> extends Feat
setExecuting(executing: boolean): void; setExecuting(executing: boolean): void;
protected startRefreshing(num: number): number | Promise<void>; protected startRefreshing(num: number): number | Promise<void>;
protected endRefreshing(num: number, error?: any): void; protected endRefreshing(num: number, error?: any): void;
isLoadingMore(): boolean;
saveExtraData(key: string, data: any): void; saveExtraData(key: string, data: any): void;
loadExtraData(key: string): any; loadExtraData(key: string): any;
isStale(): boolean; isStale(): boolean;
@ -102,6 +100,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
private getTotal?; private getTotal?;
private pagination; private pagination;
private sr; private sr;
private loadingMore;
private syncHandler; private syncHandler;
setFiltersAndSortedApplied(): void; setFiltersAndSortedApplied(): void;
private startLoading; private startLoading;
@ -115,6 +114,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
constructor(entity: T, schema: StorageSchema<ED>, cache: Cache<ED>, fullPath: string, projection?: ED[T]['Projection'] | (() => Promise<ED[T]['Projection']>), parent?: SingleNode<ED, keyof ED> | VirtualNode<ED>, path?: string, filters?: NamedFilterItem<ED, T>[], sorters?: NamedSorterItem<ED, T>[], getTotal?: number, pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, stale?: boolean); constructor(entity: T, schema: StorageSchema<ED>, cache: Cache<ED>, fullPath: string, projection?: ED[T]['Projection'] | (() => Promise<ED[T]['Projection']>), parent?: SingleNode<ED, keyof ED> | VirtualNode<ED>, path?: string, filters?: NamedFilterItem<ED, T>[], sorters?: NamedSorterItem<ED, T>[], getTotal?: number, pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, stale?: boolean);
getPagination(): Pagination; getPagination(): Pagination;
setPagination(pagination: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, dontRefresh?: true): void; setPagination(pagination: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, dontRefresh?: true): void;
isLoadingMore(): boolean;
addChild(path: string, node: SingleNode<ED, T>): void; addChild(path: string, node: SingleNode<ED, T>): void;
removeChild(path: string): void; removeChild(path: string): void;
getChild(path: string): SingleNode<ED, T>; getChild(path: string): SingleNode<ED, T>;

View File

@ -207,7 +207,6 @@ class Node extends Feature {
count = 0; count = 0;
executing = false; executing = false;
dirty; dirty;
loadingMore = false;
extraData = {}; extraData = {};
refreshing = 0; refreshing = 0;
refreshCallbacks = []; refreshCallbacks = [];
@ -282,9 +281,6 @@ class Node extends Feature {
}); });
} }
} }
isLoadingMore() {
return this.loadingMore;
}
saveExtraData(key, data) { saveExtraData(key, data) {
this.extraData[key] = data; this.extraData[key] = data;
} }
@ -312,7 +308,6 @@ class EntityNode extends Node {
this.projection = projection; this.projection = projection;
this.parent = parent; this.parent = parent;
this.dirty = undefined; this.dirty = undefined;
this.loadingMore = false;
this.executing = false; this.executing = false;
this.ulManager = new UpdateLogManager(this.schema, this.entity); this.ulManager = new UpdateLogManager(this.schema, this.entity);
} }
@ -362,6 +357,7 @@ class ListNode extends EntityNode {
getTotal; getTotal;
pagination = { ...DEFAULT_PAGINATION }; pagination = { ...DEFAULT_PAGINATION };
sr = {}; sr = {};
loadingMore = false;
syncHandler; syncHandler;
setFiltersAndSortedApplied() { setFiltersAndSortedApplied() {
this.filters.forEach(ele => ele.applied = true); this.filters.forEach(ele => ele.applied = true);
@ -643,6 +639,9 @@ class ListNode extends EntityNode {
this.refresh(0, false); this.refresh(0, false);
} }
} }
isLoadingMore() {
return this.loadingMore;
}
addChild(path, node) { addChild(path, node) {
assert(!this.children[path]); assert(!this.children[path]);
// assert(path.length > 10, 'List的path改成了id'); // assert(path.length > 10, 'List的path改成了id');
@ -2174,7 +2173,7 @@ export class RunningTree extends Feature {
} }
isLoadingMore(path) { isLoadingMore(path) {
const node = this.findNode(path); const node = this.findNode(path);
assert(!node || (node instanceof SingleNode || node instanceof ListNode)); assert(!node || (node instanceof ListNode));
return node?.isLoadingMore(); return node?.isLoadingMore();
} }
isExecuting(path) { isExecuting(path) {

View File

@ -50,7 +50,6 @@ declare abstract class Node<ED extends EntityDict & BaseEntityDict> extends Feat
private count; private count;
protected executing: boolean; protected executing: boolean;
protected dirty?: boolean; protected dirty?: boolean;
protected loadingMore: boolean;
private extraData; private extraData;
private refreshing; private refreshing;
private refreshCallbacks; private refreshCallbacks;
@ -72,7 +71,6 @@ declare abstract class Node<ED extends EntityDict & BaseEntityDict> extends Feat
setExecuting(executing: boolean): void; setExecuting(executing: boolean): void;
protected startRefreshing(num: number): number | Promise<void>; protected startRefreshing(num: number): number | Promise<void>;
protected endRefreshing(num: number, error?: any): void; protected endRefreshing(num: number, error?: any): void;
isLoadingMore(): boolean;
saveExtraData(key: string, data: any): void; saveExtraData(key: string, data: any): void;
loadExtraData(key: string): any; loadExtraData(key: string): any;
isStale(): boolean; isStale(): boolean;
@ -102,6 +100,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
private getTotal?; private getTotal?;
private pagination; private pagination;
private sr; private sr;
private loadingMore;
private syncHandler; private syncHandler;
setFiltersAndSortedApplied(): void; setFiltersAndSortedApplied(): void;
private startLoading; private startLoading;
@ -115,6 +114,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
constructor(entity: T, schema: StorageSchema<ED>, cache: Cache<ED>, fullPath: string, projection?: ED[T]['Projection'] | (() => Promise<ED[T]['Projection']>), parent?: SingleNode<ED, keyof ED> | VirtualNode<ED>, path?: string, filters?: NamedFilterItem<ED, T>[], sorters?: NamedSorterItem<ED, T>[], getTotal?: number, pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, stale?: boolean); constructor(entity: T, schema: StorageSchema<ED>, cache: Cache<ED>, fullPath: string, projection?: ED[T]['Projection'] | (() => Promise<ED[T]['Projection']>), parent?: SingleNode<ED, keyof ED> | VirtualNode<ED>, path?: string, filters?: NamedFilterItem<ED, T>[], sorters?: NamedSorterItem<ED, T>[], getTotal?: number, pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, stale?: boolean);
getPagination(): Pagination; getPagination(): Pagination;
setPagination(pagination: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, dontRefresh?: true): void; setPagination(pagination: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>, dontRefresh?: true): void;
isLoadingMore(): boolean;
addChild(path: string, node: SingleNode<ED, T>): void; addChild(path: string, node: SingleNode<ED, T>): void;
removeChild(path: string): void; removeChild(path: string): void;
getChild(path: string): SingleNode<ED, T>; getChild(path: string): SingleNode<ED, T>;

View File

@ -210,7 +210,6 @@ class Node extends Feature_1.Feature {
count = 0; count = 0;
executing = false; executing = false;
dirty; dirty;
loadingMore = false;
extraData = {}; extraData = {};
refreshing = 0; refreshing = 0;
refreshCallbacks = []; refreshCallbacks = [];
@ -285,9 +284,6 @@ class Node extends Feature_1.Feature {
}); });
} }
} }
isLoadingMore() {
return this.loadingMore;
}
saveExtraData(key, data) { saveExtraData(key, data) {
this.extraData[key] = data; this.extraData[key] = data;
} }
@ -315,7 +311,6 @@ class EntityNode extends Node {
this.projection = projection; this.projection = projection;
this.parent = parent; this.parent = parent;
this.dirty = undefined; this.dirty = undefined;
this.loadingMore = false;
this.executing = false; this.executing = false;
this.ulManager = new UpdateLogManager(this.schema, this.entity); this.ulManager = new UpdateLogManager(this.schema, this.entity);
} }
@ -365,6 +360,7 @@ class ListNode extends EntityNode {
getTotal; getTotal;
pagination = { ...DEFAULT_PAGINATION }; pagination = { ...DEFAULT_PAGINATION };
sr = {}; sr = {};
loadingMore = false;
syncHandler; syncHandler;
setFiltersAndSortedApplied() { setFiltersAndSortedApplied() {
this.filters.forEach(ele => ele.applied = true); this.filters.forEach(ele => ele.applied = true);
@ -646,6 +642,9 @@ class ListNode extends EntityNode {
this.refresh(0, false); this.refresh(0, false);
} }
} }
isLoadingMore() {
return this.loadingMore;
}
addChild(path, node) { addChild(path, node) {
(0, assert_1.assert)(!this.children[path]); (0, assert_1.assert)(!this.children[path]);
// assert(path.length > 10, 'List的path改成了id'); // assert(path.length > 10, 'List的path改成了id');
@ -2177,7 +2176,7 @@ class RunningTree extends Feature_1.Feature {
} }
isLoadingMore(path) { isLoadingMore(path) {
const node = this.findNode(path); const node = this.findNode(path);
(0, assert_1.assert)(!node || (node instanceof SingleNode || node instanceof ListNode)); (0, assert_1.assert)(!node || (node instanceof ListNode));
return node?.isLoadingMore(); return node?.isLoadingMore();
} }
isExecuting(path) { isExecuting(path) {

View File

@ -259,7 +259,6 @@ abstract class Node<ED extends EntityDict & BaseEntityDict> extends Feature {
private count: number = 0; private count: number = 0;
protected executing: boolean = false; protected executing: boolean = false;
protected dirty?: boolean; protected dirty?: boolean;
protected loadingMore: boolean = false;
private extraData: Record<string, any> = {}; private extraData: Record<string, any> = {};
private refreshing: number = 0; private refreshing: number = 0;
private refreshCallbacks: Array<[() => void, (error?: any) => void]> = []; private refreshCallbacks: Array<[() => void, (error?: any) => void]> = [];
@ -361,10 +360,6 @@ abstract class Node<ED extends EntityDict & BaseEntityDict> extends Feature {
} }
} }
isLoadingMore() {
return this.loadingMore;
}
saveExtraData(key: string, data: any) { saveExtraData(key: string, data: any) {
this.extraData[key] = data; this.extraData[key] = data;
} }
@ -402,7 +397,6 @@ abstract class EntityNode<
this.projection = projection; this.projection = projection;
this.parent = parent; this.parent = parent;
this.dirty = undefined; this.dirty = undefined;
this.loadingMore = false;
this.executing = false; this.executing = false;
this.ulManager = new UpdateLogManager(this.schema, this.entity); this.ulManager = new UpdateLogManager(this.schema, this.entity);
} }
@ -467,6 +461,7 @@ class ListNode<
private getTotal?: number; private getTotal?: number;
private pagination: Pagination = { ...DEFAULT_PAGINATION }; private pagination: Pagination = { ...DEFAULT_PAGINATION };
private sr: Record<string, any> = {}; private sr: Record<string, any> = {};
private loadingMore: boolean = false;
private syncHandler: (records: OpRecord<ED>[]) => void; private syncHandler: (records: OpRecord<ED>[]) => void;
@ -799,6 +794,11 @@ class ListNode<
} }
} }
isLoadingMore() {
return this.loadingMore;
}
addChild(path: string, node: SingleNode<ED, T>) { addChild(path: string, node: SingleNode<ED, T>) {
assert(!this.children[path]); assert(!this.children[path]);
// assert(path.length > 10, 'List的path改成了id'); // assert(path.length > 10, 'List的path改成了id');
@ -2643,9 +2643,7 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
isLoadingMore(path: string) { isLoadingMore(path: string) {
const node = this.findNode(path); const node = this.findNode(path);
assert( assert(!node || (node instanceof ListNode));
!node || (node instanceof SingleNode || node instanceof ListNode)
);
return node?.isLoadingMore(); return node?.isLoadingMore();
} }