-
Notifications
You must be signed in to change notification settings - Fork 18
Conversation
I think it's great idea. We should definietly use es6-like solution. |
Should I branch here from |
Noes. I think it would be valuable to merge it into master asap. |
Current usages of var xhr = cm.ajax('ajax', {viewInfoList: options.view.getViewInfoList(), method: functionName, params: params}, {
success: function(response) {},
error: function(msg, type, isPublic) {},
complete: function() {}
}); with that var xhr = cm.ajax('ajax', {viewInfoList: options.view.getViewInfoList(), method: functionName, params: params}).then(success, error); Also you can see that there is no analog of |
I would leave usages as they are, and migrate them step by step when we refactor code anyway. Regarding |
Depends how much work you want to do now. |
There is no way to cancel es6-promise. The spec is not ready yet https://github.com/promises-aplus/cancellation-spec. We need cancellation for |
Hmm, this seems like a pretty specific use case. How about we handle it differently by allowing to pass in a closure argument to promise = cm.ajax(..., {
handleXhr: function(xhr) {
this.on('destruct', function() {
xhr.abort();
});
}
}); |
[deleted because of the privacy] |
On the other hand bluebird library takes some space. 50kb in minified mode. |
Sorry that I multiply the comments here |
I don't necessary agree that adding ajax-specific features to I would therefore prefer to keep the Promise interface simple and standard, and expose ajax-specific features through other ways. |
|
Actually I'm shocked by your position. |
There are 4 such places where we directly access underneath jqXHR. Do you plan to solve them by #1755? But how ? We still need to abort the current request. |
I agree, cancelation can be considered a generic Promise feature! Unfortunately there's no consensus yet of how it should be implemented :/ return new Promise(function (resolve, reject) {
xhr.send();
}).cancellable().catch(Promise.CancellationError, function(e) {
xhr.abort();
throw e; //Don't swallow it
}); There's also qajax, an ajax library on top of the Promise library Q. |
btw I just noticed |
Yes. Does that somehow affect your upper statements? |
Nope, jut a side note. So should we try with Bluebird? |
I'm afraid of it cause it takes 50kb >_< but we don't have too much choice according to this research http://complexitymaze.com/2014/03/03/javascript-promises-a-comparison-of-libraries/ There are only |
Yup, and |
I think it's ok to use bluebird with its functionality for the moment. |
@@ -172,8 +170,7 @@ var CM_Form_Abstract = CM_View_Abstract.extend({ | |||
} | |||
|
|||
if (_.size(errorList)) { | |||
deferred.reject(); | |||
|
|||
return Promise.resolve();//TODO is this replacement ok. It is not rejected but resolved with empty value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomaszdurka please check this TODO comment.
…nt and showComponent.
For a formality. @tomaszdurka please review. |
@@ -0,0 +1 @@ | |||
node tools/build.js --features "core cancel" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is reason for adding this file? I understand these are instructions for build tool to include cancel.
I thought that our client vendor manager is very limited and that for now we only put end-files into the repo.
Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.then(function(component) { | ||
component.popOut(); | ||
return component; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this distribution of the functionalities. Only thing we could change is naming of the methods.
showComponent
sounds like it should take an existing component as argument. What about displayComponent
or popOutComponent
? Although I need to check behaviour of popOut.
@tomaszdurka please review. |
Looks good now. I am still worried shouldn't we rather deal with cancelations in different way. E.g. with setting some flag on a Promise and then checking it's value within resolve. |
I'm afraid that the current mechanism does not allow this. Also if you get cancellation, you do not go to resolve clause => no point to wait in resolve cause resolve ain't going to be executed. |
Oh I meant to not cancel/reject as we do via bluebird, but instead set this flag to let's say |
But then you need to check for this flag in every resolve that is based on this promise? |
IMO they are equal .catch(function(err){if(err instanceOf Cancellation){...}}) .then(function(result){if(result.flag){...}}) |
Looks good! Let's release this today. One question, are we js-catching (non-promise) all the possible exceptions properly now? It would great to see (via js log) any kind of problems related with Promises once we release. |
CM_App.ajax: Return usable Promise
Currently
CM_App.ajax()
returns the original jqXHR "Deferred" object.It only rejects if the ajax request fails (e.g. network problem or non-200 response). But if we experience an expected application error (e.g. "auth required") it will resolve.
It would be great if
ajax()
would return a usable "Promise", that:success
callback)error
callback)We should also consider using ES6's Promise interface instead of jQuery's Promise: https://www.promisejs.org/#jquery
@vogdb @tomaszdurka thoughts?