Skip to content

Commit

Permalink
fix: fix the execute order about autorun dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed Mar 7, 2018
1 parent 42e4f52 commit 8820866
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/decorator/autorun/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export default (opt = {}, target, property, description) => {
dispose = null
}

function wrapMethod(method, callback) {
function wrapMethod(method, callback, callbackPlacement = 'after') {
return function () {
// urlsync 在 autorun 后面执行
if (callbackPlacement === 'before') {
callback && callback.call(this)
return method && method.apply(this, arguments)
}

// autorun 在 urlsync 后面执行
const rlt = method && method.apply(this, arguments)
callback && callback.call(this)
Expand All @@ -30,7 +36,7 @@ export default (opt = {}, target, property, description) => {

target[exitKey] = wrapMethod(target[exitKey], function () {
release()
})
}, 'before')

target[initKey] = wrapMethod(target[initKey], function () {
if (dispose) {
Expand Down

0 comments on commit 8820866

Please sign in to comment.