From 42b7600e5109a1ef388316728748b50281c99621 Mon Sep 17 00:00:00 2001 From: Xc Date: Mon, 10 Feb 2025 10:57:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9Fmature=EF=BC=8C=E5=BD=93?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=AE=8C=E6=88=90=E6=95=B0=E6=8D=AE=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E6=97=B6=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/features/runningTree.js | 7 +++-- es/page.mp.js | 12 +++++--- es/page.react.js | 4 ++- es/platforms/web/initialize/index.js | 4 +-- es/types/Page.d.ts | 14 ++++++---- lib/features/runningTree.js | 2 +- lib/page.mp.js | 12 +++++--- lib/page.native.d.ts | 3 +- lib/page.react.d.ts | 21 +++++++++++++- lib/page.react.js | 4 ++- lib/page.web.d.ts | 3 +- lib/page.web.js | 1 - lib/platforms/native/features/index.d.ts | 4 +-- lib/platforms/native/router/withRouter.d.ts | 3 +- lib/platforms/web/Loading.d.ts | 3 +- lib/platforms/web/PullToRefresh.js | 1 - lib/platforms/web/features/index.d.ts | 2 +- .../web/initialize/AppContainer.d.ts | 2 +- lib/platforms/web/initialize/AppError.d.ts | 2 +- lib/platforms/web/initialize/AppError.js | 28 +++++++++++++++++-- lib/platforms/web/initialize/AppRouter.d.ts | 2 +- lib/platforms/web/initialize/index.js | 2 -- lib/platforms/web/responsive/context.d.ts | 5 +++- lib/platforms/web/router/withRouter.d.ts | 3 +- lib/types/Page.d.ts | 14 ++++++---- src/features/runningTree.ts | 2 +- src/page.mp.ts | 12 +++++--- src/page.react.tsx | 4 ++- src/types/Page.ts | 14 ++++++---- 29 files changed, 133 insertions(+), 57 deletions(-) diff --git a/es/features/runningTree.js b/es/features/runningTree.js index 12685e5b..e5f6aedf 100644 --- a/es/features/runningTree.js +++ b/es/features/runningTree.js @@ -113,7 +113,7 @@ class UpdateLogManager { // 插入到最后一次update中 const { action, filter, data } = oper2; let ids = action === 'create' ? [data.id] : getRelevantIds(filter); - const key = JSON.stringify(ids.length > 0 ? { ids } : filter); + const key = JSON.stringify(ids.length > 0 ? ids : filter); if (this.logs.length > 0) { const update = this.logs[this.logs.length - 1]; assert(update.lsn <= lsn); @@ -155,7 +155,8 @@ class UpdateLogManager { } } undo(filter) { - const key = JSON.stringify(filter); + const ids = getRelevantIds(filter); + const key = JSON.stringify(ids.length > 0 ? ids : filter); this.logs.forEach((log) => { const { operations } = log; unset(operations, key); @@ -524,7 +525,7 @@ class ListNode extends EntityNode { id: 1, }, filter: combineFilters(this.entity, this.schema, [ - ...filter, + ...(filter || []), { id: { $in: intersected, diff --git a/es/page.mp.js b/es/page.mp.js index c632503c..2dee26c4 100644 --- a/es/page.mp.js +++ b/es/page.mp.js @@ -473,7 +473,7 @@ const oakBehavior = Behavior({ return; } const pathState = onPathSet.call(this, this.oakOption, this.iAmThePage()); - this.setState(pathState, () => { + this.setState(pathState, async () => { if (this.prevState.oakFullpath === undefined) { // oakFullpath后置的情况,容一下错 if (this.oakLifetime !== 'ready') { @@ -486,7 +486,8 @@ const oakBehavior = Behavior({ this.oakOption.lifetimes?.ready.call(this); const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { - this.refresh(); + await this.refresh(); + this.oakOption.lifetimes?.mature && this.oakOption.lifetimes.mature(); } else { this.reRender(); @@ -649,6 +650,7 @@ export function createComponent(option, features) { await (onPullDownRefresh ? onPullDownRefresh.call(this) : this.refresh()); + lifetimes?.mature && lifetimes.mature(); this.setState({ oakPullDownRefreshLoading: false, }); @@ -755,7 +757,7 @@ export function createComponent(option, features) { else { assert(typeof ele === 'object'); const { feature, behavior, callback } = ele; - this.addFeatureSub(feature, () => { + this.addFeatureSub(feature, async () => { if (behavior) { switch (behavior) { case 'reRender': { @@ -764,7 +766,8 @@ export function createComponent(option, features) { } default: { assert(behavior === 'refresh'); - this.refresh(); + await this.refresh(); + lifetimes?.mature && lifetimes.mature(); return; } } @@ -791,6 +794,7 @@ export function createComponent(option, features) { if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { try { await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } catch (err) { if (err instanceof OakException) { diff --git a/es/page.react.js b/es/page.react.js index 85a1bd76..39a5f219 100644 --- a/es/page.react.js +++ b/es/page.react.js @@ -648,6 +648,7 @@ export function createComponent(option, features) { const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } else { this.reRender(); @@ -705,7 +706,8 @@ export function createComponent(option, features) { } const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { - this.refresh(); + await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } else { this.reRender(); diff --git a/es/platforms/web/initialize/index.js b/es/platforms/web/initialize/index.js index bc4f2b89..e8432947 100644 --- a/es/platforms/web/initialize/index.js +++ b/es/platforms/web/initialize/index.js @@ -5,13 +5,13 @@ import { createBrowserHistory } from 'history'; import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom'; import { ConfigProvider } from 'antd'; import { StyleProvider, legacyLogicalPropertiesTransformer } from '@ant-design/cssinjs'; +import dayjs from 'dayjs'; import { ResponsiveProvider } from '../responsive'; import { FeaturesProvider } from '../features'; import AppError from './AppError'; import AppContainer from './AppContainer'; import AppRouter from './AppRouter'; // import { AliveScope, autoFixContext } from 'react-activation' -import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; import zhCN from 'antd/locale/zh_CN'; import enUS from 'antd/locale/en_US'; @@ -23,7 +23,7 @@ export default function initialize(features, appName, routers, locales, error, f const history = createBrowserHistory(); features.navigator.setHistory(history); const { language } = window.navigator; - dayjs.locale(locales?.dayJs || ['zh-CN', 'zh_CN'].includes(language) ? 'zh-cn' : 'en-us'); + dayjs.locale(locales?.dayJs || ['zh-CN', 'zh_CN'].includes(language) ? 'zh-cn' : 'en-us'); const Main = error ? ( ) : ( diff --git a/es/types/Page.d.ts b/es/types/Page.d.ts index b98082da..307ddeb1 100644 --- a/es/types/Page.d.ts +++ b/es/types/Page.d.ts @@ -155,12 +155,12 @@ export type OakComponentOption { + this.setState(pathState, async () => { if (this.prevState.oakFullpath === undefined) { // oakFullpath后置的情况,容一下错 if (this.oakLifetime !== 'ready') { @@ -489,7 +489,8 @@ const oakBehavior = Behavior({ this.oakOption.lifetimes?.ready.call(this); const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { - this.refresh(); + await this.refresh(); + this.oakOption.lifetimes?.mature && this.oakOption.lifetimes.mature(); } else { this.reRender(); @@ -652,6 +653,7 @@ function createComponent(option, features) { await (onPullDownRefresh ? onPullDownRefresh.call(this) : this.refresh()); + lifetimes?.mature && lifetimes.mature(); this.setState({ oakPullDownRefreshLoading: false, }); @@ -758,7 +760,7 @@ function createComponent(option, features) { else { (0, assert_1.assert)(typeof ele === 'object'); const { feature, behavior, callback } = ele; - this.addFeatureSub(feature, () => { + this.addFeatureSub(feature, async () => { if (behavior) { switch (behavior) { case 'reRender': { @@ -767,7 +769,8 @@ function createComponent(option, features) { } default: { (0, assert_1.assert)(behavior === 'refresh'); - this.refresh(); + await this.refresh(); + lifetimes?.mature && lifetimes.mature(); return; } } @@ -794,6 +797,7 @@ function createComponent(option, features) { if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { try { await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } catch (err) { if (err instanceof types_1.OakException) { diff --git a/lib/page.native.d.ts b/lib/page.native.d.ts index a94c1ec6..2f5bea53 100644 --- a/lib/page.native.d.ts +++ b/lib/page.native.d.ts @@ -1,3 +1,4 @@ +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'; @@ -5,4 +6,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, FrontCxt extends SyncContext, AD extends Record>>, FD extends Record, FormedData extends Record, TData extends Record = {}, TProperty extends DataOption = {}, TMethod extends Record = {}>(option: OakComponentOption, features: BasicFeatures & FD): any; +export declare function createComponent, FrontCxt extends SyncContext, AD extends Record>>, FD extends Record, FormedData extends Record, TData extends Record = {}, TProperty extends DataOption = {}, TMethod extends Record = {}>(option: OakComponentOption, features: BasicFeatures & FD): React.ForwardRefExoticComponent>; diff --git a/lib/page.react.d.ts b/lib/page.react.d.ts index c7c37a41..44a00479 100644 --- a/lib/page.react.d.ts +++ b/lib/page.react.d.ts @@ -1,9 +1,10 @@ +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, ComponentProps, OakComponentOption, OakNavigateToParameters } from './types/Page'; +import { DataOption, ComponentData, ComponentProps, OakComponentOption, OakNavigateToParameters } from './types/Page'; import { MessageProps } from './types/Message'; import { NotificationProps } from './types/Notification'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; @@ -103,5 +104,23 @@ export declare function createComponent[]) => void): Promise<() => void>; + context: unknown; + setState>(state: ComponentData | ((prevState: Readonly>, props: Readonly>) => ComponentData | Pick, K> | null) | Pick, K> | null, callback?: (() => void) | undefined): void; + forceUpdate(callback?: (() => void) | undefined): void; + readonly props: Readonly>; + state: Readonly>; + refs: { + [key: string]: React.ReactInstance; + }; + shouldComponentUpdate?(nextProps: Readonly>, nextState: Readonly>, nextContext: any): boolean; + componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; + getSnapshotBeforeUpdate?(prevProps: Readonly>, prevState: Readonly>): any; + componentWillMount?(): void; + UNSAFE_componentWillMount?(): void; + componentWillReceiveProps?(nextProps: Readonly>, nextContext: any): void; + UNSAFE_componentWillReceiveProps?(nextProps: Readonly>, nextContext: any): void; + componentWillUpdate?(nextProps: Readonly>, nextState: Readonly>, nextContext: any): void; + UNSAFE_componentWillUpdate?(nextProps: Readonly>, nextState: Readonly>, nextContext: any): void; }; + contextType?: React.Context | undefined; }; diff --git a/lib/page.react.js b/lib/page.react.js index 628057a0..6f6c06c1 100644 --- a/lib/page.react.js +++ b/lib/page.react.js @@ -653,6 +653,7 @@ function createComponent(option, features) { const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } else { this.reRender(); @@ -710,7 +711,8 @@ function createComponent(option, features) { } const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { - this.refresh(); + await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } else { this.reRender(); diff --git a/lib/page.web.d.ts b/lib/page.web.d.ts index a94c1ec6..2f5bea53 100644 --- a/lib/page.web.d.ts +++ b/lib/page.web.d.ts @@ -1,3 +1,4 @@ +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'; @@ -5,4 +6,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, FrontCxt extends SyncContext, AD extends Record>>, FD extends Record, FormedData extends Record, TData extends Record = {}, TProperty extends DataOption = {}, TMethod extends Record = {}>(option: OakComponentOption, features: BasicFeatures & FD): any; +export declare function createComponent, FrontCxt extends SyncContext, AD extends Record>>, FD extends Record, FormedData extends Record, TData extends Record = {}, TProperty extends DataOption = {}, TMethod extends Record = {}>(option: OakComponentOption, features: BasicFeatures & FD): React.ForwardRefExoticComponent>; diff --git a/lib/page.web.js b/lib/page.web.js index 28223b2f..ca1bd151 100644 --- a/lib/page.web.js +++ b/lib/page.web.js @@ -3,7 +3,6 @@ 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"); diff --git a/lib/platforms/native/features/index.d.ts b/lib/platforms/native/features/index.d.ts index 61a6578a..ed07a4f1 100644 --- a/lib/platforms/native/features/index.d.ts +++ b/lib/platforms/native/features/index.d.ts @@ -4,6 +4,6 @@ type Props = { features: Record; children: React.ReactNode; }; -declare const FeaturesProvider: (props: Props) => any; -declare const useFeatures: >() => any; +declare const FeaturesProvider: (props: Props) => import("react/jsx-runtime").JSX.Element; +declare const useFeatures: >() => FD2; export { FeaturesProvider, useFeatures }; diff --git a/lib/platforms/native/router/withRouter.d.ts b/lib/platforms/native/router/withRouter.d.ts index 21857320..5eda84fb 100644 --- a/lib/platforms/native/router/withRouter.d.ts +++ b/lib/platforms/native/router/withRouter.d.ts @@ -1,6 +1,7 @@ +import React from 'react'; type OakComponentProperties = { path?: string; properties?: Record; }; -declare const withRouter: (Component: React.ComponentType, { path, properties }: OakComponentProperties) => any; +declare const withRouter: (Component: React.ComponentType, { path, properties }: OakComponentProperties) => React.ForwardRefExoticComponent>; export default withRouter; diff --git a/lib/platforms/web/Loading.d.ts b/lib/platforms/web/Loading.d.ts index 6cf00498..9a4eb5de 100644 --- a/lib/platforms/web/Loading.d.ts +++ b/lib/platforms/web/Loading.d.ts @@ -1,3 +1,4 @@ +import React from 'react'; import 'nprogress/nprogress.css'; -declare const _default: any; +declare const _default: React.MemoExoticComponent<() => null>; export default _default; diff --git a/lib/platforms/web/PullToRefresh.js b/lib/platforms/web/PullToRefresh.js index cbab5c59..a2170211 100644 --- a/lib/platforms/web/PullToRefresh.js +++ b/lib/platforms/web/PullToRefresh.js @@ -2,7 +2,6 @@ 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) => { diff --git a/lib/platforms/web/features/index.d.ts b/lib/platforms/web/features/index.d.ts index 08182f40..18e3356a 100644 --- a/lib/platforms/web/features/index.d.ts +++ b/lib/platforms/web/features/index.d.ts @@ -4,5 +4,5 @@ declare const FeaturesProvider: React.FC<{ features: Record; children: React.ReactNode; }>; -declare const useFeatures: >() => any; +declare const useFeatures: >() => FD2; export { FeaturesProvider, useFeatures }; diff --git a/lib/platforms/web/initialize/AppContainer.d.ts b/lib/platforms/web/initialize/AppContainer.d.ts index 22b5a939..03e1966b 100644 --- a/lib/platforms/web/initialize/AppContainer.d.ts +++ b/lib/platforms/web/initialize/AppContainer.d.ts @@ -2,5 +2,5 @@ import React from 'react'; type AppContainerProps = { children?: React.ReactNode; }; -declare const AppContainer: (props: AppContainerProps) => any; +declare const AppContainer: (props: AppContainerProps) => import("react/jsx-runtime").JSX.Element; export default AppContainer; diff --git a/lib/platforms/web/initialize/AppError.d.ts b/lib/platforms/web/initialize/AppError.d.ts index 300bfc4f..f0499037 100644 --- a/lib/platforms/web/initialize/AppError.d.ts +++ b/lib/platforms/web/initialize/AppError.d.ts @@ -5,5 +5,5 @@ interface ErrorProps { error: any; features: BasicFeatures; } -declare function Error(props: ErrorProps): any; +declare function Error(props: ErrorProps): import("react/jsx-runtime").JSX.Element; export default Error; diff --git a/lib/platforms/web/initialize/AppError.js b/lib/platforms/web/initialize/AppError.js index d8daf50a..b1344b81 100644 --- a/lib/platforms/web/initialize/AppError.js +++ b/lib/platforms/web/initialize/AppError.js @@ -1,12 +1,34 @@ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); -const react_1 = tslib_1.__importStar(require("react")); +const react_1 = require("react"); const antd_1 = require("antd"); const Exception_1 = require("oak-domain/lib/types/Exception"); const ErrorPage_1 = require("../../../types/ErrorPage"); -const ErrorPage = (0, react_1.lazy)(() => Promise.resolve().then(() => tslib_1.__importStar(require('../../../components/errorPage')))); +const ErrorPage = (0, react_1.lazy)(() => Promise.resolve().then(() => __importStar(require('../../../components/errorPage')))); function Error(props) { const { error, features } = props; const { locales } = features; diff --git a/lib/platforms/web/initialize/AppRouter.d.ts b/lib/platforms/web/initialize/AppRouter.d.ts index d6b79bba..b7620d11 100644 --- a/lib/platforms/web/initialize/AppRouter.d.ts +++ b/lib/platforms/web/initialize/AppRouter.d.ts @@ -5,5 +5,5 @@ declare const AppRouter: (props: { routers: IRouter[]; appName: string; features: BasicFeatures; -}) => any; +}) => import("react/jsx-runtime").JSX.Element; export default AppRouter; diff --git a/lib/platforms/web/initialize/index.js b/lib/platforms/web/initialize/index.js index 8760b978..146744e9 100644 --- a/lib/platforms/web/initialize/index.js +++ b/lib/platforms/web/initialize/index.js @@ -2,8 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); -// @ts-nocheck -const react_1 = tslib_1.__importDefault(require("react")); const client_1 = tslib_1.__importDefault(require("react-dom/client")); const history_1 = require("history"); const react_router_dom_1 = require("react-router-dom"); diff --git a/lib/platforms/web/responsive/context.d.ts b/lib/platforms/web/responsive/context.d.ts index 0fded541..08e5d73e 100644 --- a/lib/platforms/web/responsive/context.d.ts +++ b/lib/platforms/web/responsive/context.d.ts @@ -1,3 +1,4 @@ +import React from 'react'; export type Width = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'; export type Keys = Width[]; export type Values = { @@ -15,4 +16,6 @@ export type Breakpoints = { export declare const keys: Keys; export declare const values: Values; export declare const defaultBreakpoints: Breakpoints; -export declare const ResponsiveContext: any; +export declare const ResponsiveContext: React.Context<{ + breakpoints?: Breakpoints | undefined; +}>; diff --git a/lib/platforms/web/router/withRouter.d.ts b/lib/platforms/web/router/withRouter.d.ts index 21857320..5eda84fb 100644 --- a/lib/platforms/web/router/withRouter.d.ts +++ b/lib/platforms/web/router/withRouter.d.ts @@ -1,6 +1,7 @@ +import React from 'react'; type OakComponentProperties = { path?: string; properties?: Record; }; -declare const withRouter: (Component: React.ComponentType, { path, properties }: OakComponentProperties) => any; +declare const withRouter: (Component: React.ComponentType, { path, properties }: OakComponentProperties) => React.ForwardRefExoticComponent>; export default withRouter; diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index b98082da..307ddeb1 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -155,12 +155,12 @@ export type OakComponentOption { + this.setState(pathState as any, async () => { if (this.prevState.oakFullpath === undefined) { // oakFullpath后置的情况,容一下错 if (this.oakLifetime !== 'ready') { @@ -710,7 +710,8 @@ const oakBehavior = Behavior< const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { - this.refresh(); + await this.refresh(); + this.oakOption.lifetimes?.mature && this.oakOption.lifetimes.mature(); } else { this.reRender(); } @@ -968,6 +969,7 @@ export function createComponent< ? onPullDownRefresh.call(this) : this.refresh() ); + lifetimes?.mature && lifetimes.mature(); this.setState({ oakPullDownRefreshLoading: false as any, }); @@ -1075,7 +1077,7 @@ export function createComponent< } else { assert(typeof ele === 'object'); const { feature, behavior, callback } = ele; - this.addFeatureSub(feature as string, () => { + this.addFeatureSub(feature as string, async () => { if (behavior) { switch (behavior) { case 'reRender': { @@ -1084,7 +1086,8 @@ export function createComponent< } default: { assert(behavior === 'refresh'); - this.refresh(); + await this.refresh(); + lifetimes?.mature && lifetimes.mature(); return; } } @@ -1116,6 +1119,7 @@ export function createComponent< if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { try { await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } catch (err) { if (err instanceof OakException) { diff --git a/src/page.react.tsx b/src/page.react.tsx index 35c2406f..a6306716 100644 --- a/src/page.react.tsx +++ b/src/page.react.tsx @@ -981,6 +981,7 @@ export function createComponent< const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } else { this.reRender(); @@ -1048,7 +1049,8 @@ export function createComponent< } const { oakFullpath } = this.state; if (oakFullpath && !this.features.runningTree.isListDescandentOrStale(oakFullpath)) { - this.refresh(); + await this.refresh(); + lifetimes?.mature && lifetimes.mature(); } else { this.reRender(); diff --git a/src/types/Page.ts b/src/types/Page.ts index 859ab554..5a06b6f0 100644 --- a/src/types/Page.ts +++ b/src/types/Page.ts @@ -332,12 +332,12 @@ export type OakComponentOption< * 在组件实例刚刚被创建时执行 * sync only */ - created?(): void; + created?(): any; /** * 在组件实例进入页面节点树时执行 * sync only */ - attached?(): void; + attached?(): any; /** * 在组件实例进入页面节点树时执行 * async or sync @@ -347,18 +347,22 @@ export type OakComponentOption< * 小程序专用,在组件实例被移动到节点树另一个位置时执行 * sync only */ - moved?(): void; + moved?(): any; /** * 在组件实例被从页面节点树移除时执行 * sync only */ - detached?(): void; + detached?(): any; /** * 小程序专用,每当组件方法抛出错误时执行 * sync only * @param err 错误信息 */ - error?(err: Error): void; + error?(err: Error): any; + /** + * 当页面取数完成后回调 + */ + mature?(): any; /** * 组件所在的页面被展示时执行 * sync only