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

Unclear requirement for add-eventing #4

Open
FarisMarouane opened this issue May 15, 2018 · 2 comments
Open

Unclear requirement for add-eventing #4

FarisMarouane opened this issue May 15, 2018 · 2 comments

Comments

@FarisMarouane
Copy link

I didn't understand this requirement; "if obj.trigger is called with additional arguments it should pass those to the listeners". Could you please provide an example of what is expected?

@indiesquidge
Copy link
Owner

indiesquidge commented Jul 23, 2018

Hi @FarisMarouane. Great question! The crux of what that part of the challenge is asking for is that if an event type is called with trigger, any extra arguments after the event name should be passed as arguments to the event listener that is invoked.

Here's an example adapted from that challenge's test file.

const obj = addEventing({
  foo: 'bar'
})

const eventHandler = (arg1, arg2) => {
  console.log('FIRST ARG:', arg1)
  console.log('SECOND ARG:', arg2)
}

obj.on('event', eventHandler)

// invoke `event` and pass it `arg1` and `arg2` as arguments
obj.trigger('event', 'Hello world', 42) // logs "FIRST ARG: 'Hello world'" and "SECOND ARG: 42"

However, we want to write our trigger() method to take any number of arguments, each of which should be forwarded on as arguments to the listeners when an event is triggered.

Does that explanation help? Please feel free to ask for more clarification, I'd be happy to provide it :)

@FarisMarouane
Copy link
Author

Thank you @indiesquidge , it was very clear.

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

No branches or pull requests

2 participants