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
There are 2 ways to merge a specific item that belongs to a collection:
Calling Onyx.merge() directly;
Calling Onyx.mergeCollection() for the collection holding this item.
These 2 operations must be interchangeable, meaning the same result should be obtained by calling either operation.
However, they handle a deeply nested null differently: merge removes the value completely, while mergeCollection sets the value to null and returns it to the subscriber.
Here's the Unit test for the same operation called via merge and mergeCollection:
Expand for code
describe('merge',()=>{it('should remove a deeply nested null when merging an existing key',()=>{letresult;constroutineRoute=`${ONYX_KEYS.COLLECTION.ROUTES}routine`;connectionID=Onyx.connect({key: routineRoute,initWithStoredValues: false,callback: (value)=>result=value,});constinitialValue={waypoints: {1: 'Home',2: 'Work',3: 'Gym',},};returnOnyx.set(routineRoute,initialValue).then(()=>{expect(result).toEqual(initialValue);Onyx.merge(routineRoute,{waypoints: {1: 'Home',2: 'Work',3: null,},});returnwaitForPromisesToResolve();}).then(()=>{expect(result).toEqual({waypoints: {1: 'Home',2: 'Work',}});});});});describe('mergeCollection',()=>{it('should remove a deeply nested null when merging an existing collection item',()=>{letresult;constroutineRoute=`${ONYX_KEYS.COLLECTION.ROUTES}routine`;connectionID=Onyx.connect({key: ONYX_KEYS.COLLECTION.ROUTES,initWithStoredValues: false,waitForCollectionCallback: true,callback: (value)=>result=value,});constinitialValue={waypoints: {1: 'Home',2: 'Work',3: 'Gym',},};returnOnyx.set(routineRoute,initialValue).then(()=>{expect(result).toEqual({[routineRoute]: initialValue});Onyx.mergeCollection(ONYX_KEYS.COLLECTION.ROUTES,{[routineRoute]: {waypoints: {1: 'Home',2: 'Work',3: null,},}});returnwaitForPromisesToResolve();}).then(()=>{expect(result).toEqual({[routineRoute]: {waypoints: {1: 'Home',2: 'Work',},},});});});});
There are 2 ways to merge a specific item that belongs to a collection:
Onyx.merge()
directly;Onyx.mergeCollection()
for the collection holding this item.These 2 operations must be interchangeable, meaning the same result should be obtained by calling either operation.
However, they handle a deeply nested null differently:
merge
removes the value completely, whilemergeCollection
sets the value tonull
and returns it to the subscriber.Here's the Unit test for the same operation called via
merge
andmergeCollection
:Expand for code
https://github.com/paultsimura/react-native-onyx/blob/8c0f4f2e38e76e7b4193b525869ab32a92c6c4ee/tests/unit/onyxTest.js#L1049-L1137
The
merge
test passes, while themergeCollection
test fails because the actual result is:The text was updated successfully, but these errors were encountered: