Skip to content

Commit

Permalink
fix(core): 🐛 hooks: context can not be undefined
Browse files Browse the repository at this point in the history
Closes #468
  • Loading branch information
thierrymichel committed Nov 19, 2019
1 parent 272a43f commit f6bb536
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/core/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ export class Hooks extends HookMethods {
this.registered.clear();
this.all.forEach(hook => {
if (!this[hook]) {
this[hook] = (fn: HookFunction, ctx: any = {}) => {
this[hook] = (fn: HookFunction, ctx?: any) => {
if (!this.registered.has(hook)) {
this.registered.set(hook, new Set());
}
const set = this.registered.get(hook);

set.add({
ctx,
ctx: ctx || {},
fn,
});
};
Expand All @@ -105,8 +105,6 @@ export class Hooks extends HookMethods {
let chain = Promise.resolve();

this.registered.get(name).forEach(hook => {
// If needed, bind the right context
// const fn = hook.ctx ? hook.fn.bind(hook.ctx) : hook.fn;
// Chain async hooks promisified
chain = chain.then(() => runAsync(hook.fn, hook.ctx)(...args));
});
Expand Down

0 comments on commit f6bb536

Please sign in to comment.