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

added event and event listeners to manifest, start of tests #24

Closed
wants to merge 2 commits into from

Conversation

bmleight
Copy link
Member

Still need to write tests. Opening up for early feedback. For #13.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling a81c6dd on bmleight:hapi-server-events into 639b1bb on devinivy:master.

lib/manifest.js Outdated
{
place: 'events',
method: 'event',
signature: ['events'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can nix the signature for this one. By default haute will pass the contents of a file as the first argument. In this case it might be the difference between { events: { name: 'my-event' } } and { name: 'my-event' }. The latter is cleaner, as we can get away with it in this case.

lib/manifest.js Outdated
list: true
},
{
place: 'event-listeners',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks good! Only question is if we want all events stuff under a single directory, kinda like we do with auth. For example, we could choose to use something like events/listeners and events/definitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good call. Typing event-listeners didn't feel right.

lib/manifest.js Outdated
method: 'on',
signature: ['criteria', 'listener'],
list: true
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to get fancy, both of these can useFilename to hint at the event name being referenced.

lib/manifest.js Outdated
method: 'on',
signature: ['criteria', 'listener'],
list: true
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event-listeners should have after: ['events'] (or whatever we rename them). If the calls were to happen out of order, hapi would complain: srv.on('my-event', listener); srv.event('my-event');.

API.md Outdated
#### Events
> [`server.event(events)`](https://github.com/hapijs/hapi/blob/master/API.md#servereventevents)

- **`events/index.js`** - export an array of objects.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also allows events.js.

API.md Outdated
#### Event Listeners
> [`server.on(criteria, listener)`](https://github.com/hapijs/hapi/blob/master/API.md#serveroncriteria-listener)

- **`event-listeners/index.js`** - export an array of objects.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also allows event-listeners.js.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling a6f3fe5 on bmleight:hapi-server-events into 639b1bb on devinivy:master.

place: 'event/definitions',
method: 'event',
list: true,
useFilename: internals.passthruOn('name')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devinivy I wondered if I should utilize useFilename in my first commit, but didn't really understand what its doing, or what benefit this brings. Still don't, copied this from cookies -- seemed right. Can you shed some light on it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! In the docs I wrote,

when list is true and place is a directory without an index file, then this option allows one to use the name of the each file within place to modify its contents. Should be a function with signature function(filename, value) that receives the file's filename (without file extension) and its contents at value, returning a new value to be used as arguments for hapi plugin API call.

Imagine event/listeners, where calls are made server.on(criteria, listener). One particular way to make those calls is to put files exporting { criteria, listener } in the folder event/listeners/, e.g. event/listeners/my-event.js. If you want to make haute-couture smart enough to use my-event as part of criteria, then you can write a function useFilename() that receives the file's contents ({ criteria, listener }) and the filename (my-event) and returns the new contents. In that case we'd want useFilename to handle two cases– one, when criteria is missing, and two, when criteria is an object without a name property. In the former case internals.passthruOn('criteria') would be enough, but we'll have to add some additional logic to handle the latter case.

That kinda make sense? I haven't been awake very long.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. this one for event/definitions is good, but needs to handle the case that an array is exported. See the routes one as an example.

@devinivy
Copy link
Member

@bmleight just a lil ping ;) Let me know if you'd like to sit down together some time.

@devinivy
Copy link
Member

@bmleight just pingin to see if you're interested in continuing with this.

@devinivy devinivy self-assigned this Jun 11, 2018
@devinivy
Copy link
Member

No offense @bmleight, but closing this for now :) This is a great reference for anyone looking to pick-up where @bmleight left off! Might be worth branching from here.

@devinivy devinivy closed this Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants