改动了mp下对oakPath更改的处理逻辑

This commit is contained in:
Xu Chang 2024-06-20 18:24:05 +08:00
parent 77e4b33971
commit 64fe94b972
3 changed files with 57 additions and 27 deletions

View File

@ -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);

View File

@ -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);

View File

@ -65,7 +65,7 @@ const oakBehavior = Behavior<
loadMissedLocales: (key: string) => void;
},
{
mountStatus: 'init' | 'mounted' | 'unmounted';
lifetime: 'attached' | 'created' | 'ready' | 'detached';
prevState: Record<string, any>;
state: Record<string, any>;
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<string, any>;
state: Record<string, any>;
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);