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

Comments

Projects
None yet
2 participants
@PaulUithol
Owner

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

This comment has been minimized.

Show comment
Hide comment
@philfreo

philfreo Jun 3, 2014

Collaborator

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

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@PaulUithol

PaulUithol Jun 3, 2014

Owner

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?

Owner

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

This comment has been minimized.

Show comment
Hide comment
@PaulUithol

PaulUithol Jun 4, 2014

Owner

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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@philfreo

philfreo Jun 4, 2014

Collaborator

sounds good, +1 for not complicating Model#get

Collaborator

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