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

change portalDetail.request to return a jQuery promise #1163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

terencehonles
Copy link
Contributor

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.

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.
@nexushoratio
Copy link
Contributor

Why not a standard JS Promise instead?

@terencehonles
Copy link
Contributor Author

@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.

@terencehonles
Copy link
Contributor Author

@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.

@nexushoratio
Copy link
Contributor

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.

@terencehonles
Copy link
Contributor Author

/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 window.Promise in an arbitrary file I would be creating a hard to find(/what I meant by implicit) dependency.

I did check the code and it does seem that deferred is not being used, but the difference between that and window.Promise is that I know for sure that the dependency will be fulfilled because jQuery provides it (so it's not a new dependency).

@nexushoratio
Copy link
Contributor

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

@terencehonles
Copy link
Contributor Author

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 window.Promise being used you may re-write my code and propose that PR instead. I really don't care, the point is I made the decision based on the information I had and you still haven't given me a good reason to think otherwise.

Until any promise like solution is achieved I am currently pleasantly using window.activeRequests, but I do look forward to not having to use that work around.

@McBen
Copy link
Contributor

McBen commented Dec 30, 2016

let's get back to a basic question:
For what is it good for? What's the difference to the "portalDetailLoaded" hook?

@terencehonles
Copy link
Contributor Author

@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...
});

@dingram
Copy link
Contributor

dingram commented Jan 8, 2017

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.

@terencehonles
Copy link
Contributor Author

@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.

@pleasantone
Copy link
Contributor

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.

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.

5 participants