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

API changes for easier lazy loading #467

Closed
PaulUithol opened this issue Jun 3, 2014 · 4 comments
Closed

API changes for easier lazy loading #467

PaulUithol opened this issue Jun 3, 2014 · 4 comments

Comments

@PaulUithol
Copy link
Owner

@PaulUithol PaulUithol commented Jun 3, 2014

I'd like to make some API changes to accommodate more transparent lazy loading. There's more than one option here, so feedback would be appreciated.

What I'm planning to do:

  1. Change fetchRelated to only return a single promise, which resolves when all requests are done (or a single one fails..)
  2. Create a Model.lookup( attr ) method which acts like Model.get, but always return a promise which resolves with the attribute's value as its first argument. If the contents of the attribute/relation are found locally, it would resolve immediately; if not, it would resolve after the contents of the attribute/relation have been fetched.

Any thoughts about this?

@philfreo
Copy link
Collaborator

@philfreo philfreo commented Jun 3, 2014

I'd give it a more clear name than lookup to indicate that it's async. More ideas: Model#fetchAttr or Model#asyncGet

@PaulUithol
Copy link
Owner Author

@PaulUithol PaulUithol commented Jun 3, 2014

We could also overload Model.get; give it an extra fetch or async option/parameter. That would be pretty nice as well (at least, as long as Backbone itself doesn't add something similar-but-different).

Also: do we still need fetchRelated as a separate method?

@PaulUithol
Copy link
Owner Author

@PaulUithol PaulUithol commented Jun 4, 2014

After sleeping on it for a night, I'm definitely leaning towards a separate method; how's getAsync (like your suggestion, just a different word order)? A quick search seems to show more libs are using that convention.

I also think this function could straight up replace fetchRelated (maybe alias it for a while), now that we're messing with its signature anyway.

@philfreo
Copy link
Collaborator

@philfreo philfreo commented Jun 4, 2014

sounds good, +1 for not complicating Model#get

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.