Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat($resource): deep-merge custom actions with default actions. #14821

Closed

Conversation

gabrielmaldi
Copy link
Contributor

@gabrielmaldi gabrielmaldi commented Jun 24, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Feature.

What is the current behavior? (You can also link to an open issue here)

If you want to specify a timeout, transform, interceptor, or any other property for an action, you also have to include the other properties of the default action (method, isArray):

var Resource = $resource('/foo', {}, { save: { method: 'POST', timeout: 10000 }});

What is the new behavior (if this is a feature change)?

Perform a deep-merge between the provided custom actions and the default actions, so you can specify just the properties you want to add or override:

var Resource = $resource('/foo', {}, { save: { timeout: 10000 }});

Does this PR introduce a breaking change?

Theoretically yes, but should have no impact in practice.

Please check if the PR fulfills these requirements

@gabrielmaldi gabrielmaldi force-pushed the resource-merge-actions branch from 3e2bfd4 to 2c7440f Compare June 24, 2016 00:54
gabrielmaldi added a commit to gabrielmaldi/angular.js that referenced this pull request Jun 24, 2016
Previously, if you wanted to specify a timeout, transform, interceptor, or any
other property for an action, you also had to include the other properties of
the default action (method, isArray):

```
var Resource = $resource('/foo', {}, { save: { method: 'POST', timeout: 10000 }});
```

Now, a deep-merge between the provided custom actions and the default actions
will be performed, so you can specify just the properties you want to add or
override:

```
var Resource = $resource('/foo', {}, { save: { timeout: 10000 }});
```

Closes angular#14821
@gkalpak gkalpak modified the milestones: Backlog, Ice Box Jun 25, 2016
@gkalpak
Copy link
Member

gkalpak commented Jun 25, 2016

TBH, I am not a fan of this change. It would save a few characters for a few usecases and add a few characters for a few other usecases. But it would increase the complexity/reduce the declarativeness in all usecases: In order to know what some method of a $resource class/instance does, one would have to look up the default action methods (which might or might not be overriden).

I don't think that the few usecases that would benefit from this PR, justify the extra cost.

I will leave it open to see what others think.

@gabrielmaldi
Copy link
Contributor Author

I get your point. What I think is that most devs would expect actions to work this way, which is what happened to me: I didn't understand why setting a timeout on save would change it from POST to GET.

@Narretz
Copy link
Contributor

Narretz commented Jul 4, 2016

I'm kind of on the fence about this. It does make sense to expect that setting the options preserve the defaults, especially in cases like "save" where it is unlikely that the verb is changed. Then again, it doesn't seem to be a huge problem, as I've never seen this mentioned before.

@gabrielmaldi gabrielmaldi force-pushed the resource-merge-actions branch from 2c7440f to 8246c36 Compare July 4, 2016 16:44
gabrielmaldi added a commit to gabrielmaldi/angular.js that referenced this pull request Jul 4, 2016
Previously, if you wanted to specify a timeout, transform, interceptor, or any
other property for an action, you also had to include the other properties of
the default action (method, isArray):

```
var Resource = $resource('/foo', {}, { save: { method: 'POST', timeout: 10000 }});
```

Now, a deep-merge between the provided custom actions and the default actions
will be performed, so you can specify just the properties you want to add or
override:

```
var Resource = $resource('/foo', {}, { save: { timeout: 10000 }});
```

Closes angular#14821
Previously, if you wanted to specify a timeout, transform, interceptor, or any
other property for an action, you also had to include the other properties of
the default action (method, isArray):

```
var Resource = $resource('/foo', {}, { save: { method: 'POST', timeout: 10000 }});
```

Now, a deep-merge between the provided custom actions and the default actions
will be performed, so you can specify just the properties you want to add or
override:

```
var Resource = $resource('/foo', {}, { save: { timeout: 10000 }});
```

Closes angular#14821
@gabrielmaldi gabrielmaldi force-pushed the resource-merge-actions branch from 8246c36 to 32c35f1 Compare July 4, 2016 17:36
@gabrielmaldi
Copy link
Contributor Author

Also, if, for instance, you add a custom header to query, or specify a timeout, you'd lose isArray: true and would have to spend some time figuring out what happened. I agree that it's not a huge problem, but I think that this change may someday save someone some time.

@gkalpak
Copy link
Member

gkalpak commented Jul 5, 2016

I would not introduce a breaking change so that I "may someday save someone some time" 😛
(Espacially, since this would mean that I may someday cause someone else to lose some time.)

@Narretz Narretz closed this in 1660ddd Aug 3, 2016
@Narretz
Copy link
Contributor

Narretz commented Aug 3, 2016

I agree with @gkalpak that this might cause more problems than it solves. I've updated the documentation to clarify what happens when the custom action has the same key as the default action.

@gabrielmaldi gabrielmaldi deleted the resource-merge-actions branch August 28, 2016 09:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants