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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ Here's the complete rundown of how files and directories are mapped to API calls
- **`cookies/index.js`** - export an array of objects.
- **`cookies/cookie-name.js`** - export an object. The `name` will be assigned `'cookie-name'` from the filename if it isn't already specified.

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

- **`event/definitions.js`** - export an array of objects `{ name, options }`.
- **`event/definitions/index.js`** - export an array of objects.
- **`event/definitions/event-name.js`** - export `event` object.

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

- **`event/listeners.js`** - export an array of objects `{ name, options }`.
- **`event/listeners/index.js`** - export an array of objects.
- **`event/listeners/listener-name.js`** - export `listener` object.

#### Model definitions (for [schwifty](https://github.com/BigRoomStudios/schwifty))
> [`server.schwifty(config)`](https://github.com/BigRoomStudios/schwifty/blob/master/API.md#serverschwiftyconfig)

Expand Down
14 changes: 14 additions & 0 deletions lib/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ internals.manifest = [
list: true,
useFilename: internals.passthruOn('name')
},
{
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.

},
{
place: 'event/listeners',
method: 'on',
signature: ['criteria', 'listener'],
list: true,
useFilename: internals.passthruOn('name'),
after: ['event/definitions']
},
{ // Schwifty models
place: 'models',
method: 'schwifty',
Expand Down
5 changes: 5 additions & 0 deletions test/closet/event/definitions/test-definition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
name: 'test-event'
}
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,16 @@ describe('HauteCouture', () => {
done();
});

it('defines event definitions in event/definitions/.', (done) => {

done();
});

it('defines event listeners in event/listeners/.', (done) => {

done();
});

it('defines schwifty models in models/.', (done) => {

const models = bigServer.models(true);
Expand Down