为clean增加了dontPublish参数

This commit is contained in:
Xu Chang 2024-06-14 19:34:13 +08:00
parent 896711588f
commit 2c80c5b077
20 changed files with 73 additions and 82 deletions

View File

@ -117,7 +117,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
getProjection(): ED[T]["Selection"]["data"] | undefined;
private constructFilters;
constructSelection(withParent?: true, ignoreNewParent?: boolean, ignoreUnapplied?: true): {
data: ED[T]["Selection"]["data"];
data: ED[T]["Selection"]["data"] | undefined;
filter: ED[T]["Selection"]["filter"] | undefined;
sorter: ED[T]["Selection"]["sorter"];
total: number | undefined;
@ -131,7 +131,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
refresh(pageNumber?: number, append?: boolean): Promise<void>;
loadMore(): Promise<void>;
setCurrentPage(currentPage: number): void;
clean(): void;
clean(dontPublish?: true): void;
getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined;
}
declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof ED> extends Node<ED, T> {
@ -179,7 +179,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
private passRsToChild;
saveRefreshResult(data: Record<string, any>): void;
refresh(): Promise<void>;
clean(): void;
clean(dontPublish?: true): void;
private getFilter;
getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined;
/**
@ -217,7 +217,7 @@ declare class VirtualNode<ED extends EntityDict & BaseEntityDict> extends Featur
setExecuting(executing: boolean): void;
isExecuting(): boolean;
isLoading(): boolean;
clean(): void;
clean(dontPublish?: true): void;
checkIfClean(): void;
}
export type CreateNodeOptions<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {

View File

@ -726,7 +726,7 @@ class ListNode extends Node {
constructSelection(withParent, ignoreNewParent, ignoreUnapplied) {
const { sorters, getTotal } = this;
const data = this.getProjection();
// (0, assert_1.assert)(data, '取数据时找不到projection信息');
// assert(data, '取数据时找不到projection信息');
const sorterArr = sorters.filter(ele => !ignoreUnapplied || ele.applied).map((ele) => {
const { sorter } = ele;
if (typeof sorter === 'function') {
@ -841,15 +841,17 @@ class ListNode extends Node {
setCurrentPage(currentPage) {
this.refresh(currentPage, false);
}
clean() {
clean(dontPublish) {
if (this.dirty) {
const originUpdates = this.updates;
this.updates = {};
for (const k in this.children) {
this.children[k].clean();
this.children[k].clean(dontPublish);
}
this.dirty = undefined;
this.publish();
if (!dontPublish) {
this.publish();
}
}
}
// 查看这个list上所有数据必须遵守的限制
@ -1117,14 +1119,14 @@ class SingleNode extends Node {
if (attr === 'entityId') {
(0, assert_1.assert)(data.entity, '设置entityId时请将entity也传入');
if (this.children[data.entity]) {
this.children[data.entity].clean();
this.children[data.entity].clean(true);
this.passRsToChild(data.entity);
}
}
else if (this.schema[this.entity].attributes[attr]?.type === 'ref') {
const refKey = attr.slice(0, attr.length - 2);
if (this.children[refKey]) {
this.children[refKey].clean();
this.children[refKey].clean(true);
this.passRsToChild(refKey);
}
}
@ -1331,14 +1333,16 @@ class SingleNode extends Node {
this.publish();
}
}
clean() {
clean(dontPublish) {
if (this.dirty) {
this.operation = undefined;
for (const child in this.children) {
this.children[child].clean();
this.children[child].clean(dontPublish);
}
this.dirty = undefined;
this.publish();
if (!dontPublish) {
this.publish();
}
}
}
getFilter() {
@ -1550,12 +1554,14 @@ class VirtualNode extends Feature_1.Feature {
isLoading() {
return this.loading;
}
clean() {
clean(dontPublish) {
for (const ele in this.children) {
this.children[ele].clean();
this.children[ele].clean(dontPublish);
}
this.dirty = false;
this.publish();
if (!dontPublish) {
this.publish();
}
}
checkIfClean() {
for (const k in this.children) {
@ -2044,7 +2050,7 @@ class RunningTree extends Feature_1.Feature {
.filter((ele) => !!ele)
.map((ele) => ele.operation), undefined, () => {
// 清空缓存
node.clean();
node.clean(true);
if (node instanceof SingleNode) {
(0, assert_1.assert)(operations.length === 1);
// 这逻辑有点扯,页面自己决定后续逻辑 by Xc 20231108
@ -2058,7 +2064,7 @@ class RunningTree extends Feature_1.Feature {
});
return result;
}
node.clean();
node.clean(true);
node.setExecuting(false);
return { message: 'No Operation' };
}

View File

@ -163,11 +163,11 @@ const oakBehavior = Behavior({
switchTab(option, state) {
return this.features.navigator.switchTab(option, state);
},
clean(path) {
clean(dontPublish, path) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
return this.features.runningTree.clean(path2);
return this.features.runningTree.clean(path2, dontPublish);
},
isDirty(path) {
return this.features.runningTree.isDirty(path || this.state.oakFullpath);

View File

@ -5,4 +5,4 @@ import { Feature } from './types/Feature';
import { DataOption, OakComponentOption } from './types/Page';
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
export declare function createComponent<IsList extends boolean, ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, TData extends Record<string, any> = {}, TProperty extends DataOption = {}, TMethod extends Record<string, Function> = {}>(option: OakComponentOption<IsList, ED, T, Cxt, FrontCxt, AD, FD, FormedData, TData, TProperty, TMethod>, features: BasicFeatures<ED> & FD): (props: any) => import("react/jsx-runtime").JSX.Element;
export declare function createComponent<IsList extends boolean, ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, TData extends Record<string, any> = {}, TProperty extends DataOption = {}, TMethod extends Record<string, Function> = {}>(option: OakComponentOption<IsList, ED, T, Cxt, FrontCxt, AD, FD, FormedData, TData, TProperty, TMethod>, features: BasicFeatures<ED> & FD): (props: any) => any;

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

@ -1,10 +1,9 @@
import React from 'react';
import { Aspect, CheckerType, EntityDict, OpRecord } from 'oak-domain/lib/types';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { BasicFeatures } from './features';
import { NamedFilterItem, NamedSorterItem } from './types/NamedCondition';
import { Feature } from './types/Feature';
import { DataOption, ComponentData, ComponentProps, OakComponentOption, OakNavigateToParameters } from './types/Page';
import { DataOption, ComponentProps, OakComponentOption, OakNavigateToParameters } from './types/Page';
import { MessageProps } from './types/Message';
import { NotificationProps } from './types/Notification';
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
@ -64,7 +63,7 @@ export declare function createComponent<IsList extends boolean, ED extends Entit
create<T_4 extends keyof ED>(data: Omit<ED[T_4]["CreateSingle"]["data"], "id">, path?: string | undefined): void;
remove(path?: string | undefined): void;
isCreation(path?: string | undefined): boolean;
clean(path?: string | undefined): void;
clean(dontPublish?: true | undefined, path?: string | undefined): void;
t(key: string, params?: object | undefined): string;
execute(action?: ED[T]["Action"] | undefined, messageProps?: boolean | MessageProps | undefined, path?: string | undefined, opers?: {
entity: T;
@ -101,23 +100,5 @@ export declare function createComponent<IsList extends boolean, ED extends Entit
setCurrentPage(currentPage: number, path?: string | undefined): void;
subDataEvents(events: string[], moduleName: string, callback: (event: string, opRecords: OpRecord<ED>[]) => void): Promise<void>;
unsubDataEvents(events: string[], moduleName: string): Promise<void>;
context: unknown;
setState<K extends keyof TData | keyof FormedData | keyof import("./types/Page").OakComponentData<ED, T>>(state: ComponentData<ED, T, FormedData, TData> | ((prevState: Readonly<ComponentData<ED, T, FormedData, TData>>, props: Readonly<ComponentProps<ED, T, TProperty>>) => ComponentData<ED, T, FormedData, TData> | Pick<ComponentData<ED, T, FormedData, TData>, K> | null) | Pick<ComponentData<ED, T, FormedData, TData>, K> | null, callback?: (() => void) | undefined): void;
forceUpdate(callback?: (() => void) | undefined): void;
readonly props: Readonly<ComponentProps<ED, T, TProperty>>;
state: Readonly<ComponentData<ED, T, FormedData, TData>>;
refs: {
[key: string]: React.ReactInstance;
};
shouldComponentUpdate?(nextProps: Readonly<ComponentProps<ED, T, TProperty>>, nextState: Readonly<ComponentData<ED, T, FormedData, TData>>, nextContext: any): boolean;
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly<ComponentProps<ED, T, TProperty>>, prevState: Readonly<ComponentData<ED, T, FormedData, TData>>): any;
componentWillMount?(): void;
UNSAFE_componentWillMount?(): void;
componentWillReceiveProps?(nextProps: Readonly<ComponentProps<ED, T, TProperty>>, nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<ComponentProps<ED, T, TProperty>>, nextContext: any): void;
componentWillUpdate?(nextProps: Readonly<ComponentProps<ED, T, TProperty>>, nextState: Readonly<ComponentData<ED, T, FormedData, TData>>, nextContext: any): void;
UNSAFE_componentWillUpdate?(nextProps: Readonly<ComponentProps<ED, T, TProperty>>, nextState: Readonly<ComponentData<ED, T, FormedData, TData>>, nextContext: any): void;
};
contextType?: React.Context<any> | undefined;
};

View File

@ -157,11 +157,11 @@ class OakComponentBase extends react_1.default.PureComponent {
throw err;
}
}
clean(path) {
clean(dontPublish, path) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.clean(path2);
this.features.runningTree.clean(path2, dontPublish);
}
t(key, params) {
return this.features.locales.t(key, params);
@ -456,8 +456,8 @@ function createComponent(option, features) {
redirectTo: (options, state, disableNamespace) => {
return this.redirectTo(options, state, disableNamespace);
},
clean: (path) => {
return this.clean(path);
clean: (dontPublish, path) => {
return this.clean(dontPublish, path);
},
checkOperation: (entity, operation, checkerTypes) => {
return this.checkOperation(entity, operation, checkerTypes);

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

@ -1,4 +1,3 @@
import React from 'react';
import { Aspect, EntityDict } from 'oak-domain/lib/types';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { BasicFeatures } from './features';
@ -6,4 +5,4 @@ import { Feature } from './types/Feature';
import { DataOption, OakComponentOption } from './types/Page';
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
export declare function createComponent<IsList extends boolean, ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, TData extends Record<string, any> = {}, TProperty extends DataOption = {}, TMethod extends Record<string, Function> = {}>(option: OakComponentOption<IsList, ED, T, Cxt, FrontCxt, AD, FD, FormedData, TData, TProperty, TMethod>, features: BasicFeatures<ED> & FD): React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
export declare function createComponent<IsList extends boolean, ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, TData extends Record<string, any> = {}, TProperty extends DataOption = {}, TMethod extends Record<string, Function> = {}>(option: OakComponentOption<IsList, ED, T, Cxt, FrontCxt, AD, FD, FormedData, TData, TProperty, TMethod>, features: BasicFeatures<ED> & FD): any;

View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.createComponent = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const withRouter_1 = tslib_1.__importDefault(require("./platforms/web/router/withRouter"));
const PullToRefresh_1 = tslib_1.__importDefault(require("./platforms/web/PullToRefresh"));
const page_react_1 = require("./page.react");

View File

@ -4,6 +4,6 @@ type Props = {
features: Record<string, Feature>;
children: React.ReactNode;
};
declare const FeaturesProvider: (props: Props) => import("react/jsx-runtime").JSX.Element;
declare const useFeatures: <FD2 extends Record<string, Feature>>() => FD2;
declare const FeaturesProvider: (props: Props) => any;
declare const useFeatures: <FD2 extends Record<string, Feature>>() => any;
export { FeaturesProvider, useFeatures };

View File

@ -1,7 +1,6 @@
import React from 'react';
type OakComponentProperties = {
path?: string;
properties?: Record<string, any>;
};
declare const withRouter: (Component: React.ComponentType<any>, { path, properties }: OakComponentProperties) => (props: any) => import("react/jsx-runtime").JSX.Element;
declare const withRouter: (Component: React.ComponentType<any>, { path, properties }: OakComponentProperties) => (props: any) => any;
export default withRouter;

View File

@ -1,6 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const assert_1 = require("oak-domain/lib/utils/assert");
function getParams(params, properties) {
const props = getProps(params, properties);

View File

@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const rmc_pull_to_refresh_1 = tslib_1.__importDefault(require("rmc-pull-to-refresh"));
require("./PullToRefresh.css");
const OakPullToRefresh = (props) => {

View File

@ -4,5 +4,5 @@ declare const FeaturesProvider: React.FC<{
features: Record<string, Feature>;
children: React.ReactNode;
}>;
declare const useFeatures: <FD2 extends Record<string, Feature>>() => FD2;
declare const useFeatures: <FD2 extends Record<string, Feature>>() => any;
export { FeaturesProvider, useFeatures };

View File

@ -1,4 +1,3 @@
import React from 'react';
export type Width = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
export type Keys = Width[];
export type Values = {
@ -16,6 +15,4 @@ export type Breakpoints = {
export declare const keys: Keys;
export declare const values: Values;
export declare const defaultBreakpoints: Breakpoints;
export declare const ResponsiveContext: React.Context<{
breakpoints?: Breakpoints | undefined;
}>;
export declare const ResponsiveContext: any;

View File

@ -1,7 +1,6 @@
import React from 'react';
type OakComponentProperties = {
path?: string;
properties?: Record<string, any>;
};
declare const withRouter: (Component: React.ComponentType<any>, { path, properties }: OakComponentProperties) => React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
declare const withRouter: (Component: React.ComponentType<any>, { path, properties }: OakComponentProperties) => any;
export default withRouter;

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

@ -156,7 +156,7 @@ export type OakCommonComponentMethods<ED extends EntityDict & BaseEntityDict, T
navigateBack: (delta?: number) => Promise<void>;
redirectTo: <T2 extends keyof ED>(options: Parameters<typeof wx.redirectTo>[0] & OakNavigateToParameters<ED, T2>, state?: Record<string, any>, disableNamespace?: boolean) => Promise<void>;
switchTab: <T2 extends keyof ED>(options: Parameters<typeof wx.switchTab>[0] & OakNavigateToParameters<ED, T2>, state?: Record<string, any>, disableNamespace?: boolean) => Promise<void>;
clean: (path?: string) => void;
clean: (dontPublish?: true, path?: string) => void;
isDirty: (path?: string) => boolean;
t(key: string, params?: object): string;
execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps, path?: string, opers?: Array<{

View File

@ -1027,16 +1027,18 @@ class ListNode<
this.refresh(currentPage, false);
}
clean() {
clean(dontPublish?: true) {
if (this.dirty) {
const originUpdates = this.updates;
this.updates = {};
for (const k in this.children) {
this.children[k].clean();
this.children[k].clean(dontPublish);
}
this.dirty = undefined;
this.publish();
if (!dontPublish) {
this.publish();
}
}
}
@ -1346,14 +1348,14 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
if (attr === 'entityId') {
assert(data.entity, '设置entityId时请将entity也传入');
if (this.children[data.entity]) {
this.children[data.entity].clean();
this.children[data.entity].clean(true);
this.passRsToChild(data.entity);
}
}
else if (this.schema[this.entity]!.attributes[attr as any]?.type === 'ref') {
const refKey = attr.slice(0, attr.length - 2);
if (this.children[refKey]) {
this.children[refKey].clean();
this.children[refKey].clean(true);
this.passRsToChild(refKey);
}
}
@ -1579,15 +1581,17 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
}
}
clean() {
clean(dontPublish?: true) {
if (this.dirty) {
this.operation = undefined;
for (const child in this.children) {
this.children[child]!.clean();
this.children[child]!.clean(dontPublish);
}
this.dirty = undefined;
this.publish();
if (!dontPublish) {
this.publish();
}
}
}
@ -1826,12 +1830,14 @@ class VirtualNode<
return this.loading;
}
clean() {
clean(dontPublish?: true) {
for (const ele in this.children) {
this.children[ele].clean();
this.children[ele].clean(dontPublish);
}
this.dirty = false;
this.publish();
if (!dontPublish) {
this.publish();
}
}
checkIfClean() {
for (const k in this.children) {
@ -2506,7 +2512,7 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
undefined,
() => {
// 清空缓存
node.clean();
node.clean(true);
if (node instanceof SingleNode) {
assert(operations.length === 1);
// 这逻辑有点扯,页面自己决定后续逻辑 by Xc 20231108
@ -2523,7 +2529,7 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
return result;
}
node.clean();
node.clean(true);
node.setExecuting(false);
return { message: 'No Operation' };
@ -2536,10 +2542,10 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
}
}
clean(path: string) {
clean(path: string, dontPublish?: true) {
const node = this.findNode(path)!;
node.clean();
node.clean(dontPublish);
const parent = node.getParent();
if (parent) {
parent.checkIfClean();

View File

@ -279,11 +279,11 @@ const oakBehavior = Behavior<
return this.features.navigator.switchTab(option, state);
},
clean(path) {
clean(dontPublish, path) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
return this.features.runningTree.clean(path2);
return this.features.runningTree.clean(path2, dontPublish);
},
isDirty(path) {

View File

@ -301,11 +301,11 @@ abstract class OakComponentBase<
}
}
clean(path?: string) {
clean(dontPublish?: true, path?: string) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.clean(path2);
this.features.runningTree.clean(path2, dontPublish);
}
t(key: string, params?: object) {
@ -762,8 +762,8 @@ export function createComponent<
disableNamespace
);
},
clean: (path?: string) => {
return this.clean(path);
clean: (dontPublish?: true, path?: string) => {
return this.clean(dontPublish, path);
},
checkOperation: <T2 extends keyof ED>(entity: T2, operation: ED[T2]['Operation'], checkerTypes?: CheckerType[]) => {
return this.checkOperation(entity, operation, checkerTypes);

View File

@ -369,7 +369,7 @@ export type OakCommonComponentMethods<
disableNamespace?: boolean
) => Promise<void>;
// setProps: (props: Record<string, any>, usingState?: true) => void;
clean: (path?: string) => void;
clean: (dontPublish?: true, path?: string) => void;
isDirty: (path?: string) => boolean;
t(key: string, params?: object): string;