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 promise returns to Plotly.plot #226

Merged
merged 5 commits into from Feb 1, 2016
Merged

Added promise returns to Plotly.plot #226

merged 5 commits into from Feb 1, 2016

Conversation

tchandler
Copy link

Added promise rejections missed in #77 meant to resolve part of #76

All tests pass.

@etpinard
Copy link
Contributor

@tchandler This looks good. Thank very much for doing this 🍻

We should add to test cases in https://github.com/plotly/plotly.js/blob/master/test/jasmine/tests/plot_promise_test.js before merging.

I hope that you'll be up for the challenge 😏

But, if you don't feel like it (which totally understandable), me or @mdtusz will gladly add the test cases for you. Cheers.

@tchandler
Copy link
Author

@etpinard I'm working through the unit tests and I noticed something, in #77 the Promise returns that were added are implemented like this:

new Promise.resolve(gd);
//or
new Promise.reject();

But you can't use new to construct immediate resolved/rejected promises, it throws a TypeError:

> new Promise.reject()
TypeError: function reject() { [native code] } is not a constructor
    at repl:1:1
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:95:20)
    at REPLServer.emit (events.js:182:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
    at REPLServer.Interface._ttyWrite (readline.js:827:14)

I suspect the reason this doesn't break in production is because either the build fixes the error or the polyfill for Promises is implemented as a JS constructor function, which works just fine with that syntax:

> Promise = function() {}
[Function]
> Promise.resolve = function() {}
[Function]
> new Promise()
{}
> new Promise.resolve()
{}

I should have another commit for this in an hour or 2 that fixes my and the other uses of new Promise.reject/resolve and includes some unit tests to verify.

@mdtusz
Copy link
Contributor

mdtusz commented Jan 29, 2016

Good catch! Those were meant to be fixed in a PR that's been put on the backburner https://github.com/plotly/plotly.js/pull/149/files#diff-2941ab69a12080c0633ff4ac8ea3aa83R1654

We'll review what you've got once you've pushed up the next changes!

@mdtusz
Copy link
Contributor

mdtusz commented Feb 1, 2016

Changes and tests look good to me so I'll merge it in.

Thanks for the contribution!

💃

mdtusz added a commit that referenced this pull request Feb 1, 2016
@mdtusz mdtusz merged commit 9a585e2 into plotly:master Feb 1, 2016
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.

None yet

3 participants