Skip to content

Commit

Permalink
fix(cli): keep unregister function
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaufy committed Sep 3, 2019
1 parent c8b1b1e commit dafd8b2
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions packages/cli/core/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,9 @@ class Hook {
}
this._hooks[key].push(fn);

const createUnregister = function (key, fn) {
return function () {
let fns = this._hooks[key];
if (fns && typeof fn === 'function') {
fns = fns.filter(f => f !== fn);
if (fns.length > 0) {
this._hooks[key] = fns;
} else {
delete this._hooks[key];
}
}
};
};

return createUnregister(key, fn).bind(this);
return (() => {
this.unregister(key, fn);
});
}

hasHook (key) {
Expand Down Expand Up @@ -111,6 +99,18 @@ class Hook {
return (args.length <= 1 ? args[0] : args);
}

unregister (key, fn) {
let fns = this._hooks[key];
if (fns && typeof fn === 'function') {
fns = fns.filter(f => f !== fn);
if (fns.length > 0) {
this._hooks[key] = fns;
} else {
delete this._hooks[key];
}
}
}

unregisterAll (key) {
delete this._hooks[key];
}
Expand Down

0 comments on commit dafd8b2

Please sign in to comment.