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

Core: Implement event emitter #1087

Merged
merged 5 commits into from
Jan 6, 2017
Merged

Conversation

trentmwillis
Copy link
Member

Do NOT merge until after 2.1.1 is released.

This implements a simple event emitter interface that will eventually supersede the current logging callbacks. No tests are added here since the emit function is private in scope and not currently wired up internally. One goal here is to avoid a giant PR that both implement the event emitter and wires it up to all possible events.

A follow-up commit to this will use the API implemented here to emit data according to the js-reporters standard.

Copy link
Contributor

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

Left one comment where I wasn't sure about a line.

My only other question is this: Is there any way we can use an existing event emitter? I know QUnit doesn't like to have hard dependencies, but could Rollup be configured to bundle in certain dependencies and then we wouldn't have to roll our own EventEmitter?

@@ -60,7 +60,7 @@ export default ( function() {
parse: function( obj, objType, stack ) {
stack = stack || [];
var res, parser, parserType,
inStack = inArray( obj, stack );
inStack = stack.indexOf( obj );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this say stack.indexOf( obj ) !== -1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, we need the actual index value later. Renamed this variable to make it clearer as to what is going on.

@trentmwillis
Copy link
Member Author

Is there any way we can use an existing event emitter? I know QUnit doesn't like to have hard dependencies, but could Rollup be configured to bundle in certain dependencies and then we wouldn't have to roll our own EventEmitter?

I thought about this, but we don't need a super robust eventing system and we would still likely need to wrap the library in some of our own logic to verify usage according to what we expect. Therefore, since the actual code is only like 30 lines, I figured we should just maintain it ourselves. Seem good?

Copy link
Contributor

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

Just one suggestion on improving readability, otherwise LGTM.

if ( inStack !== -1 ) {
return "recursion(" + ( inStack - stack.length ) + ")";
if ( objIndex !== -1 ) {
return "recursion(" + ( objIndex - stack.length ) + ")";
Copy link
Contributor

Choose a reason for hiding this comment

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

This would probably work better as a template literal, since you're using them elsewhere in this PR.

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 point! Will update.

@trentmwillis
Copy link
Member Author

Updated. Thanks for the review.

@trentmwillis
Copy link
Member Author

@platinumazure does this look good to you now?

@leobalter any update about releasing 2.1.1?

Copy link
Contributor

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Sorry for losing track of this.

}

return -1;
return array.indexOf( elem ) !== -1;
Copy link
Member

Choose a reason for hiding this comment

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

in a close future, hopefully, we'll be able to use [].includes.


// Clone the callbacks in case one of them registers a new callback
let originalCallbacks = LISTENERS[ eventName ];
let callbacks = originalCallbacks ? [ ...originalCallbacks ] : [];
Copy link
Member

Choose a reason for hiding this comment

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

nice!

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't improve readability, but I was playing with the syntax: [ ...(originalCallbacks || []) ].

I still prefer your code. 👍

@leobalter
Copy link
Member

LGTM

@leobalter leobalter merged commit f48072e into qunitjs:master Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants