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

Makes WrappedPromise an ES6 class #113

Merged
merged 1 commit into from
Jun 23, 2017
Merged

Makes WrappedPromise an ES6 class #113

merged 1 commit into from
Jun 23, 2017

Conversation

matthewloring
Copy link
Contributor

This allow for correct dispatch of method calls made on ES6 classes that
subclass promise.

Fixes: #112

@hayes
Copy link
Collaborator

hayes commented Jun 14, 2017

I don't think this will work as a valid solution because the file still needs to parse in old versions of node that do not support the class syntax. It should be possible to make subclassing work without using the class syntax

@hayes
Copy link
Collaborator

hayes commented Jun 14, 2017

It looks like subclassing promises without the class syntax may require assigning to .__proto__ which is not ideal, one possible solution would be to writ an es5 and es6 versions and determine the correct version to use at runtime

@matthewloring
Copy link
Contributor Author

@hayes If necessary this could be pulled to a different file that is conditionally required if running a version of node that supports classes. I think that would be an ugly approach and am definitely open to other options but am not aware of any other solutions.

@matthewloring
Copy link
Contributor Author

Oops, looks like there was a race in the last two comments. I can pull this into a separate file if that is the best way forward.

@hayes
Copy link
Collaborator

hayes commented Jun 14, 2017

I think that would be a good next step. I'll not sure what versions of node support promises but not class syntax, so that would be something worth checking out as well. I wont have time until later this week, but I could look into that if you want

@matthewloring
Copy link
Contributor Author

@hayes I've got things passing on everything but v7 and the failures there seem unrelated.

@watson
Copy link
Collaborator

watson commented Jun 15, 2017

Though I haven't looked at the CI error in detail, I wouldn't be surprised if the reason why this fails in 7 is because of this: nodejs/node#12861

@watson
Copy link
Collaborator

watson commented Jun 15, 2017

If everyone is ok with merging #117, then we can rebase this PR to check that the tests pass correctly.

}

return promise;
function wrappedExecutor(resolve, reject) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case we ever need to make a change to this function, I'd probably add a comment noting that this is a duplicate of the function in index.js. And I'd also make a similar comment by the function in index.js. Else they might deviate by a mistake at some point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I've added the comments.

@hayes
Copy link
Collaborator

hayes commented Jun 15, 2017

This looks great, I think it should pass CI once this is rebased on the changes @watson made to travis.yml
I think this should be good to merge, and I am really happy that using the es6 sub classing approach avoids having to assign the prototype on new promises on modern node, that should be a huge win.

I am going to leave this here for @othiym23 to merge since it is a more significant change than just testing/ci, and I don't have access to cut a new release anyways.

Thanks for working on this!

@hayes
Copy link
Collaborator

hayes commented Jun 15, 2017

I was mistaken, ci still won't pass due to an unrelated issue, but I think this change still looks good to me

try {
executor.apply(context, args);
} catch (err) {
args[1](err)

Choose a reason for hiding this comment

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

nit: missing semicolon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to keep naming and style the same as the ES3 counterpart. If we want to address general style issues there are a few other things I would want clean up too.

Copy link
Collaborator

@watson watson Jun 16, 2017

Choose a reason for hiding this comment

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

I'd say it's a mistake that there were no semicolon in the ES3 counterpart. We should probably fix that as well 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in both places.

return promise;
function wrappedExecutor(resolve, reject) {
context = this;
args = [wrappedAccept, wrappedReject];

Choose a reason for hiding this comment

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

nit: either rename resolve to accept or rename wrappedAccept to wrappedResolve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto

Copy link
Collaborator

Choose a reason for hiding this comment

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

An effort was made recently to rename all accept to resolve. A few places this was missed, but I made a PR to address this: #108

I didn't have commit access at the time, otherwise I could probably just have merged it my self as it's just naming. It have been sitting there for over a month now with no comments so I took the liberty to just merge it now. I hope that's ok 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've renamed this to wrappedResolve.

@watson
Copy link
Collaborator

watson commented Jun 16, 2017

@hayes It doesn't look like this have been rebased with the changes in master - could you please do that?

CI would normally have passed if it was rebased with master, but unfortunately #115 have just been merged, so now Node.js 8 will now start failing. So for now please ignore Node.js 8 errors 😅

@hayes
Copy link
Collaborator

hayes commented Jun 16, 2017

@watson not my PR (and the branch is not on this repo) so I can't rebase it myself, but just merged the fix for tests on node 8, so after a rebase we should have a green build.

@watson
Copy link
Collaborator

watson commented Jun 17, 2017

@hayes ah my bad 😄 But nice to know that we now have a stable CI build 👍

This allow for correct dispatch of method calls made on ES6 classes that
subclass promise.

Fixes: #112
@matthewloring
Copy link
Contributor Author

All rebased, looks like the CI is green (with the new allowed failures).

then(onSuccess, onReject) {
tap.type(onSuccess, 'function');
tap.type(onReject, 'undefined');
return Promise.prototype.then.call(this, onSuccess, onReject);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if it makes a difference in this case as I'm not that familiar with the new class syntax, but is there a difference between Promise.prototype.then.call() and super.then()? I haven't seen the two styles mixed like this before

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just checked out the branch to test it and the test passed using super as well 😃

I'm not sure if it's a big deal - if not, just leave it as is and feel free to merge on my account 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here they should be effectively the same. Using super you are guaranteed that your getting tge then you want, using this approach Promise, or Promise.prototype could be changed out from underneath you. In a test this shouldnt be an issue, but would be a bad idea if we were using this in our wrapping code

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the explanation 👍 I'm fine with just merging this then. We can always modify the style in master if we want

@matthewloring
Copy link
Contributor Author

What are the next steps to getting this landed/released?

@watson watson merged commit 6b17355 into othiym23:master Jun 23, 2017
@watson
Copy link
Collaborator

watson commented Jun 23, 2017

I just took the liberty to merge this as there didn't seem to be any objections (I hope that's ok with everybody 😅).

Next step is to cut a new version and publish. I do have the publish bit, so I can do it if nobody mind?

@watson
Copy link
Collaborator

watson commented Jun 23, 2017

After talking to @othiym23 I have now released this as v0.6.6 on npm 😅🎉

@matthewloring matthewloring deleted the promise branch June 23, 2017 11:29
@matthewloring
Copy link
Contributor Author

matthewloring commented Jun 23, 2017

Thanks! 😄

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

Successfully merging this pull request may close these issues.

4 participants