runningTree在refresh时publish应当扩散到自身所有的子结点

This commit is contained in:
Xu Chang 2023-10-18 15:24:37 +08:00
parent b6f87170f6
commit 204ca25952
5 changed files with 96 additions and 27 deletions

View File

@ -129,6 +129,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
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;
publishRecursively(): void;
}
declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends CommonAspectDict<ED, Cxt>> extends Node<ED, T, Cxt, FrontCxt, AD> {
private id?;
@ -175,6 +176,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
* @returns
*/
getParentFilter<T2 extends keyof ED>(childNode: Node<ED, keyof ED, Cxt, FrontCxt, AD>, ignoreNewParent?: boolean): ED[T2]['Selection']['filter'] | undefined;
publishRecursively(): void;
}
declare class VirtualNode<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends CommonAspectDict<ED, Cxt>> extends Feature {
private dirty;
@ -203,6 +205,7 @@ declare class VirtualNode<ED extends EntityDict & BaseEntityDict, Cxt extends As
doAfterTrigger(): Promise<void>;
clean(): void;
checkIfClean(): void;
publishRecursively(): void;
}
export type CreateNodeOptions<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
path: string;

View File

@ -718,7 +718,7 @@ class ListNode extends Node {
if (append) {
this.loadingMore = true;
}
this.publish();
this.publishRecursively();
await this.cache.refresh(entity, {
data: projection,
filter,
@ -750,20 +750,20 @@ class ListNode extends Node {
this.aggr = aggr;
}
});
this.publish();
this.publishRecursively();
}
catch (err) {
this.setLoading(false);
if (append) {
this.loadingMore = false;
}
this.publish();
this.publishRecursively();
throw err;
}
}
else {
// 不刷新也publish一下触发页面reRender不然有可能导致页面不进入formData
this.publish();
this.publishRecursively();
}
}
async loadMore() {
@ -814,6 +814,12 @@ class ListNode extends Node {
const filters = this.constructFilters(undefined, true, true);
return combineFilters(this.entity, this.schema, filters || []);
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
class SingleNode extends Node {
id;
@ -1170,7 +1176,7 @@ class SingleNode extends Node {
const filter = this.getFilter();
if (projection && filter) {
this.setLoading(true);
this.publish();
this.publishRecursively();
try {
const { data: [value] } = await this.cache.refresh(this.entity, {
data: projection,
@ -1198,17 +1204,17 @@ class SingleNode extends Node {
this.setLoading(false);
//this.clean();
});
this.publish();
this.publishRecursively();
}
catch (err) {
this.setLoading(false);
this.publish();
this.publishRecursively();
throw err;
}
}
else {
// 不刷新也publish一下触发页面reRender不然有可能导致页面不进入formData
this.publish();
this.publishRecursively();
}
}
clean() {
@ -1355,6 +1361,12 @@ class SingleNode extends Node {
}
return;
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
class VirtualNode extends Feature {
dirty;
@ -1415,13 +1427,15 @@ class VirtualNode extends Feature {
}
async refresh() {
this.loading = true;
this.publishRecursively();
try {
await Promise.all(Object.keys(this.children).map(ele => this.children[ele].refresh()));
this.loading = false;
this.publish();
this.publishRecursively();
}
catch (err) {
this.loading = false;
this.publishRecursively();
throw err;
}
}
@ -1492,6 +1506,12 @@ class VirtualNode extends Feature {
}
this.dirty = false;
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
function analyzePath(path) {
const idx = path.lastIndexOf('.');

View File

@ -129,6 +129,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
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;
publishRecursively(): void;
}
declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends CommonAspectDict<ED, Cxt>> extends Node<ED, T, Cxt, FrontCxt, AD> {
private id?;
@ -175,6 +176,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
* @returns
*/
getParentFilter<T2 extends keyof ED>(childNode: Node<ED, keyof ED, Cxt, FrontCxt, AD>, ignoreNewParent?: boolean): ED[T2]['Selection']['filter'] | undefined;
publishRecursively(): void;
}
declare class VirtualNode<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends CommonAspectDict<ED, Cxt>> extends Feature {
private dirty;
@ -203,6 +205,7 @@ declare class VirtualNode<ED extends EntityDict & BaseEntityDict, Cxt extends As
doAfterTrigger(): Promise<void>;
clean(): void;
checkIfClean(): void;
publishRecursively(): void;
}
export type CreateNodeOptions<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
path: string;

View File

@ -721,7 +721,7 @@ class ListNode extends Node {
if (append) {
this.loadingMore = true;
}
this.publish();
this.publishRecursively();
await this.cache.refresh(entity, {
data: projection,
filter,
@ -753,20 +753,20 @@ class ListNode extends Node {
this.aggr = aggr;
}
});
this.publish();
this.publishRecursively();
}
catch (err) {
this.setLoading(false);
if (append) {
this.loadingMore = false;
}
this.publish();
this.publishRecursively();
throw err;
}
}
else {
// 不刷新也publish一下触发页面reRender不然有可能导致页面不进入formData
this.publish();
this.publishRecursively();
}
}
async loadMore() {
@ -817,6 +817,12 @@ class ListNode extends Node {
const filters = this.constructFilters(undefined, true, true);
return (0, filter_1.combineFilters)(this.entity, this.schema, filters || []);
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
class SingleNode extends Node {
id;
@ -1173,7 +1179,7 @@ class SingleNode extends Node {
const filter = this.getFilter();
if (projection && filter) {
this.setLoading(true);
this.publish();
this.publishRecursively();
try {
const { data: [value] } = await this.cache.refresh(this.entity, {
data: projection,
@ -1201,17 +1207,17 @@ class SingleNode extends Node {
this.setLoading(false);
//this.clean();
});
this.publish();
this.publishRecursively();
}
catch (err) {
this.setLoading(false);
this.publish();
this.publishRecursively();
throw err;
}
}
else {
// 不刷新也publish一下触发页面reRender不然有可能导致页面不进入formData
this.publish();
this.publishRecursively();
}
}
clean() {
@ -1358,6 +1364,12 @@ class SingleNode extends Node {
}
return;
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
class VirtualNode extends Feature_1.Feature {
dirty;
@ -1418,13 +1430,15 @@ class VirtualNode extends Feature_1.Feature {
}
async refresh() {
this.loading = true;
this.publishRecursively();
try {
await Promise.all(Object.keys(this.children).map(ele => this.children[ele].refresh()));
this.loading = false;
this.publish();
this.publishRecursively();
}
catch (err) {
this.loading = false;
this.publishRecursively();
throw err;
}
}
@ -1495,6 +1509,12 @@ class VirtualNode extends Feature_1.Feature {
}
this.dirty = false;
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
function analyzePath(path) {
const idx = path.lastIndexOf('.');

View File

@ -921,7 +921,7 @@ class ListNode<
if (append) {
this.loadingMore = true;
}
this.publish();
this.publishRecursively();
await this.cache.refresh(
entity,
{
@ -957,19 +957,19 @@ class ListNode<
}
}
);
this.publish();
this.publishRecursively();
} catch (err) {
this.setLoading(false);
if (append) {
this.loadingMore = false;
}
this.publish();
this.publishRecursively();
throw err;
}
}
else {
// 不刷新也publish一下触发页面reRender不然有可能导致页面不进入formData
this.publish();
this.publishRecursively();
}
}
@ -1026,6 +1026,13 @@ class ListNode<
const filters = this.constructFilters(undefined, true, true);
return combineFilters(this.entity, this.schema, filters || []);
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
class SingleNode<ED extends EntityDict & BaseEntityDict,
@ -1434,7 +1441,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
const filter = this.getFilter();
if (projection && filter) {
this.setLoading(true);
this.publish();
this.publishRecursively();
try {
const { data: [value] } = await this.cache.refresh(this.entity, {
data: projection,
@ -1462,17 +1469,17 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
this.setLoading(false);
//this.clean();
});
this.publish();
this.publishRecursively();
}
catch (err) {
this.setLoading(false);
this.publish();
this.publishRecursively();
throw err;
}
}
else {
// 不刷新也publish一下触发页面reRender不然有可能导致页面不进入formData
this.publish();
this.publishRecursively();
}
}
@ -1628,6 +1635,13 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
}
return;
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
class VirtualNode<
@ -1697,6 +1711,7 @@ class VirtualNode<
}
async refresh() {
this.loading = true;
this.publishRecursively();
try {
await Promise.all(
Object.keys(this.children).map(
@ -1704,10 +1719,11 @@ class VirtualNode<
)
);
this.loading = false;
this.publish();
this.publishRecursively();
}
catch (err) {
this.loading = false;
this.publishRecursively();
throw err;
}
}
@ -1783,6 +1799,13 @@ class VirtualNode<
}
this.dirty = false;
}
publishRecursively() {
this.publish();
for (const child in this.children) {
this.children[child].publishRecursively();
}
}
}
export type CreateNodeOptions<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {