-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngResource): don't convert literal values into Resource objects when isArray is true #7741
Conversation
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314
You can overwrite the But I believe it would create bugs that are hard to track for our users ("an empty Resource instance that sometimes behave like a primitive and has no data on it 😯 ") : Maybe Resources can have hooks to handle non-object responses? +1 for the issue this PR tries to solve though :-) |
I don't think we can pretend Resource objects are primitives, since it wouldn't work when writing to them and stuff. It's probably adequate to just not convert them to Resources unless they're objects, since you probably aren't going to try to send off the primitives on their own. But, someone else can think about that |
We're using What if it the array is With this PR, the resulting array contains an empty Resource object. |
its not a breaking change, it is already empty/not copying anything in ( |
Currently if the response is: I just want to be sure that it's the behavior we want. Maybe we want it to result in: |
Not wrapping null into a resource instance sounds reasonable. We should add a test for it. Otherwise lgtm. |
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314 Closes angular#7741
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314 Closes angular#7741
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314 Closes angular#7741
Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value.
Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important.
In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. (@rodyhaddad can you think of a way to do this? You're the master of ES5 valueOf, as far as I know :P)
Closes #6314