增加了组件上的select接口,可以在应用runningTree上的更新后再去取数

This commit is contained in:
Xu Chang 2024-12-17 17:01:05 +08:00
parent f03f1d5e8d
commit b0e0834fb0
16 changed files with 90 additions and 5 deletions

1
es/page.common.d.ts vendored
View File

@ -17,3 +17,4 @@ opers?: Array<{
}>): Promise<void>;
export declare function destroyNode<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(this: ComponentFullThisType<ED, T>, isPage: boolean, path: string): void;
export declare function getFreshValue<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(this: ComponentFullThisType<ED, T>, path: string): Partial<ED[keyof ED]["Schema"]> | Partial<ED[keyof ED]["Schema"]>[] | undefined;
export declare function select<ED extends EntityDict & BaseEntityDict, T extends keyof ED, T2 extends keyof ED>(this: ComponentFullThisType<ED, T>, entity: T2, selection: ED[T2]['Selection']): Partial<ED[T2]["Schema"]>[];

View File

@ -604,3 +604,19 @@ export function getFreshValue(path) {
assert(false);
}
}
export function select(entity, selection) {
const rollback = this.features.runningTree.begin();
try {
const path = this.state.oakFullpath;
this.features.runningTree.redoBranchModis(`${path}.any:next`);
this.features.runningTree.redoBranchOperations(path);
const result = this.features.cache.get(entity, selection);
rollback();
return result;
}
catch (err) {
rollback();
console.error(err);
assert(false);
}
}

View File

@ -1,7 +1,7 @@
/// <reference path="../node_modules/@types/wechat-miniprogram/index.d.ts" />
import { assert } from 'oak-domain/lib/utils/assert';
import { OakException } from 'oak-domain/lib/types';
import { onPathSet, reRender, refresh, loadMore, execute, destroyNode, getFreshValue, } from './page.common';
import { onPathSet, reRender, refresh, loadMore, execute, destroyNode, getFreshValue, select } from './page.common';
import { cloneDeep, pull } from 'oak-domain/lib/utils/lodash';
const OakProperties = {
oakId: '',
@ -182,6 +182,9 @@ const oakBehavior = Behavior({
: this.state.oakFullpath;
return getFreshValue.call(this, path2);
},
select(entity, selection) {
return select.call(this, entity, selection);
},
checkOperation(entity, { action, data, filter }, checkerTypes) {
return this.features.cache.checkOperation(entity, {
action,

3
es/page.react.d.ts vendored
View File

@ -75,7 +75,8 @@ export declare function createComponent<IsList extends boolean, ED extends Entit
}[] | undefined): Promise<void>;
isDirty(path?: string | undefined): boolean;
getFreshValue(path?: string | undefined): Partial<import("oak-domain/lib/types").GeneralEntityShape> | Partial<import("oak-domain/lib/types").GeneralEntityShape>[] | undefined;
checkOperation<T2_2 extends keyof ED>(entity: T2_2, operation: Omit<ED[T2_2]["Operation"], "id">, checkerTypes?: CheckerType[] | undefined): boolean | { [A in ED[T2_2]["Action"]]: boolean | import("oak-domain/lib/types").OakUserException<ED>; }[ED[T2_2]["Action"]];
select<T2_2 extends keyof ED>(entity: T2_2, selection: ED[T2_2]["Selection"]): Partial<import("oak-domain/lib/types").GeneralEntityShape>[];
checkOperation<T2_3 extends keyof ED>(entity: T2_3, operation: Omit<ED[T2_3]["Operation"], "id">, checkerTypes?: CheckerType[] | undefined): boolean | { [A in ED[T2_3]["Action"]]: boolean | import("oak-domain/lib/types").OakUserException<ED>; }[ED[T2_3]["Action"]];
tryExecute(path?: string | undefined, action?: string | undefined): boolean | { [A_1 in ED[keyof ED]["Action"]]: boolean | import("oak-domain/lib/types").OakUserException<ED>; }[ED[keyof ED]["Action"]];
getOperations<T_7 extends keyof ED>(path?: string | undefined): {
entity: keyof ED;

View File

@ -2,7 +2,7 @@ import { assert } from 'oak-domain/lib/utils/assert';
import React from 'react';
import { get, pull } from 'oak-domain/lib/utils/lodash';
import { OakException } from 'oak-domain/lib/types';
import { onPathSet, reRender, refresh, loadMore, execute, destroyNode, getFreshValue, } from './page.common';
import { onPathSet, reRender, refresh, loadMore, execute, destroyNode, getFreshValue, select, } from './page.common';
class OakComponentBase extends React.PureComponent {
oakFullpath = '';
featuresSubscribed = [];
@ -176,6 +176,9 @@ class OakComponentBase extends React.PureComponent {
: this.state.oakFullpath;
return getFreshValue.call(this, path2);
}
select(entity, selection) {
return select.call(this, entity, selection);
}
checkOperation(entity, operation, checkerTypes) {
return this.features.cache.checkOperation(entity, operation, checkerTypes);
}

1
es/types/Page.d.ts vendored
View File

@ -245,6 +245,7 @@ export type OakCommonComponentMethods<ED extends EntityDict & BaseEntityDict, T
consumeMessage: () => MessageProps | undefined;
reRender: (extra?: Record<string, any>) => void;
getFreshValue: (path?: string) => Partial<ED[keyof ED]['Schema']>[] | Partial<ED[keyof ED]['Schema']> | undefined;
select: <T2 extends keyof ED>(entity: T2, selection: ED[T2]['Selection']) => Partial<ED[T2]['Schema']>[];
navigateTo: <T2 extends keyof ED>(options: {
url: string;
} & OakNavigateToParameters<ED, T2>, state?: Record<string, any>, disableNamespace?: boolean) => Promise<void>;

View File

@ -17,3 +17,4 @@ opers?: Array<{
}>): Promise<void>;
export declare function destroyNode<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(this: ComponentFullThisType<ED, T>, isPage: boolean, path: string): void;
export declare function getFreshValue<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(this: ComponentFullThisType<ED, T>, path: string): Partial<ED[keyof ED]["Schema"]> | Partial<ED[keyof ED]["Schema"]>[] | undefined;
export declare function select<ED extends EntityDict & BaseEntityDict, T extends keyof ED, T2 extends keyof ED>(this: ComponentFullThisType<ED, T>, entity: T2, selection: ED[T2]['Selection']): Partial<ED[T2]["Schema"]>[];

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFreshValue = exports.destroyNode = exports.execute = exports.loadMore = exports.refresh = exports.reRender = exports.onPathSet = void 0;
exports.select = exports.getFreshValue = exports.destroyNode = exports.execute = exports.loadMore = exports.refresh = exports.reRender = exports.onPathSet = void 0;
const assert_1 = require("oak-domain/lib/utils/assert");
const lodash_1 = require("oak-domain/lib/utils/lodash");
const relation_1 = require("oak-domain/lib/store/relation");
@ -614,3 +614,20 @@ function getFreshValue(path) {
}
}
exports.getFreshValue = getFreshValue;
function select(entity, selection) {
const rollback = this.features.runningTree.begin();
try {
const path = this.state.oakFullpath;
this.features.runningTree.redoBranchModis(`${path}.any:next`);
this.features.runningTree.redoBranchOperations(path);
const result = this.features.cache.get(entity, selection);
rollback();
return result;
}
catch (err) {
rollback();
console.error(err);
(0, assert_1.assert)(false);
}
}
exports.select = select;

View File

@ -185,6 +185,9 @@ const oakBehavior = Behavior({
: this.state.oakFullpath;
return page_common_1.getFreshValue.call(this, path2);
},
select(entity, selection) {
return page_common_1.select.call(this, entity, selection);
},
checkOperation(entity, { action, data, filter }, checkerTypes) {
return this.features.cache.checkOperation(entity, {
action,

3
lib/page.react.d.ts vendored
View File

@ -75,7 +75,8 @@ export declare function createComponent<IsList extends boolean, ED extends Entit
}[] | undefined): Promise<void>;
isDirty(path?: string | undefined): boolean;
getFreshValue(path?: string | undefined): Partial<import("oak-domain/lib/types").GeneralEntityShape> | Partial<import("oak-domain/lib/types").GeneralEntityShape>[] | undefined;
checkOperation<T2_2 extends keyof ED>(entity: T2_2, operation: Omit<ED[T2_2]["Operation"], "id">, checkerTypes?: CheckerType[] | undefined): boolean | { [A in ED[T2_2]["Action"]]: boolean | import("oak-domain/lib/types").OakUserException<ED>; }[ED[T2_2]["Action"]];
select<T2_2 extends keyof ED>(entity: T2_2, selection: ED[T2_2]["Selection"]): Partial<import("oak-domain/lib/types").GeneralEntityShape>[];
checkOperation<T2_3 extends keyof ED>(entity: T2_3, operation: Omit<ED[T2_3]["Operation"], "id">, checkerTypes?: CheckerType[] | undefined): boolean | { [A in ED[T2_3]["Action"]]: boolean | import("oak-domain/lib/types").OakUserException<ED>; }[ED[T2_3]["Action"]];
tryExecute(path?: string | undefined, action?: string | undefined): boolean | { [A_1 in ED[keyof ED]["Action"]]: boolean | import("oak-domain/lib/types").OakUserException<ED>; }[ED[keyof ED]["Action"]];
getOperations<T_7 extends keyof ED>(path?: string | undefined): {
entity: keyof ED;

View File

@ -181,6 +181,9 @@ class OakComponentBase extends react_1.default.PureComponent {
: this.state.oakFullpath;
return page_common_1.getFreshValue.call(this, path2);
}
select(entity, selection) {
return page_common_1.select.call(this, entity, selection);
}
checkOperation(entity, operation, checkerTypes) {
return this.features.cache.checkOperation(entity, operation, checkerTypes);
}

1
lib/types/Page.d.ts vendored
View File

@ -245,6 +245,7 @@ export type OakCommonComponentMethods<ED extends EntityDict & BaseEntityDict, T
consumeMessage: () => MessageProps | undefined;
reRender: (extra?: Record<string, any>) => void;
getFreshValue: (path?: string) => Partial<ED[keyof ED]['Schema']>[] | Partial<ED[keyof ED]['Schema']> | undefined;
select: <T2 extends keyof ED>(entity: T2, selection: ED[T2]['Selection']) => Partial<ED[T2]['Schema']>[];
navigateTo: <T2 extends keyof ED>(options: {
url: string;
} & OakNavigateToParameters<ED, T2>, state?: Record<string, any>, disableNamespace?: boolean) => Promise<void>;

View File

@ -747,4 +747,25 @@ export function getFreshValue<
console.error(err);
assert(false);
}
}
export function select<
ED extends EntityDict & BaseEntityDict,
T extends keyof ED,
T2 extends keyof ED
>(this: ComponentFullThisType<ED, T>, entity: T2, selection: ED[T2]['Selection']) {
const rollback = this.features.runningTree.begin();
try {
const path = this.state.oakFullpath;
this.features.runningTree.redoBranchModis(`${path}.any:next`);
this.features.runningTree.redoBranchOperations(path);
const result = this.features.cache.get(entity, selection);
rollback();
return result;
}
catch(err) {
rollback();
console.error(err);
assert(false);
}
}

View File

@ -17,6 +17,7 @@ import {
onPathSet, reRender, refresh,
loadMore, execute,
destroyNode, getFreshValue,
select
} from './page.common';
import { MessageProps } from './types/Message';
import { NotificationProps } from './types/Notification';
@ -309,6 +310,11 @@ const oakBehavior = Behavior<
return getFreshValue.call(this as any, path2);
},
select<T2 extends keyof EDD>(entity: T2, selection: EDD[T2]['Selection']) {
return select.call(this as any, entity as any, selection);
},
checkOperation(entity, { action, data, filter }, checkerTypes) {
return this.features.cache.checkOperation(
entity,

View File

@ -22,6 +22,7 @@ import {
onPathSet, reRender, refresh,
loadMore, execute,
destroyNode, getFreshValue,
select,
} from './page.common';
import { MessageProps } from './types/Message';
import { NotificationProps } from './types/Notification';
@ -346,6 +347,10 @@ abstract class OakComponentBase<
return getFreshValue.call(this as any, path2);
}
select<T2 extends keyof ED>(entity: T2, selection: ED[T2]['Selection']) {
return select.call(this as any, entity as any, selection);
}
checkOperation<T2 extends keyof ED>(
entity: T2,
operation: Omit<ED[T2]['Operation'], 'id'>,

View File

@ -447,6 +447,8 @@ export type OakCommonComponentMethods<
| Partial<ED[keyof ED]['Schema']>[]
| Partial<ED[keyof ED]['Schema']>
| undefined;
/*这个方法是将当前node上的modi和operation应用后再去cache中获取对应的数据 */
select: <T2 extends keyof ED>(entity: T2, selection: ED[T2]['Selection']) => Partial<ED[T2]['Schema']>[];
navigateTo: <T2 extends keyof ED>(
options: { url: string } & OakNavigateToParameters<ED, T2>,
state?: Record<string, any>,