Skip to content

Commit ea878e3

Browse files
committed
Update test to match new behavior for arrays and update readme
1 parent b3e801f commit ea878e3

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The data will then be cached and stored via [`AsyncStorage`](https://github.com/
6363

6464
We can also use `Onyx.merge()` to merge new `Object` or `Array` data in with existing data.
6565

66-
For `Array` the default behavior is to concatenate new items.
66+
For `Array` the default behavior is to concatenate replace it fully, effectively making it equivalent to set:
6767

6868
```javascript
6969
Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Joe']); // -> ['Joe']
@@ -77,7 +77,7 @@ Onyx.merge(ONYXKEYS.POLICY, {id: 1}); // -> {id: 1}
7777
Onyx.merge(ONYXKEYS.POLICY, {name: 'My Workspace'}); // -> {id: 1, name: 'My Workspace'}
7878
```
7979

80-
Arrays inside objects will NOT be concatenated and instead will be replaced fully:
80+
Arrays inside objects will NOT be concatenated and instead will be replaced fully, same as arrays not inside objects:
8181

8282
```javascript
8383
Onyx.merge(ONYXKEYS.POLICY, {employeeList: ['Joe', 'Jack']}); // -> {employeeList: ['Joe', 'Jack']}

tests/unit/onyxCacheTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ describe('Onyx', () => {
267267
mockKey: [{ID: 3}, {added: 'field'}, {}, {ID: 1000}],
268268
});
269269

270-
// THEN the arrays should be merged as expected
270+
// THEN the arrays should be replaced as expected
271271
expect(cache.getValue('mockKey')).toEqual([
272-
{ID: 3}, {ID: 2, added: 'field'}, {ID: 3}, {ID: 1000},
272+
{ID: 3}, {added: 'field'}, {}, {ID: 1000},
273273
]);
274274
});
275275

0 commit comments

Comments
 (0)