react-native-onyx 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +9 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -86,11 +86,18 @@ Onyx.merge(ONYXKEYS.POLICY, {employeeList: ['Jack']}); // -> {employeeList: ['Ja
86
86
 
87
87
  ### Should I use `merge()` or `set()` or both?
88
88
 
89
- - Use `merge()` if we want to merge partial data into an existing `Array` or `Object`
90
- - Use `set()` if we are working with simple values (`String`, `Boolean`, etc), need to completely overwrite a complex property of an `Object`, or reset some data entirely.
89
+ - Use `merge()` when creating a new object
90
+ - Use `merge()` to merge partial data into an existing object
91
+ - Use `merge()` when storing simple values (`String`, `Boolean`, `Number`)
92
+ - Use `set()` when you need to delete an Onyx key completely from storage
93
+ - Use `set()` when you need to completely reset an object or array of data
91
94
 
92
95
  Consecutive calls to `Onyx.merge()` with the same key are batched in a stack and processed in the order that they were called. This helps avoid race conditions where one merge possibly finishes before another. However, it's important to note that calls to `Onyx.set()` are not batched together with calls to `Onyx.merge()`. For this reason, it is usually preferable to use one or the other, but not both. Onyx is a work-in-progress so always test code to make sure assumptions are correct!
93
96
 
97
+ ### Should I store things as an array or an object?
98
+
99
+ You should avoid arrays as much as possible. They do not work well with `merge()` because it can't update a single element in an array, it must always set the entire array each time. This forces you to use `set()` a lot, and as seen above, `merge()` is more performant and better to use in almost any situation. If you are working with an array of objects, then you should be using an Onyx collection because it's optimized for working with arrays of objects.
100
+
94
101
  ## Subscribing to data changes
95
102
 
96
103
  To set up a basic subscription for a given key use the `Onyx.connect()` method.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",