-
Notifications
You must be signed in to change notification settings - Fork 552
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
change portalDetail.request to return a jQuery promise #1163
base: master
Are you sure you want to change the base?
change portalDetail.request to return a jQuery promise #1163
Conversation
portalDetail.request returns a jQuery promise which if the request is successful resolves to the value which would be returned by portalDetail.get otherwise the promise is rejected.
Why not a standard JS Promise instead? |
@nexushoratio because iitc is centered around jQuery - I didn't want to add a different dependency and I didn't check if JS Promises are used elsewhere. |
@nexushoratio I just checked and they're not, so it's safer to use jQuery.Deferred rather than add an implicit dependency. Originally it was because I would be returning ajax().promise(), but since I was making the change I figured it would be better to handle the RETRY scenario and return a separate promise. |
Using a built in feature of the language is not an implicit dependency. Neither of jquery's promise or deferred is currently used in the code base either. |
/respectfully: I'm not sure how long you have been doing software engineering, but it is indeed creating a dependency. Promises are only a language feature for certain versions of JavaScript. I am personally not sure which versions iitc is targeting and by using I did check the code and it does seem that deferred is not being used, but the difference between that and |
Likely longer than you've been alive. JS Promises have been out for a while now. All of the major browsers, desktop and mobile, except for IE, support it. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility |
Unless you're the owner/maintainer of the project (and you haven't said that yet) you haven't given me a concrete reason why your opinion is more correct than mine. A decision like this should not be just made by a couple of contributors. Unless you want to point me to a document that describes what browsers iitc is targeting or bring in another contributor I have no reason to change the code as proposed. If you would rather see Until any promise like solution is achieved I am currently pleasantly using |
let's get back to a basic question: |
@McBen personally I need the value for multiple portals. $.when(
portalDetail.request(guid1),
portalDetail.request(guid2),
...portalDetail.request(guidN)).then(function(p1, p2, ...pN) { ...do work... }) is much easier to express/more elegant than: portalDetail.request(guid1);
portalDetail.request(guid2);
...
portalDetail.request(guidN);
addHook('portalDetailLoaded', function(...) {
if (...not all loaded...) return;
...do work...
}); |
My concern is that this would introduce some inconsistency to the IITC API. Why should just one call use promises, instead of all of them? Perhaps an alternative way to do this would be to provide a plugin that provides a promise-based wrapper around IITC's existing API. That would also avoid the issue of which style of promises to use: two libraries could be written, one for jQuery and another for native ES6. My feeling is that promises may otherwise have to wait until the IITC core gets rewritten. |
@dingram do you know the time frame or progress for a potential IITC core re-write? I agree it may be inconsistent, but it would be nice if we document and move towards providing promises instead of solely on hooks. I do prefer ES6 promises, but until we have some sort of roadmap we're just kinda floating around. |
I like @dingrams idea of a hook wrapper so you get your promise support before a core rewrite and we get an API for all hooks, not just one. Would you care to submit a PR that covers all hooks? It's more likely to be accepted than this one. |
portalDetail.request returns a jQuery promise which if the request is
successful resolves to the value which would be returned by
portalDetail.get otherwise the promise is rejected.