Skip to content

Commit

Permalink
fix(okam-core): fix watch not work in wx custom component
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhy committed Nov 4, 2018
1 parent 583bf02 commit 0a7cdd0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/okam-core/src/extend/data/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default {
/**
* Watch the given expression or function
*
* @param {string|Function} expressOrFunc the expression or functon to watch
* @param {string|Function} expressOrFunc the expression or function to watch
* @param {Function|Object} callback the callback to execute when the
* expression or function value changes
* @param {Object=} options watch options
Expand All @@ -115,8 +115,12 @@ export default {
* @private
*/
afterObserverInit() {
let watch = this.$rawWatch;
if (typeof watch === 'function') {
watch = this.$rawWatch();
}
this.__computedObserver.addWatchComputed(
normalizeWatch.call(this, this.watch)
normalizeWatch.call(this, watch)
);
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/okam-core/src/helper/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
* @type {Array.<string>}
*/
const extendPropMethods = [
'beforeCreate', 'beforeMount', 'mounted',
'beforeDestroy', 'destroyed', 'beforeUpdate',
'updated', ['computed', '$computed'], '$rawRefData'
'beforeCreate',
'beforeMount', 'mounted',
'beforeDestroy', 'destroyed',
'beforeUpdate', 'updated',
['computed', '$rawComputed'],
['watch', '$rawWatch'],
'$rawRefData'
];

/**
Expand Down
8 changes: 7 additions & 1 deletion packages/okam-core/src/helper/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export function normalizePage(pageInfo) {

let computed = pageInfo.computed;
if (computed) {
pageInfo.$computed = computed;
pageInfo.$rawComputed = computed;
delete pageInfo.computed;
}

let watch = pageInfo.watch;
if (watch) {
pageInfo.$rawWatch = watch;
delete pageInfo.watch;
}

return pageInfo;
}

0 comments on commit 0a7cdd0

Please sign in to comment.