From 64fe94b97200612fe73f1a2e070cc381800e97c5 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Thu, 20 Jun 2024 18:24:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=8A=A8=E4=BA=86mp=E4=B8=8B=E5=AF=B9?= =?UTF-8?q?oakPath=E6=9B=B4=E6=94=B9=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/page.mp.js | 26 ++++++++++++++++++-------- lib/page.mp.js | 26 ++++++++++++++++++-------- src/page.mp.ts | 32 +++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/es/page.mp.js b/es/page.mp.js index 8636ef31..3fa7996b 100644 --- a/es/page.mp.js +++ b/es/page.mp.js @@ -483,14 +483,15 @@ const oakBehavior = Behavior({ oakPath(data) { if (data && data !== this.prevState.oakFullpath) { assert(data); - if (this.mountStatus !== 'mounted') { + if (this.lifetime !== 'ready') { // 在init状态小程序也会调这个observer,先忽略之 return; } const pathState = onPathSet.call(this, this.oakOption); this.setState(pathState, () => { - if (data === undefined) { - if (this.mountStatus !== 'mounted') { + if (this.prevState.oakFullpath === undefined) { + // oakFullpath后置的情况,容一下错 + if (this.lifetime !== 'ready') { // 在init状态小程序也会调这个observer,先忽略之 return; } @@ -508,11 +509,15 @@ const oakBehavior = Behavior({ this.reRender(); } } + else { + // listNode修改子结点上的oakPath时能跑到这里,直接reRender + this.reRender(); + } }); } }, oakId(data) { - if (this.mountStatus !== 'mounted') { + if (this.lifetime !== 'ready') { // 在init状态小程序也可能会调这个observer,先忽略之 return; } @@ -725,8 +730,8 @@ export function createComponent(option, features) { this.oakOption = option; this.features = features; this.featuresSubscribed = []; - this.mountStatus = 'init'; created && created.call(this); + this.lifetime = 'created'; }, attached() { if (typeof data === 'function') { @@ -795,7 +800,7 @@ export function createComponent(option, features) { (this.iAmThePage() && this.oakOption.path)) { const pathState = onPathSet.call(this, this.oakOption); this.setState(pathState, () => { - if (this.mountStatus === 'unmounted') { + if (this.lifetime === 'detached') { return; } const { oakFullpath } = this.state; @@ -805,13 +810,17 @@ export function createComponent(option, features) { else { this.reRender(); } + if (this.lifetime === 'ready') { + // ready已经调过但是oakFullpath尚未置好,在这里再调一次 + ready && ready(); + } }); } else if (!this.oakOption.entity) { this.reRender(); } - this.mountStatus = 'mounted'; attached && attached.call(this); + this.lifetime = 'attached'; }, detached() { this.unsubscribeAll(); @@ -819,7 +828,7 @@ export function createComponent(option, features) { (this.iAmThePage() || !this.props.oakZombie) && destroyNode.call(this); detached && detached.call(this); - this.mountStatus = 'unmounted'; + this.lifetime = 'detached'; }, ready() { // 等oakFullpath构建完成后再ready @@ -832,6 +841,7 @@ export function createComponent(option, features) { else if (!this.oakOption.entity) { ready && ready.call(this); } + this.lifetime = 'ready'; }, moved() { moved && moved.call(this); diff --git a/lib/page.mp.js b/lib/page.mp.js index a2f50f70..66d55c47 100644 --- a/lib/page.mp.js +++ b/lib/page.mp.js @@ -486,14 +486,15 @@ const oakBehavior = Behavior({ oakPath(data) { if (data && data !== this.prevState.oakFullpath) { (0, assert_1.assert)(data); - if (this.mountStatus !== 'mounted') { + if (this.lifetime !== 'ready') { // 在init状态小程序也会调这个observer,先忽略之 return; } const pathState = page_common_1.onPathSet.call(this, this.oakOption); this.setState(pathState, () => { - if (data === undefined) { - if (this.mountStatus !== 'mounted') { + if (this.prevState.oakFullpath === undefined) { + // oakFullpath后置的情况,容一下错 + if (this.lifetime !== 'ready') { // 在init状态小程序也会调这个observer,先忽略之 return; } @@ -511,11 +512,15 @@ const oakBehavior = Behavior({ this.reRender(); } } + else { + // listNode修改子结点上的oakPath时能跑到这里,直接reRender + this.reRender(); + } }); } }, oakId(data) { - if (this.mountStatus !== 'mounted') { + if (this.lifetime !== 'ready') { // 在init状态小程序也可能会调这个observer,先忽略之 return; } @@ -728,8 +733,8 @@ function createComponent(option, features) { this.oakOption = option; this.features = features; this.featuresSubscribed = []; - this.mountStatus = 'init'; created && created.call(this); + this.lifetime = 'created'; }, attached() { if (typeof data === 'function') { @@ -798,7 +803,7 @@ function createComponent(option, features) { (this.iAmThePage() && this.oakOption.path)) { const pathState = page_common_1.onPathSet.call(this, this.oakOption); this.setState(pathState, () => { - if (this.mountStatus === 'unmounted') { + if (this.lifetime === 'detached') { return; } const { oakFullpath } = this.state; @@ -808,13 +813,17 @@ function createComponent(option, features) { else { this.reRender(); } + if (this.lifetime === 'ready') { + // ready已经调过但是oakFullpath尚未置好,在这里再调一次 + ready && ready(); + } }); } else if (!this.oakOption.entity) { this.reRender(); } - this.mountStatus = 'mounted'; attached && attached.call(this); + this.lifetime = 'attached'; }, detached() { this.unsubscribeAll(); @@ -822,7 +831,7 @@ function createComponent(option, features) { (this.iAmThePage() || !this.props.oakZombie) && page_common_1.destroyNode.call(this); detached && detached.call(this); - this.mountStatus = 'unmounted'; + this.lifetime = 'detached'; }, ready() { // 等oakFullpath构建完成后再ready @@ -835,6 +844,7 @@ function createComponent(option, features) { else if (!this.oakOption.entity) { ready && ready.call(this); } + this.lifetime = 'ready'; }, moved() { moved && moved.call(this); diff --git a/src/page.mp.ts b/src/page.mp.ts index 0cc4ec6d..c7881841 100644 --- a/src/page.mp.ts +++ b/src/page.mp.ts @@ -65,7 +65,7 @@ const oakBehavior = Behavior< loadMissedLocales: (key: string) => void; }, { - mountStatus: 'init' | 'mounted' | 'unmounted'; + lifetime: 'attached' | 'created' | 'ready' | 'detached'; prevState: Record; state: Record; props: { @@ -696,7 +696,7 @@ const oakBehavior = Behavior< oakPath(data) { if (data && data !== this.prevState.oakFullpath) { assert(data); - if (this.mountStatus !== 'mounted') { + if (this.lifetime !== 'ready') { // 在init状态小程序也会调这个observer,先忽略之 return; } @@ -705,8 +705,9 @@ const oakBehavior = Behavior< this.oakOption as any ); this.setState(pathState as any, () => { - if (data === undefined) { - if (this.mountStatus !== 'mounted') { + if (this.prevState.oakFullpath === undefined) { + // oakFullpath后置的情况,容一下错 + if (this.lifetime !== 'ready') { // 在init状态小程序也会调这个observer,先忽略之 return; } @@ -732,11 +733,15 @@ const oakBehavior = Behavior< this.reRender(); } } + else { + // listNode修改子结点上的oakPath时能跑到这里,直接reRender + this.reRender(); + } }); } }, oakId(data) { - if (this.mountStatus !== 'mounted') { + if (this.lifetime !== 'ready') { // 在init状态小程序也可能会调这个observer,先忽略之 return; } @@ -911,7 +916,7 @@ export function createComponent< WechatMiniprogram.Component.PropertyOption, MethodOption, { - mountStatus: 'init' | 'mounted' | 'unmounted'; + lifetime: 'created' | 'attached' | 'ready' | 'detached'; prevState: Record; state: Record; featuresSubscribed: Array<{ @@ -1046,8 +1051,8 @@ export function createComponent< this.oakOption = option; this.features = features; this.featuresSubscribed = []; - this.mountStatus = 'init'; created && created.call(this); + this.lifetime = 'created'; }, attached() { if (typeof data === 'function') { @@ -1119,7 +1124,7 @@ export function createComponent< this.oakOption as any ); this.setState(pathState as any, () => { - if (this.mountStatus === 'unmounted') { + if (this.lifetime === 'detached') { return; } const { oakFullpath } = this.state; @@ -1128,13 +1133,17 @@ export function createComponent< } else { this.reRender(); } + + if (this.lifetime === 'ready') { + // ready已经调过但是oakFullpath尚未置好,在这里再调一次 + ready && ready(); + } }); } else if (!this.oakOption.entity) { this.reRender(); } - this.mountStatus = 'mounted'; - attached && attached.call(this); + this.lifetime = 'attached'; }, detached() { this.unsubscribeAll(); @@ -1143,7 +1152,7 @@ export function createComponent< destroyNode.call(this as any); detached && detached.call(this); - this.mountStatus = 'unmounted'; + this.lifetime = 'detached'; }, ready() { // 等oakFullpath构建完成后再ready @@ -1159,6 +1168,7 @@ export function createComponent< else if (!this.oakOption.entity) { ready && ready.call(this); } + this.lifetime = 'ready'; }, moved() { moved && moved.call(this);