getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Question about how the adapter builds URLs #109

Closed dsawardekar closed 10 years ago

dsawardekar commented 10 years ago

Hi,

I am working on a custom adapter for Epf. I have a question regarding how the RestAdapter builds URLs that are used to make the ajax calls. I see that the RestAdapter uses buildURL to build the url given to the this.ajax function.

My question is how does Epf construct the URL for a nested resource like /posts/1/comments. Say /posts has yielded a collection of posts and the comments aren't sideloaded or embedded. How does Epf go about building the URL for loading the comments for Post with id=1?

There is a url property on the RestAdapter that is prefixed to every call. But isn't this for setting a custom Domain alongside the namespace? I can't locate the code that prefixes the parent resource to the url. Can you please point me in the right direction?

Thanks.

ghempton commented 10 years ago

Currently, there is not a notion of child resources in terms of url structure. I think this is a totally valid use case and would like to support it soon. At the moment, however, epf would expect the parent post to serialize a list of comment ids which would be loaded via the top level /comment/ID

dsawardekar commented 10 years ago

Ok I see, so I must embed/sideload.

Can you clarify the sequence of calls Epf would send out in the following scenario?

Lets say you have a /posts which loads the top 10 posts. The call for this is made via session.query('post', ...). The post has comment_ids embedded.

Would Epf make a single call with multiple IDs or multiple calls for each comment_id? Also at what point would this call be triggered? At `post.get('comments') access, or is there a manual load call that I need to make in a route perhaps?

Thanks for your help.

ghempton commented 10 years ago

At the moment epf would make multiple calls for each comment_id. The way to optimize this is to use sideloading/embedding to pre-emptively load associations like that.

As far as when it its triggered: this will happen when any of the properties of the members of the association are observed.