-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
lib/manifest.js
Outdated
{ | ||
place: 'events', | ||
method: 'event', | ||
signature: ['events'], |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 | ||
}, |
There was a problem hiding this comment.
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 | ||
}, |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
.
place: 'event/definitions', | ||
method: 'event', | ||
list: true, | ||
useFilename: internals.passthruOn('name') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
andplace
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 signaturefunction(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.
There was a problem hiding this comment.
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.
@bmleight just a lil ping ;) Let me know if you'd like to sit down together some time. |
@bmleight just pingin to see if you're interested in continuing with this. |
Still need to write tests. Opening up for early feedback. For #13.