恢复了clean的逻辑

This commit is contained in:
Xu Chang 2023-09-28 16:43:06 +08:00
parent e9fe10044e
commit 112a0200e6
5 changed files with 66 additions and 126 deletions

View File

@ -126,7 +126,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
refresh(pageNumber?: number, getCount?: true, append?: boolean): Promise<void>;
loadMore(): Promise<void>;
setCurrentPage(currentPage: number, append?: boolean): void;
clean(preserveAfterExecute?: true): void;
clean(): void;
getChildOperation(child: SingleNode<ED, T, Cxt, FrontCxt, AD>): ED[T]["CreateSingle"] | ED[T]["Update"] | ED[T]["Remove"] | undefined;
getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined;
}
@ -165,7 +165,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
}> | undefined;
getProjection(withDecendants?: boolean): ED[T]["Selection"]["data"] | undefined;
refresh(): Promise<void>;
clean(preserveAfterExecute?: true): void;
clean(): void;
private getFilter;
getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined;
/**
@ -201,7 +201,7 @@ declare class VirtualNode<ED extends EntityDict & BaseEntityDict, Cxt extends As
isLoading(): boolean;
doBeforeTrigger(): Promise<void>;
doAfterTrigger(): Promise<void>;
clean(preserveAfterExecute?: true): void;
clean(): void;
checkIfClean(): void;
}
export type CreateNodeOptions<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {

View File

@ -762,29 +762,22 @@ class ListNode extends Node {
setCurrentPage(currentPage, append) {
this.refresh(currentPage, undefined, append);
}
clean(preserveAfterExecute) {
clean() {
if (this.dirty) {
const originUpdates = this.updates;
this.updates = {};
if (preserveAfterExecute) {
for (const k in originUpdates) {
if (originUpdates[k].afterExecute) {
this.updates[k] = {
afterExecute: originUpdates[k].afterExecute,
};
}
for (const k in originUpdates) {
if (originUpdates[k].afterExecute) {
this.updates[k] = {
afterExecute: originUpdates[k].afterExecute,
};
}
}
for (const k in this.children) {
this.children[k].clean(preserveAfterExecute);
}
if (!preserveAfterExecute) {
this.dirty = undefined;
}
else {
// preserveAfterExecute一定发生在execute后面的cache会publish
this.publish();
this.children[k].clean();
}
this.dirty = undefined;
this.publish();
}
}
getChildOperation(child) {
@ -1186,23 +1179,14 @@ class SingleNode extends Node {
this.publish();
}
}
clean(preserveAfterExecute) {
clean() {
if (this.dirty) {
if (preserveAfterExecute && this.operation?.afterExecute) {
this.operation.operation = undefined;
}
else {
this.operation = undefined;
}
this.operation = undefined;
for (const child in this.children) {
this.children[child].clean(preserveAfterExecute);
}
if (!preserveAfterExecute) {
this.dirty = undefined;
}
else {
this.publish();
this.children[child].clean();
}
this.dirty = undefined;
this.publish();
}
}
getFilter() {
@ -1461,16 +1445,12 @@ class VirtualNode extends Feature {
}
this.dirty = false;
}
clean(preserveAfterExecute) {
clean() {
for (const ele in this.children) {
this.children[ele].clean(preserveAfterExecute);
}
if (!preserveAfterExecute) {
this.dirty = false;
}
else {
this.publish();
this.children[ele].clean();
}
this.dirty = false;
this.publish();
}
checkIfClean() {
for (const k in this.children) {
@ -1891,13 +1871,13 @@ export class RunningTree extends Feature {
.filter((ele) => !!ele)
.map((ele) => ele.operation), undefined, () => {
// 清空缓存
node.clean(true);
node.clean();
node.setExecuting(false);
});
await node.doAfterTrigger();
return result;
}
node.clean(true);
node.clean();
node.setExecuting(false);
await node.doAfterTrigger();
return { message: 'No Operation' };

View File

@ -126,7 +126,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
refresh(pageNumber?: number, getCount?: true, append?: boolean): Promise<void>;
loadMore(): Promise<void>;
setCurrentPage(currentPage: number, append?: boolean): void;
clean(preserveAfterExecute?: true): void;
clean(): void;
getChildOperation(child: SingleNode<ED, T, Cxt, FrontCxt, AD>): ED[T]["CreateSingle"] | ED[T]["Update"] | ED[T]["Remove"] | undefined;
getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined;
}
@ -165,7 +165,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
}> | undefined;
getProjection(withDecendants?: boolean): ED[T]["Selection"]["data"] | undefined;
refresh(): Promise<void>;
clean(preserveAfterExecute?: true): void;
clean(): void;
private getFilter;
getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined;
/**
@ -201,7 +201,7 @@ declare class VirtualNode<ED extends EntityDict & BaseEntityDict, Cxt extends As
isLoading(): boolean;
doBeforeTrigger(): Promise<void>;
doAfterTrigger(): Promise<void>;
clean(preserveAfterExecute?: true): void;
clean(): void;
checkIfClean(): void;
}
export type CreateNodeOptions<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {

View File

@ -765,29 +765,22 @@ class ListNode extends Node {
setCurrentPage(currentPage, append) {
this.refresh(currentPage, undefined, append);
}
clean(preserveAfterExecute) {
clean() {
if (this.dirty) {
const originUpdates = this.updates;
this.updates = {};
if (preserveAfterExecute) {
for (const k in originUpdates) {
if (originUpdates[k].afterExecute) {
this.updates[k] = {
afterExecute: originUpdates[k].afterExecute,
};
}
for (const k in originUpdates) {
if (originUpdates[k].afterExecute) {
this.updates[k] = {
afterExecute: originUpdates[k].afterExecute,
};
}
}
for (const k in this.children) {
this.children[k].clean(preserveAfterExecute);
}
if (!preserveAfterExecute) {
this.dirty = undefined;
}
else {
// preserveAfterExecute一定发生在execute后面的cache会publish
this.publish();
this.children[k].clean();
}
this.dirty = undefined;
this.publish();
}
}
getChildOperation(child) {
@ -1189,23 +1182,14 @@ class SingleNode extends Node {
this.publish();
}
}
clean(preserveAfterExecute) {
clean() {
if (this.dirty) {
if (preserveAfterExecute && this.operation?.afterExecute) {
this.operation.operation = undefined;
}
else {
this.operation = undefined;
}
this.operation = undefined;
for (const child in this.children) {
this.children[child].clean(preserveAfterExecute);
}
if (!preserveAfterExecute) {
this.dirty = undefined;
}
else {
this.publish();
this.children[child].clean();
}
this.dirty = undefined;
this.publish();
}
}
getFilter() {
@ -1464,16 +1448,12 @@ class VirtualNode extends Feature_1.Feature {
}
this.dirty = false;
}
clean(preserveAfterExecute) {
clean() {
for (const ele in this.children) {
this.children[ele].clean(preserveAfterExecute);
}
if (!preserveAfterExecute) {
this.dirty = false;
}
else {
this.publish();
this.children[ele].clean();
}
this.dirty = false;
this.publish();
}
checkIfClean() {
for (const k in this.children) {
@ -1894,13 +1874,13 @@ class RunningTree extends Feature_1.Feature {
.filter((ele) => !!ele)
.map((ele) => ele.operation), undefined, () => {
// 清空缓存
node.clean(true);
node.clean();
node.setExecuting(false);
});
await node.doAfterTrigger();
return result;
}
node.clean(true);
node.clean();
node.setExecuting(false);
await node.doAfterTrigger();
return { message: 'No Operation' };

View File

@ -971,30 +971,23 @@ class ListNode<
this.refresh(currentPage, undefined, append);
}
clean(preserveAfterExecute?: true) {
clean() {
if (this.dirty) {
const originUpdates = this.updates;
this.updates = {};
if (preserveAfterExecute) {
for (const k in originUpdates) {
if (originUpdates[k].afterExecute) {
this.updates[k] = {
afterExecute: originUpdates[k].afterExecute,
};
}
for (const k in originUpdates) {
if (originUpdates[k].afterExecute) {
this.updates[k] = {
afterExecute: originUpdates[k].afterExecute,
};
}
}
for (const k in this.children) {
this.children[k].clean(preserveAfterExecute);
this.children[k].clean();
}
if (!preserveAfterExecute) {
this.dirty = undefined;
}
else {
// preserveAfterExecute一定发生在execute后面的cache会publish
this.publish();
}
this.dirty = undefined;
this.publish();
}
}
@ -1451,24 +1444,15 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
}
}
clean(preserveAfterExecute?: true) {
clean() {
if (this.dirty) {
if (preserveAfterExecute && this.operation?.afterExecute) {
this.operation.operation = undefined;
}
else {
this.operation = undefined;
}
this.operation = undefined;
for (const child in this.children) {
this.children[child]!.clean(preserveAfterExecute);
this.children[child]!.clean();
}
if (!preserveAfterExecute) {
this.dirty = undefined;
}
else {
this.publish();
}
this.dirty = undefined;
this.publish();
}
}
@ -1752,16 +1736,12 @@ class VirtualNode<
}
this.dirty = false;
}
clean(preserveAfterExecute?: true) {
clean() {
for (const ele in this.children) {
this.children[ele].clean(preserveAfterExecute);
}
if (!preserveAfterExecute) {
this.dirty = false;
}
else {
this.publish();
this.children[ele].clean();
}
this.dirty = false;
this.publish();
}
checkIfClean() {
for (const k in this.children) {
@ -2376,7 +2356,7 @@ export class RunningTree<
undefined,
() => {
// 清空缓存
node.clean(true);
node.clean();
node.setExecuting(false);
}
);
@ -2385,7 +2365,7 @@ export class RunningTree<
return result;
}
node.clean(true);
node.clean();
node.setExecuting(false);
await node.doAfterTrigger();