From 7114b62c3a64bbcabff18cbd7791cb553249b522 Mon Sep 17 00:00:00 2001 From: magicly Date: Tue, 14 Mar 2017 11:54:20 +0800 Subject: [PATCH 1/6] =?UTF-8?q?error=E8=BF=98=E5=8C=85=E5=90=ABerr=5Fcode,?= =?UTF-8?q?=20err=5Fdesc=E7=AD=89=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=8F=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BAerrMsg=E4=B8=8D=E5=88=A9=E4=BA=8Edebug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.js b/index.js index 37d9f12..9f2323d 100644 --- a/index.js +++ b/index.js @@ -82,12 +82,8 @@ Object.keys(wx).forEach((key) => { obj = obj || {}; return new Promise((resolve, reject) => { obj.success = resolve; - obj.fail = (res) => { - if (res && res.errMsg) { - reject(new Error(res.errMsg)); - } else { + obj.fail = res => { reject(res); - } }; wx[key](obj); }); From a7d1c119e35b13dd84f08f828c32c5a368e379bb Mon Sep 17 00:00:00 2001 From: magicly Date: Fri, 31 Mar 2017 14:04:22 +0800 Subject: [PATCH 2/6] setState just setData not all state --- component.js | 121 +++++++++++++++++++++++++------------------------ create-page.js | 35 ++++++++------ 2 files changed, 83 insertions(+), 73 deletions(-) diff --git a/component.js b/component.js index d744271..0ba83a8 100644 --- a/component.js +++ b/component.js @@ -93,60 +93,61 @@ export default class Component { if (!this._inited) { console.error(this.id + ' 组件未自动初始化之前请勿调用setState(),如果在组件构造函数中请直接使用"this.state={}"赋值语法'); } - this._setStateQueue.push(nextState); - if (callback) { - this._setStateCallbacks.push(callback); - } - - if (this._setStateTimer) return; - - this._setStateTimer = setTimeout(() => { - this._setStateTimer = 0; - let state = this.state; - let stateChanged = false; - this._setStateQueue.forEach((item) => { + // this._setStateQueue.push(nextState); + // if (callback) { + // this._setStateCallbacks.push(callback); + // } + + // if (this._setStateTimer) return; + + // this._setStateTimer = setTimeout(() => { + // this._setStateTimer = 0; + // let state = this.state; + // let stateChanged = false; + // this._setStateQueue.forEach((item) => { + let item = nextState; if (typeof item === 'function') { item = item(state, this.props); } - if (!utils.shouldUpdate(state, item)) { - // 如果没有发生变化,则忽略更新,优化性能 - if (__DEV__) { - console.log('%c%s setState(%o) ignored', - 'color:#fcc', - this.id, - utils.getDebugObject(item) - ); - } - return; - } - - stateChanged = true; - - if (__DEV__) { - // Development 环境打印state变化 - let original = utils.getDebugObject(state); - let append = utils.getDebugObject(item); - state = Object.assign({}, state, item); - console.log('%c%s setState(%o) : %o -> %o Component:%o', - 'color:#2a8f99', - this.id, append, original, - utils.getDebugObject(state), - this - ); - } else { - state = Object.assign({}, state, item); - } - }); - - this.state = state; - this._setStateQueue = []; - this._setStateCallbacks.forEach((fn) => fn()); - this._setStateCallbacks = []; - - if (!stateChanged) return; - - this._update(); - }); + // if (!utils.shouldUpdate(state, item)) { + // // 如果没有发生变化,则忽略更新,优化性能 + // if (__DEV__) { + // console.log('%c%s setState(%o) ignored', + // 'color:#fcc', + // this.id, + // utils.getDebugObject(item) + // ); + // } + // return; + // } + + // stateChanged = true; + + // if (__DEV__) { + // // Development 环境打印state变化 + // let original = utils.getDebugObject(state); + // let append = utils.getDebugObject(item); + // state = Object.assign({}, state, item); + // console.log('%c%s setState(%o) : %o -> %o Component:%o', + // 'color:#2a8f99', + // this.id, append, original, + // utils.getDebugObject(state), + // this + // ); + // } else { + // state = Object.assign({}, state, item); + // } + // }); + + // this.state = state; + // this._setStateQueue = []; + // this._setStateCallbacks.forEach((fn) => fn()); + // this._setStateCallbacks = []; + + // if (!stateChanged) return; + + this._update(item); + // }); } /** @@ -235,22 +236,26 @@ export default class Component { * 更新组件 * @private */ - _update() { - if (this._updateTimer) return; - this._updateTimer = setTimeout(() => { - this._updateTimer = 0; + _update(item) { + if (!item) item = this.state; + // if (this._updateTimer) return; + // this._updateTimer = setTimeout(() => { + // this._updateTimer = 0; // 内部state数据更新后,自动更新页面数据 let path = this.path ? this.path + '.' : ''; let newData = {}; newData[path + 'props'] = this.props; - newData[path + 'state'] = this.state; + // newData[path + 'state'] = this.state; + for (let key in item) { + newData[path + 'state.' + key] = item[key]; + } this.page.updateData(newData); // 更新子组件列表 - this._updateChildren(); - }); + // this._updateChildren(); + // }); } /** diff --git a/create-page.js b/create-page.js index d5a688a..0175362 100644 --- a/create-page.js +++ b/create-page.js @@ -93,21 +93,26 @@ module.exports = function createPage(ComponentClass: Class) { // if (__DEV__) { // console.log('%c%s updateData(%o)', 'color:#2a8f99', page.__route__, utils.getDebugObject(newData)); // } - let data = page.data; - - Object.keys(newData).forEach((path) => { - let dataMap = newData[path]; - if (Array.isArray(dataMap)) { - // 如果是组件列表,需要与之前列表数据合并,这样主要为了在子组件嵌套情况下,不丢失底层子组件数据 - let list = _get(data, path); //原有data中列表数据 - let newList = dataMap.map((item) => buildListItem(list, item)); - _set(data, path, newList); - } else { - _set(data, path.split('.'), dataMap); - } - }); - - page.setData(data); + // let data = page.data; + + // console.log('newData: ', newData) + + // Object.keys(newData).forEach((path) => { + // let dataMap = newData[path]; + // if (Array.isArray(dataMap)) { + // // 如果是组件列表,需要与之前列表数据合并,这样主要为了在子组件嵌套情况下,不丢失底层子组件数据 + // let list = _get(data, path); //原有data中列表数据 + // let newList = dataMap.map((item) => buildListItem(list, item)); + // _set(data, path, newList); + // } else { + // _set(data, path.split('.'), dataMap); + // } + // }); + + // console.log('data: ', data) + + // page.setData(data); + page.setData(newData); }; let root = page.root = new ComponentClass({}); From 771b6b313a317963641a99e8c107e5dc2f24728a Mon Sep 17 00:00:00 2001 From: magicly Date: Fri, 31 Mar 2017 16:10:54 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=B0=86newState?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=90=88=E5=B9=B6=E5=88=B0=E5=8E=9F=E6=9D=A5?= =?UTF-8?q?=E7=9A=84state=E9=87=8C=EF=BC=8C=E5=90=A6=E5=88=99=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BC=9A=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/component.js b/component.js index 0ba83a8..779848d 100644 --- a/component.js +++ b/component.js @@ -102,7 +102,7 @@ export default class Component { // this._setStateTimer = setTimeout(() => { // this._setStateTimer = 0; - // let state = this.state; + let state = this.state; // let stateChanged = false; // this._setStateQueue.forEach((item) => { let item = nextState; @@ -123,23 +123,23 @@ export default class Component { // stateChanged = true; - // if (__DEV__) { - // // Development 环境打印state变化 - // let original = utils.getDebugObject(state); - // let append = utils.getDebugObject(item); - // state = Object.assign({}, state, item); - // console.log('%c%s setState(%o) : %o -> %o Component:%o', - // 'color:#2a8f99', - // this.id, append, original, - // utils.getDebugObject(state), - // this - // ); - // } else { - // state = Object.assign({}, state, item); - // } + if (__DEV__) { + // Development 环境打印state变化 + let original = utils.getDebugObject(state); + let append = utils.getDebugObject(item); + state = Object.assign({}, state, item); + console.log('%c%s setState(%o) : %o -> %o Component:%o', + 'color:#2a8f99', + this.id, append, original, + utils.getDebugObject(state), + this + ); + } else { + state = Object.assign({}, state, item); + } // }); - // this.state = state; + this.state = state; // this._setStateQueue = []; // this._setStateCallbacks.forEach((fn) => fn()); // this._setStateCallbacks = []; From bdfc974c3753d0c24858639ddb036885786465bf Mon Sep 17 00:00:00 2001 From: ON10N Date: Wed, 16 Aug 2017 19:41:30 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E8=A1=A5=E4=B8=8A=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- create-page.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create-page.js b/create-page.js index d5a688a..a4961cf 100644 --- a/create-page.js +++ b/create-page.js @@ -142,8 +142,8 @@ module.exports = function createPage(ComponentClass: Class) { }; if (ComponentClass.prototype.onShareAppMessage) { - config.onShareAppMessage = function () { - let share = this.root.onShareAppMessage(); + config.onShareAppMessage = function (res) { + let share = this.root.onShareAppMessage(res); if (__DEV__ && !share) { console.error(this.root.id + ' onShareAppMessage() 没有返回分享数据'); } From 04154bf5ec699db3c2c571f6fa1f77f09116523f Mon Sep 17 00:00:00 2001 From: ON10N Date: Wed, 13 Sep 2017 16:40:12 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=8E=92=E9=99=A4getBackgroundAudioManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 37d9f12..840d48b 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ const noPromiseMethods = { drawCanvas: 1, canvasToTempFilePath: 1, hideKeyboard: 1, + getBackgroundAudioManager: 1 }; const labrador = { From 81f2633fb19ba334c57d8617a4d21f87c0f815b1 Mon Sep 17 00:00:00 2001 From: ON10N Date: Tue, 10 Oct 2017 14:06:53 +0800 Subject: [PATCH 6/6] fix not init component --- component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component.js b/component.js index 779848d..49b846d 100644 --- a/component.js +++ b/component.js @@ -254,7 +254,7 @@ export default class Component { this.page.updateData(newData); // 更新子组件列表 - // this._updateChildren(); + this._updateChildren(); // }); }