Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check invalid before names #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

check invalid before names #120

wants to merge 1 commit into from

Conversation

Cslove
Copy link

@Cslove Cslove commented Mar 14, 2020

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

@jsf-clabot
Copy link

jsf-clabot commented Mar 14, 2020

CLA assistant check
All committers have signed the CLA.

@Cslove Cslove force-pushed the master branch 2 times, most recently from 1fc11ec to 38f05aa Compare March 16, 2020 01:58
@Rulexec
Copy link

Rulexec commented Jan 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants