tapable
tapable copied to clipboard
check invalid before names
const { SyncHook } = require('./lib')
const car = new SyncHook()
const calls = []
car.tap('1', () => calls.push(1))
car.tap('2', () => calls.push(2))
car.tap('3', () => calls.push(3))
car.tap({
before: ['3', '5'],
name: '4'
}, () => calls.push(4))
car.call()
console.log(calls) // unexpected print [4, 1, 2, 3]
when pass invalid before names, should throw error
I think this should not throw exceptions, because 5 can be added later. For such case there maybe should be field like require: string | string[], which will throw exception at call-time if there is no taps with the specified name (although you can check it yourself inside of tap callback via looking inside car.taps). At least this will not break backward compatibility.
I have issue #168, where I have code like this:
const car = new SyncHook()
const calls = []
car.tap('1', () => calls.push(1))
car.tap({
before: '4',
name: '2',
}, () => calls.push(2))
car.tap('3', () => calls.push(3))
car.tap({
before: ['3', '5'],
name: '4'
}, () => calls.push(4))
car.call()
console.log(calls) // unexpected print [4, 2, 1, 3]
Where order is really broken (2 should be before 4). [4, 1, 2, 3] looks valid for me, 4 is before 3 and there is no constraints violated.