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

Break buildURL into multiple requestType methods #2966

Merged
merged 1 commit into from
Apr 10, 2015

Conversation

jamiebuilds
Copy link
Contributor

This provides separate abstract methods that can be used for different request types with better signatures. It also passes the query in from findQuery.

I still need to write tests for this, but I'm putting it up before I go to sleep.

PS: @wycats I still want to be able to pass query to findAll but I wasn't able to find a good way of doing that.

@fivetanley
Copy link
Member

@bmac can you add this to the friday team discussion?

fivetanley added a commit that referenced this pull request Apr 10, 2015
Break buildURL into multiple requestType methods
@fivetanley fivetanley merged commit 1d17291 into emberjs:master Apr 10, 2015
@@ -391,7 +391,7 @@ export default Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findQuery: function(store, type, query) {
var url = this.buildURL(type.typeKey, null, null, 'findQuery');
var url = this.buildURL(type.typeKey, query, null, 'findQuery');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to the PR in question?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for passing query along to buildURL; I will find that useful!

I'm wondering, though, why is it passed as the id parameter and would it make more sense as the snapshot parameter? I know it's not really a snapshot, but it seems more like a snapshot than an id. Before this change, id is either null, a string, or an array of strings. With this change it can also be an object. snapshot on the other hand, is either null, an object, or an array of objects. Also, I think the query is used similarly as the snapshot (to fill arbitrary values in the url).

For reference, here is the signature of buildURL:

buildURL: function(type, id, snapshot, requestType) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a breaking change for anyone currently overriding buildURL that is expecting it to be an actual snapshot. And I would say that the breaking change should be adding a formal query argument so that the signature would be:

buildURL: function(type, id, query, snapshot, requestType) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok
I just thought I would check. I don't understand how putting the using query instead of null would break anything that using query instead of id would, but it sounds like you've thought about this more in depth than I have.

Anyway, I'm just happy to have the query available in buildURL at all. Thanks!

@jamiebuilds jamiebuilds deleted the url-for-methods branch April 10, 2015 17:18
jamiebuilds added a commit to jamiebuilds/data that referenced this pull request Apr 17, 2015
amiel pushed a commit to amiel/ember-data-url-templates that referenced this pull request Apr 19, 2015
In emberjs/data#2966 ember-data started passing the `query` from
`findQuery` to `buildURL` as the `id` parameter.
@wycats
Copy link
Member

wycats commented Apr 21, 2015

@thejameskyle does this satisfy your requirements or do you still need more stuff here?

@funtusov
Copy link
Contributor

I understand the benefits for when you want to override particular queries, but what is the reasoning for making the actual url construction (_buildURL) a private api?

Here's a usecase I had:
I was implementing nested models for the following api structure:
GET|POST|PUT /posts/:post_id/comments/...
by adding one line to buildUrl:

...
if (parentKey) { url.push(this.pathForParent(record, parentKey)); }``
...

To avoid using the private _buildURL, I only see adding the same custom code to 10 different methods?

@igorT
Copy link
Member

igorT commented May 25, 2015

Could you override buildUrl and call super?

@funtusov
Copy link
Contributor

My override inserts a segment somewhere in the middle of the generated url, so while theoretically it could be possible to insert the needed part within this._super() with some strings work, I imagine that code would be convoluted and brittle.

The new buildUrl branches to 10 different methods based on request type (urlForFind, urlForFindAll, urlForFindQuery), and each of those methods by default is a proxy to the (now private) _buildUrl – making it public (constructUrl?) would solve that.

@jamiebuilds
Copy link
Contributor Author

I don't see how that would improve anything. Calling super here should behave almost exactly the way it did previously for your case.

@funtusov
Copy link
Contributor

@thejameskyle are you referring to calling super in the new buildUrl method (that only dispatches the url construction to _buildUrl) or in the private _buildUrl (that does url construction)?

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.

8 participants