I recently noice in version 16.1.1 that when you remove an afterChange Hook callback, then is not possible to add it again using addHook(‘afterChange‘, callback).
It seems that once the callback is added to pluginHookBucket.getHooks(‘afterChange’), then the removeHook call sets skip flag to true but then addHookfails to set skip = false .
hot.addHook('afterChange', onAfterChange);
console.log(hot.pluginHookBucket.getHooks('afterChange')[1])
// Object { callback: onAfterChange(data),
// orderIndex: 0,
// runOnce: false,
// initialHook: false,
// skip: false }
hot.removeHook('afterChange', onAfterChange);
console.log(hot.pluginHookBucket.getHooks('afterChange')[1])
// Object { callback: onAfterChange(data),
// orderIndex: 0,
// runOnce: false,
// initialHook: false,
// skip: true }
hot.addHook('afterChange', onAfterChange);
console.log(hot.pluginHookBucket.getHooks('afterChange')[1])
// Object { callback: onAfterChange(data),
// orderIndex: 0,
// runOnce: false,
// initialHook: false,
// skip: true }
The issue is that can’t fire afterChange again. I came across this result while tracking down a failure with addHookOnce maybe it has the same issue.
Is it possible that addHooke doesn’t do anything if the object is already present tough it is flagged as skipped?
The issue is resolved if the skip flag is changed directly:
hot.pluginHookBucket.getHooks('afterChange')[1].skip=false