react-native-onyx 3.0.15 → 3.0.17
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.
- package/API.md +1 -1
- package/dist/useLiveRef.d.ts +3 -0
- package/dist/useLiveRef.js +3 -0
- package/dist/useOnyx.js +6 -6
- package/package.json +1 -1
package/API.md
CHANGED
|
@@ -177,7 +177,7 @@ applied in the order they were called. Note: `Onyx.set()` calls do not work this
|
|
|
177
177
|
**Example**
|
|
178
178
|
```js
|
|
179
179
|
Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Joe']); // -> ['Joe']
|
|
180
|
-
Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Jack']); // -> ['
|
|
180
|
+
Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Jack']); // -> ['Jack']
|
|
181
181
|
Onyx.merge(ONYXKEYS.POLICY, {id: 1}); // -> {id: 1}
|
|
182
182
|
Onyx.merge(ONYXKEYS.POLICY, {name: 'My Workspace'}); // -> {id: 1, name: 'My Workspace'}
|
|
183
183
|
```
|
package/dist/useLiveRef.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates a mutable reference to a value, useful when you need to
|
|
3
3
|
* maintain a reference to a value that may change over time without triggering re-renders.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated This hook breaks the Rules of React, and should not be used.
|
|
6
|
+
* The migration effort to remove it safely is not currently planned.
|
|
4
7
|
*/
|
|
5
8
|
declare function useLiveRef<T>(value: T): import("react").MutableRefObject<T>;
|
|
6
9
|
export default useLiveRef;
|
package/dist/useLiveRef.js
CHANGED
|
@@ -4,6 +4,9 @@ const react_1 = require("react");
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a mutable reference to a value, useful when you need to
|
|
6
6
|
* maintain a reference to a value that may change over time without triggering re-renders.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated This hook breaks the Rules of React, and should not be used.
|
|
9
|
+
* The migration effort to remove it safely is not currently planned.
|
|
7
10
|
*/
|
|
8
11
|
function useLiveRef(value) {
|
|
9
12
|
const ref = (0, react_1.useRef)(value);
|
package/dist/useOnyx.js
CHANGED
|
@@ -51,24 +51,24 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
51
51
|
const connectionRef = (0, react_1.useRef)(null);
|
|
52
52
|
const previousKey = (0, usePrevious_1.default)(key);
|
|
53
53
|
const currentDependenciesRef = (0, useLiveRef_1.default)(dependencies);
|
|
54
|
-
const
|
|
54
|
+
const selector = options === null || options === void 0 ? void 0 : options.selector;
|
|
55
55
|
// Create memoized version of selector for performance
|
|
56
56
|
const memoizedSelector = (0, react_1.useMemo)(() => {
|
|
57
|
-
if (!
|
|
57
|
+
if (!selector) {
|
|
58
58
|
return null;
|
|
59
|
+
}
|
|
59
60
|
let lastInput;
|
|
60
61
|
let lastOutput;
|
|
61
62
|
let lastDependencies = [];
|
|
62
63
|
let hasComputed = false;
|
|
63
64
|
return (input) => {
|
|
64
65
|
const currentDependencies = currentDependenciesRef.current;
|
|
65
|
-
const currentSelector = currentSelectorRef.current;
|
|
66
66
|
// Recompute if input changed, dependencies changed, or first time
|
|
67
67
|
const dependenciesChanged = !(0, fast_equals_1.shallowEqual)(lastDependencies, currentDependencies);
|
|
68
68
|
if (!hasComputed || lastInput !== input || dependenciesChanged) {
|
|
69
69
|
// Only proceed if we have a valid selector
|
|
70
|
-
if (
|
|
71
|
-
const newOutput =
|
|
70
|
+
if (selector) {
|
|
71
|
+
const newOutput = selector(input);
|
|
72
72
|
// Deep equality mode: only update if output actually changed
|
|
73
73
|
if (!hasComputed || !(0, fast_equals_1.deepEqual)(lastOutput, newOutput) || dependenciesChanged) {
|
|
74
74
|
lastInput = input;
|
|
@@ -80,7 +80,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
80
80
|
}
|
|
81
81
|
return lastOutput;
|
|
82
82
|
};
|
|
83
|
-
}, [currentDependenciesRef,
|
|
83
|
+
}, [currentDependenciesRef, selector]);
|
|
84
84
|
// Stores the previous cached value as it's necessary to compare with the new value in `getSnapshot()`.
|
|
85
85
|
// We initialize it to `null` to simulate that we don't have any value from cache yet.
|
|
86
86
|
const previousValueRef = (0, react_1.useRef)(null);
|