tapable icon indicating copy to clipboard operation
tapable copied to clipboard

check invalid before names

Open Cslove opened this issue 5 years ago • 2 comments

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

Cslove avatar Mar 14 '20 04:03 Cslove

CLA assistant check
All committers have signed the CLA.

jsf-clabot avatar Mar 14 '20 04:03 jsf-clabot

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.

Rulexec avatar Jan 05 '22 11:01 Rulexec