From 4a7e7ca5bb34cfa6b9f52b97539c546c3ddb83db Mon Sep 17 00:00:00 2001 From: GSBL <2602140596@qq.com> Date: Thu, 22 Aug 2019 14:53:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81lifetimes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/create.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/create.js b/utils/create.js index 7f22a39..8fb5721 100644 --- a/utils/create.js +++ b/utils/create.js @@ -54,10 +54,17 @@ export default function create(store, option) { Page(option) } else { - const ready = store.ready const pure = store.pure const componentUpdatePath = getUpdatePath(store.data) - store.ready = function () { + let ready = null + if (store.lifetimes === undefined) { + store.lifetimes = {} + } else if (store.lifetimes) { + ready = store.lifetimes.ready + } else { + ready = store.ready + } + store.lifetimes.ready = function () { if (pure) { this.store = { data: store.data || {} } this.store.originData = store.data ? JSON.parse(JSON.stringify(store.data)) : {} From 8e8a2aa066786a56059faa9d07125ab2bca4ce6b Mon Sep 17 00:00:00 2001 From: GSBL <2602140596@qq.com> Date: Thu, 22 Aug 2019 20:12:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=94=AF=E6=8C=81lifetimes=E5=B9=B6?= =?UTF-8?q?=E5=85=BC=E5=AE=B92.2.3=E4=BB=A5=E4=B8=8B=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/create.js | 60 ++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/utils/create.js b/utils/create.js index 8fb5721..ab7d061 100644 --- a/utils/create.js +++ b/utils/create.js @@ -7,6 +7,8 @@ let fnMapping = {} const ARRAYTYPE = '[object Array]' const OBJECTTYPE = '[object Object]' const FUNCTIONTYPE = '[object Function]' +const { SDKVersion } = wx.getSystemInfoSync() +const isSupportLifetimes = SDKVersion >= '2.2.3' export default function create(store, option) { let updatePath = null @@ -57,31 +59,39 @@ export default function create(store, option) { const pure = store.pure const componentUpdatePath = getUpdatePath(store.data) let ready = null - if (store.lifetimes === undefined) { - store.lifetimes = {} - } else if (store.lifetimes) { - ready = store.lifetimes.ready - } else { - ready = store.ready - } - store.lifetimes.ready = function () { - if (pure) { - this.store = { data: store.data || {} } - this.store.originData = store.data ? JSON.parse(JSON.stringify(store.data)) : {} - walk(store.data || {}) - rewritePureUpdate(this) - } else { - this.page = getCurrentPages()[getCurrentPages().length - 1] - this.store = this.page.store - this._updatePath = componentUpdatePath - syncValues(this.store.data, store.data) - walk(store.data || {}) - this.setData.call(this, this.store.data) - rewriteUpdate(this) - this.store.instances[this.page.route].push(this) - } - ready && ready.call(this) - } + let newReady = function () { + if (pure) { + this.store = { + data: store.data || {}, + } + this.store.originData = store.data ? JSON.parse(JSON.stringify(store.data)) : {} + walk(store.data || {}) + rewritePureUpdate(this) + } else { + this.page = getCurrentPages()[getCurrentPages().length - 1] + this.store = this.page.store + this._updatePath = componentUpdatePath + syncValues(this.store.data, store.data) + walk(store.data || {}) + this.setData.call(this, this.store.data) + rewriteUpdate(this) + this.store.instances[this.page.route].push(this) + } + ready && ready.call(this) + } + if (isSupportLifetimes) { + if (store.lifetimes === undefined) { + store.lifetimes = {} + } else if (store.lifetimes) { + ready = store.lifetimes.ready + } else { + ready = store.ready + } + store.lifetimes.ready = newReady + } else { + ready = store.ready + store.ready = newReady + } Component(store) } }