You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default behavior of Oynx.merge is a deep merge which will object keys and array elements. This is fine but for some scenarios, we want to overwrite the object entirely while.
For example, to merge this data
{
A: {email: '[email protected]', description: 'this is a description'}
}
into this existing onyx key
{
A: {email: '[email protected]', description: '', test: 'test', stuff: 'stuff'}
B: {email: '[email protected]', description: 'this is a description'}
otherKey: bla
...
}
Instead of getting a new value of A: {email: '[email protected]', description: 'this is a description', test: 'test', stuff: 'stuff'}
we want to get this saved in the onyx key
{
A: {email: '[email protected]', description: 'this is a description'}
B: {email: '[email protected]', description: 'this is a description'}
otherKey: bla
...
}
Solution
Create an option for shallow merging which will merge the values but will overwrite objects
Also could look into doing something like Onyx.removeProperty('keyName', ['A'])
Workarounds
Right now, the workaround is to first merge the key with null, and then do another merge with the new object as the Onyx.merge calls are batched and should
Since otherwise a typical deep merge would give us {errors: {someError: true, someOtherError: true}}
Shallow merge could work, but I think the most flexible one is to add a callback to Onyx.set(). This also would solve the issue where array values do not get concatenated in a deep merge. But the current workaround for that has us relying on local data e.g. here in Policy.js.
Problem
The default behavior of Oynx.merge is a deep merge which will object keys and array elements. This is fine but for some scenarios, we want to overwrite the object entirely while.
For example, to merge this data
into this existing onyx key
Instead of getting a new value of
A: {email: '[email protected]', description: 'this is a description', test: 'test', stuff: 'stuff'}
we want to get this saved in the onyx key
Solution
Create an option for shallow merging which will merge the values but will overwrite objects
Also could look into doing something like
Onyx.removeProperty('keyName', ['A'])
Workarounds
Right now, the workaround is to first merge the key with
null
, and then do another merge with the new object as the Onyx.merge calls are batched and shouldcc @marcaaron
The text was updated successfully, but these errors were encountered: