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

feat(defineDriver): set up custom drivers syncronously if there's no _support property or it's not a function #692

Merged
merged 2 commits into from
May 2, 2017

Conversation

gabrielmaldi
Copy link
Contributor

This addresses #686 according to #686 (comment).

gabrielmaldi pushed a commit to gabrielmaldi/localForage that referenced this pull request May 2, 2017
gabrielmaldi pushed a commit to gabrielmaldi/localForage that referenced this pull request May 2, 2017
gabrielmaldi pushed a commit to gabrielmaldi/localForage that referenced this pull request May 2, 2017
gabrielmaldi added a commit to gabrielmaldi/localForage that referenced this pull request May 2, 2017
@@ -343,7 +343,7 @@ if (typeof global.Promise !== 'function') {
},{"2":2}],4:[function(_dereq_,module,exports){
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
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 don't know why this line is changing. Should this be part of the commit?

Copy link
Member

Choose a reason for hiding this comment

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

If you just did a fresh npm install then don't worry about it.
It would be great if the dist files were in a different commit, but it's not mandatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's it. I separated the code into two commits 👍

@thgreasi
Copy link
Member

thgreasi commented May 2, 2017

I think that the code should be moved outside the new Promise(function(){...}), since according to the spec you can't bet that the constructor function runs synchronously.

@gabrielmaldi
Copy link
Contributor Author

I think it's guaranteed that the constructor will run immediately:

From MDN (emphasis mine):

new Promise( /* executor */ function(resolve, reject) { ... } );
executor
A function that is passed with the arguments resolve and reject. The executor function is executed immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise constructor even returns the created object). The resolve and reject functions, when called, resolve or reject the promise, respectively. The executor normally initiates some asynchronous work, and then, once that completes, either calls the resolve function to resolve the promise or else rejects it if an error occurred.
If an error is thrown in the executor function, the promise is rejected. The return value of the executor is ignored.

From promisejs.org (emphasis also mine):

We use new Promise to construct the promise. We give the constructor a factory function which does the actual work. This function is called immediately with two arguments. The first argument fulfills the promise and the second argument rejects the promise. Once the operation has completed, we call the appropriate function.

However, if you still feel it's safer to move the code outside the constructor, I'll make the change.

@thgreasi
Copy link
Member

thgreasi commented May 2, 2017

My bad 😞
It seems I was a bit confused with an other part of the Promises spec.
If the current code works for you then I;m fine with it.
It would be great to have a test case as well, but if it troubles you then I can give it a try during the weekend,
Kudos for the PR.

@thgreasi
Copy link
Member

thgreasi commented May 2, 2017

Thanks for this!!

@gabrielmaldi gabrielmaldi deleted the define-driver-sync branch May 2, 2017 18:49
@gabrielmaldi
Copy link
Contributor Author

Thanks for the tests, I had taken a look and was planning on doing something very similar to what you did. 👍

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

2 participants