@legendapp/state 3.0.0-beta.47 → 3.0.0-beta.48

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/README.md CHANGED
@@ -67,7 +67,8 @@ function FineGrained() {
67
67
 
68
68
  ### 4. 💾 Powerful sync and persistence
69
69
 
70
- Legend-State includes a powerful [sync and persistence system](../../usage/persist-sync). It easily enables local-first apps by optimistically applying all changes locally first, retrying changes even after restart until they eventually sync, and syncing minimal diffs. We use Legend-State as the sync systems in [Legend](https://legendapp.com) and [Bravely](https://bravely.io), so it is by necessity very full featured while being simple to set up.
70
+ Legend-State includes a powerful [sync and persistence system](https://www.legendapp.com/open-source/state/v3/usage/persist-sync/)
71
+ . It easily enables local-first apps by optimistically applying all changes locally first, retrying changes even after restart until they eventually sync, and syncing minimal diffs. We use Legend-State as the sync systems in [Legend](https://legendapp.com) and [Bravely](https://bravely.io), so it is by necessity very full featured while being simple to set up.
71
72
 
72
73
  Local persistence plugins for the browser and React Native are included, with sync plugins for [Keel](https://www.keel.so), [Supabase](https://www.supabase.com), [TanStack Query](https://tanstack.com/query), and `fetch`.
73
74
 
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var react$1 = require('react');
4
3
  var react = require('@legendapp/state/react');
5
4
  var reactNative = require('react-native');
6
5
 
@@ -39,9 +38,8 @@ function enableReactNativeComponents() {
39
38
  FlatList: {
40
39
  data: {
41
40
  selector: (propsOut, p) => {
42
- const state = react$1.useRef(0);
43
- const [renderNum, value] = react.useSelector(() => [state.current++, p.get(true)]);
44
- propsOut.extraData = renderNum;
41
+ const value = p.get(true);
42
+ propsOut.extraData = {};
45
43
  return value;
46
44
  }
47
45
  }
@@ -1,5 +1,4 @@
1
- import { useRef } from 'react';
2
- import { configureReactive, useSelector } from '@legendapp/state/react';
1
+ import { configureReactive } from '@legendapp/state/react';
3
2
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
3
 
5
4
  // src/config/enableReactNativeComponents.ts
@@ -37,9 +36,8 @@ function enableReactNativeComponents() {
37
36
  FlatList: {
38
37
  data: {
39
38
  selector: (propsOut, p) => {
40
- const state = useRef(0);
41
- const [renderNum, value] = useSelector(() => [state.current++, p.get(true)]);
42
- propsOut.extraData = renderNum;
39
+ const value = p.get(true);
40
+ propsOut.extraData = {};
43
41
  return value;
44
42
  }
45
43
  }
@@ -25,10 +25,9 @@ function undoRedo(obs$, options) {
25
25
  historyPointer = 0;
26
26
  }
27
27
  const snapshot = state.internal.clone(obs$.get());
28
+ history = history.slice(0, historyPointer + 1);
28
29
  if (options == null ? void 0 : options.limit) {
29
30
  history = history.slice(Math.max(0, history.length - options.limit));
30
- } else {
31
- history = history.slice(0, historyPointer + 1);
32
31
  }
33
32
  history.push(snapshot);
34
33
  historyPointer = history.length - 1;
@@ -23,10 +23,9 @@ function undoRedo(obs$, options) {
23
23
  historyPointer = 0;
24
24
  }
25
25
  const snapshot = internal.clone(obs$.get());
26
+ history = history.slice(0, historyPointer + 1);
26
27
  if (options == null ? void 0 : options.limit) {
27
28
  history = history.slice(Math.max(0, history.length - options.limit));
28
- } else {
29
- history = history.slice(0, historyPointer + 1);
30
29
  }
31
30
  history.push(snapshot);
32
31
  historyPointer = history.length - 1;
package/index.d.mts CHANGED
@@ -109,6 +109,8 @@ declare function setNodeValue(node: NodeInfo, newValue: any): {
109
109
  prevValue: any;
110
110
  newValue: any;
111
111
  parentValue: any;
112
+ parentHadKey: boolean;
113
+ parentHasKey: boolean;
112
114
  };
113
115
  declare function getNodeValue(node: NodeInfo): any;
114
116
  declare function getChildNode(node: NodeInfo, key: string, asFunction?: Function): NodeInfo;
package/index.d.ts CHANGED
@@ -109,6 +109,8 @@ declare function setNodeValue(node: NodeInfo, newValue: any): {
109
109
  prevValue: any;
110
110
  newValue: any;
111
111
  parentValue: any;
112
+ parentHadKey: boolean;
113
+ parentHasKey: boolean;
112
114
  };
113
115
  declare function getNodeValue(node: NodeInfo): any;
114
116
  declare function getChildNode(node: NodeInfo, key: string, asFunction?: Function): NodeInfo;
package/index.js CHANGED
@@ -9,7 +9,7 @@ function isString(obj) {
9
9
  return typeof obj === "string";
10
10
  }
11
11
  function isObject(obj) {
12
- return !!obj && typeof obj === "object" && !(obj instanceof Date) && !isArray(obj);
12
+ return !!obj && typeof obj === "object" && !(obj instanceof Date) && !isTemporal(obj) && !isArray(obj);
13
13
  }
14
14
  function isPlainObject(obj) {
15
15
  return isObject(obj) && obj.constructor === Object;
@@ -19,11 +19,14 @@ function isFunction(obj) {
19
19
  }
20
20
  function isPrimitive(arg) {
21
21
  const type = typeof arg;
22
- return arg !== void 0 && (isDate(arg) || type !== "object" && type !== "function");
22
+ return arg !== void 0 && (isDate(arg) || isTemporal(arg) || type !== "object" && type !== "function");
23
23
  }
24
24
  function isDate(obj) {
25
25
  return obj instanceof Date;
26
26
  }
27
+ function isTemporal(obj) {
28
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj[Symbol.toStringTag] === "string" && obj[Symbol.toStringTag].startsWith("Temporal.");
29
+ }
27
30
  function isSymbol(obj) {
28
31
  return typeof obj === "symbol";
29
32
  }
@@ -166,6 +169,7 @@ function setNodeValue(node, newValue) {
166
169
  const parentValue = node.parent ? ensureNodeValue(parentNode) : parentNode.root;
167
170
  const useSetFn = isSet(parentValue);
168
171
  const useMapFn = isMap(parentValue);
172
+ const parentHadKey = useSetFn || useMapFn ? parentValue.has(key) : Object.prototype.hasOwnProperty.call(parentValue, key);
169
173
  const prevValue = useSetFn ? key : useMapFn ? parentValue.get(key) : parentValue[key];
170
174
  const isFunc = isFunction(newValue);
171
175
  newValue = !parentNode.isAssigning && isFunc && !isFunction(prevValue) ? newValue(prevValue) : newValue;
@@ -185,7 +189,8 @@ function setNodeValue(node, newValue) {
185
189
  parentNode.isSetting--;
186
190
  }
187
191
  }
188
- return { prevValue, newValue, parentValue };
192
+ const parentHasKey = useSetFn || useMapFn ? parentValue.has(key) : Object.prototype.hasOwnProperty.call(parentValue, key);
193
+ return { prevValue, newValue, parentValue, parentHadKey, parentHasKey };
189
194
  }
190
195
  var arrNodeKeys = [];
191
196
  function getNodeValue(node) {
@@ -261,7 +266,7 @@ function extractFunction(node, key, fnOrComputed) {
261
266
  node.functions.set(key, fnOrComputed);
262
267
  }
263
268
  function equals(a, b) {
264
- return a === b || isDate(a) && isDate(b) && +a === +b;
269
+ return a === b || isDate(a) && isDate(b) && +a === +b || isTemporal(a) && isTemporal(b) && String(a) === String(b);
265
270
  }
266
271
  function getKeys(obj, isArr, isMap2, isSet2) {
267
272
  return isArr ? void 0 : obj ? isSet2 ? Array.from(obj) : isMap2 ? Array.from(obj.keys()) : Object.keys(obj) : [];
@@ -1520,6 +1525,16 @@ function updateNodes(parent, obj, prevValue) {
1520
1525
  parent.children.set(key, child);
1521
1526
  }
1522
1527
  }
1528
+ if (isArr && length < lengthPrev && parent.children) {
1529
+ for (let i = length; i < lengthPrev; i++) {
1530
+ const key = i + "";
1531
+ const child = parent.children.get(key);
1532
+ if (child) {
1533
+ handleDeletedChild(child, prevValue == null ? void 0 : prevValue[i]);
1534
+ parent.children.delete(key);
1535
+ }
1536
+ }
1537
+ }
1523
1538
  retValue = hasADiff || didMove;
1524
1539
  } else if (prevValue !== void 0) {
1525
1540
  retValue = true;
@@ -1531,8 +1546,8 @@ function updateNodes(parent, obj, prevValue) {
1531
1546
  }
1532
1547
  function handleDeletedChild(child, p) {
1533
1548
  var _a, _b;
1534
- (_a = child.linkedToNodeDispose) == null ? void 0 : _a.call(child);
1535
- (_b = child.activatedObserveDispose) == null ? void 0 : _b.call(child);
1549
+ deactivateNode(child);
1550
+ (_b = (_a = child.parent) == null ? void 0 : _a.functions) == null ? void 0 : _b.delete(child.key);
1536
1551
  if (!isPrimitive(p)) {
1537
1552
  updateNodes(child, void 0, p);
1538
1553
  }
@@ -1791,8 +1806,14 @@ function setKey(node, key, newValue, level) {
1791
1806
  if (isObservable(newValue)) {
1792
1807
  setToObservable(childNode, newValue);
1793
1808
  } else {
1794
- const { newValue: savedValue, prevValue, parentValue } = setNodeValue(childNode, newValue);
1795
- const isPrim = isPrimitive(prevValue) || prevValue instanceof Date || isPrimitive(savedValue) || savedValue instanceof Date;
1809
+ const {
1810
+ newValue: savedValue,
1811
+ prevValue,
1812
+ parentValue,
1813
+ parentHadKey,
1814
+ parentHasKey
1815
+ } = setNodeValue(childNode, newValue);
1816
+ const isPrim = isPrimitive(prevValue) || prevValue instanceof Date || isTemporal(prevValue) || isPrimitive(savedValue) || savedValue instanceof Date || isTemporal(savedValue);
1796
1817
  if (!isPrim) {
1797
1818
  let parent = childNode;
1798
1819
  do {
@@ -1812,7 +1833,8 @@ function setKey(node, key, newValue, level) {
1812
1833
  isPrim,
1813
1834
  isRoot,
1814
1835
  level,
1815
- forceNotify
1836
+ forceNotify,
1837
+ parentHadKey !== parentHasKey
1816
1838
  );
1817
1839
  }
1818
1840
  extractFunctionOrComputed(node, key, savedValue);
@@ -1920,7 +1942,7 @@ function handlerMapSet(node, p, value) {
1920
1942
  };
1921
1943
  }
1922
1944
  }
1923
- function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue, isPrim, isRoot, level, forceNotify) {
1945
+ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue, isPrim, isRoot, level, forceNotify, parentKeyChanged) {
1924
1946
  if (!childNode)
1925
1947
  childNode = node;
1926
1948
  beginBatch();
@@ -1931,6 +1953,7 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue,
1931
1953
  let whenOptimizedOnlyIf = false;
1932
1954
  let valueAsArr;
1933
1955
  let valueAsMap;
1956
+ let valueAsObj;
1934
1957
  if (!isPrim || prevValue && !isPrimitive(prevValue)) {
1935
1958
  if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
1936
1959
  __devUpdateNodes.clear();
@@ -1940,6 +1963,8 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue,
1940
1963
  valueAsArr = newValue;
1941
1964
  } else if (isMap(newValue) || isSet(newValue)) {
1942
1965
  valueAsMap = newValue;
1966
+ } else if (isObject(newValue)) {
1967
+ valueAsObj = newValue;
1943
1968
  }
1944
1969
  }
1945
1970
  if (isArray(parentValue)) {
@@ -1951,6 +1976,13 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue,
1951
1976
  whenOptimizedOnlyIf = (valueAsArr == null ? void 0 : valueAsArr.length) !== (prevValue == null ? void 0 : prevValue.length);
1952
1977
  } else if (valueAsMap) {
1953
1978
  whenOptimizedOnlyIf = (valueAsMap == null ? void 0 : valueAsMap.size) !== (prevValue == null ? void 0 : prevValue.size);
1979
+ } else if (valueAsObj) {
1980
+ const keys = Object.keys(valueAsObj);
1981
+ const prevValueAsObj = isObject(prevValue) ? prevValue : {};
1982
+ const prevKeys = Object.keys(prevValueAsObj);
1983
+ whenOptimizedOnlyIf = keys.length !== prevKeys.length || keys.some((key) => !hasOwnProperty.call(prevValueAsObj, key));
1984
+ } else if (isObject(parentValue)) {
1985
+ whenOptimizedOnlyIf = !!parentKeyChanged;
1954
1986
  }
1955
1987
  if (isPrim || !newValue || isEmpty(newValue) && !isEmpty(prevValue) ? newValue !== prevValue : hasADiff) {
1956
1988
  notify(
package/index.mjs CHANGED
@@ -7,7 +7,7 @@ function isString(obj) {
7
7
  return typeof obj === "string";
8
8
  }
9
9
  function isObject(obj) {
10
- return !!obj && typeof obj === "object" && !(obj instanceof Date) && !isArray(obj);
10
+ return !!obj && typeof obj === "object" && !(obj instanceof Date) && !isTemporal(obj) && !isArray(obj);
11
11
  }
12
12
  function isPlainObject(obj) {
13
13
  return isObject(obj) && obj.constructor === Object;
@@ -17,11 +17,14 @@ function isFunction(obj) {
17
17
  }
18
18
  function isPrimitive(arg) {
19
19
  const type = typeof arg;
20
- return arg !== void 0 && (isDate(arg) || type !== "object" && type !== "function");
20
+ return arg !== void 0 && (isDate(arg) || isTemporal(arg) || type !== "object" && type !== "function");
21
21
  }
22
22
  function isDate(obj) {
23
23
  return obj instanceof Date;
24
24
  }
25
+ function isTemporal(obj) {
26
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj[Symbol.toStringTag] === "string" && obj[Symbol.toStringTag].startsWith("Temporal.");
27
+ }
25
28
  function isSymbol(obj) {
26
29
  return typeof obj === "symbol";
27
30
  }
@@ -164,6 +167,7 @@ function setNodeValue(node, newValue) {
164
167
  const parentValue = node.parent ? ensureNodeValue(parentNode) : parentNode.root;
165
168
  const useSetFn = isSet(parentValue);
166
169
  const useMapFn = isMap(parentValue);
170
+ const parentHadKey = useSetFn || useMapFn ? parentValue.has(key) : Object.prototype.hasOwnProperty.call(parentValue, key);
167
171
  const prevValue = useSetFn ? key : useMapFn ? parentValue.get(key) : parentValue[key];
168
172
  const isFunc = isFunction(newValue);
169
173
  newValue = !parentNode.isAssigning && isFunc && !isFunction(prevValue) ? newValue(prevValue) : newValue;
@@ -183,7 +187,8 @@ function setNodeValue(node, newValue) {
183
187
  parentNode.isSetting--;
184
188
  }
185
189
  }
186
- return { prevValue, newValue, parentValue };
190
+ const parentHasKey = useSetFn || useMapFn ? parentValue.has(key) : Object.prototype.hasOwnProperty.call(parentValue, key);
191
+ return { prevValue, newValue, parentValue, parentHadKey, parentHasKey };
187
192
  }
188
193
  var arrNodeKeys = [];
189
194
  function getNodeValue(node) {
@@ -259,7 +264,7 @@ function extractFunction(node, key, fnOrComputed) {
259
264
  node.functions.set(key, fnOrComputed);
260
265
  }
261
266
  function equals(a, b) {
262
- return a === b || isDate(a) && isDate(b) && +a === +b;
267
+ return a === b || isDate(a) && isDate(b) && +a === +b || isTemporal(a) && isTemporal(b) && String(a) === String(b);
263
268
  }
264
269
  function getKeys(obj, isArr, isMap2, isSet2) {
265
270
  return isArr ? void 0 : obj ? isSet2 ? Array.from(obj) : isMap2 ? Array.from(obj.keys()) : Object.keys(obj) : [];
@@ -1518,6 +1523,16 @@ function updateNodes(parent, obj, prevValue) {
1518
1523
  parent.children.set(key, child);
1519
1524
  }
1520
1525
  }
1526
+ if (isArr && length < lengthPrev && parent.children) {
1527
+ for (let i = length; i < lengthPrev; i++) {
1528
+ const key = i + "";
1529
+ const child = parent.children.get(key);
1530
+ if (child) {
1531
+ handleDeletedChild(child, prevValue == null ? void 0 : prevValue[i]);
1532
+ parent.children.delete(key);
1533
+ }
1534
+ }
1535
+ }
1521
1536
  retValue = hasADiff || didMove;
1522
1537
  } else if (prevValue !== void 0) {
1523
1538
  retValue = true;
@@ -1529,8 +1544,8 @@ function updateNodes(parent, obj, prevValue) {
1529
1544
  }
1530
1545
  function handleDeletedChild(child, p) {
1531
1546
  var _a, _b;
1532
- (_a = child.linkedToNodeDispose) == null ? void 0 : _a.call(child);
1533
- (_b = child.activatedObserveDispose) == null ? void 0 : _b.call(child);
1547
+ deactivateNode(child);
1548
+ (_b = (_a = child.parent) == null ? void 0 : _a.functions) == null ? void 0 : _b.delete(child.key);
1534
1549
  if (!isPrimitive(p)) {
1535
1550
  updateNodes(child, void 0, p);
1536
1551
  }
@@ -1789,8 +1804,14 @@ function setKey(node, key, newValue, level) {
1789
1804
  if (isObservable(newValue)) {
1790
1805
  setToObservable(childNode, newValue);
1791
1806
  } else {
1792
- const { newValue: savedValue, prevValue, parentValue } = setNodeValue(childNode, newValue);
1793
- const isPrim = isPrimitive(prevValue) || prevValue instanceof Date || isPrimitive(savedValue) || savedValue instanceof Date;
1807
+ const {
1808
+ newValue: savedValue,
1809
+ prevValue,
1810
+ parentValue,
1811
+ parentHadKey,
1812
+ parentHasKey
1813
+ } = setNodeValue(childNode, newValue);
1814
+ const isPrim = isPrimitive(prevValue) || prevValue instanceof Date || isTemporal(prevValue) || isPrimitive(savedValue) || savedValue instanceof Date || isTemporal(savedValue);
1794
1815
  if (!isPrim) {
1795
1816
  let parent = childNode;
1796
1817
  do {
@@ -1810,7 +1831,8 @@ function setKey(node, key, newValue, level) {
1810
1831
  isPrim,
1811
1832
  isRoot,
1812
1833
  level,
1813
- forceNotify
1834
+ forceNotify,
1835
+ parentHadKey !== parentHasKey
1814
1836
  );
1815
1837
  }
1816
1838
  extractFunctionOrComputed(node, key, savedValue);
@@ -1918,7 +1940,7 @@ function handlerMapSet(node, p, value) {
1918
1940
  };
1919
1941
  }
1920
1942
  }
1921
- function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue, isPrim, isRoot, level, forceNotify) {
1943
+ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue, isPrim, isRoot, level, forceNotify, parentKeyChanged) {
1922
1944
  if (!childNode)
1923
1945
  childNode = node;
1924
1946
  beginBatch();
@@ -1929,6 +1951,7 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue,
1929
1951
  let whenOptimizedOnlyIf = false;
1930
1952
  let valueAsArr;
1931
1953
  let valueAsMap;
1954
+ let valueAsObj;
1932
1955
  if (!isPrim || prevValue && !isPrimitive(prevValue)) {
1933
1956
  if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
1934
1957
  __devUpdateNodes.clear();
@@ -1938,6 +1961,8 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue,
1938
1961
  valueAsArr = newValue;
1939
1962
  } else if (isMap(newValue) || isSet(newValue)) {
1940
1963
  valueAsMap = newValue;
1964
+ } else if (isObject(newValue)) {
1965
+ valueAsObj = newValue;
1941
1966
  }
1942
1967
  }
1943
1968
  if (isArray(parentValue)) {
@@ -1949,6 +1974,13 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, parentValue,
1949
1974
  whenOptimizedOnlyIf = (valueAsArr == null ? void 0 : valueAsArr.length) !== (prevValue == null ? void 0 : prevValue.length);
1950
1975
  } else if (valueAsMap) {
1951
1976
  whenOptimizedOnlyIf = (valueAsMap == null ? void 0 : valueAsMap.size) !== (prevValue == null ? void 0 : prevValue.size);
1977
+ } else if (valueAsObj) {
1978
+ const keys = Object.keys(valueAsObj);
1979
+ const prevValueAsObj = isObject(prevValue) ? prevValue : {};
1980
+ const prevKeys = Object.keys(prevValueAsObj);
1981
+ whenOptimizedOnlyIf = keys.length !== prevKeys.length || keys.some((key) => !hasOwnProperty.call(prevValueAsObj, key));
1982
+ } else if (isObject(parentValue)) {
1983
+ whenOptimizedOnlyIf = !!parentKeyChanged;
1952
1984
  }
1953
1985
  if (isPrim || !newValue || isEmpty(newValue) && !isEmpty(prevValue) ? newValue !== prevValue : hasADiff) {
1954
1986
  notify(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/state",
3
- "version": "3.0.0-beta.47",
3
+ "version": "3.0.0-beta.48",
4
4
  "description": "legend-state",
5
5
  "sideEffects": false,
6
6
  "private": false,
@@ -7,6 +7,14 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
7
 
8
8
  var React__default = /*#__PURE__*/_interopDefault(React);
9
9
 
10
+ // src/react-hooks/createObservableHook.ts
11
+ function runInRender(fn) {
12
+ try {
13
+ return fn();
14
+ } finally {
15
+ }
16
+ }
17
+
10
18
  // src/react-hooks/createObservableHook.ts
11
19
  function overrideHooks(refObs) {
12
20
  React__default.default.useState = function useState(initialState) {
@@ -30,10 +38,13 @@ function createObservableHook(fn) {
30
38
  const _useReducer = React__default.default.useReducer;
31
39
  return function(...args) {
32
40
  const refObs = React__default.default.useRef(void 0);
33
- overrideHooks(refObs);
34
- fn(...args);
35
- React__default.default.useState = _useState;
36
- React__default.default.useReducer = _useReducer;
41
+ try {
42
+ overrideHooks(refObs);
43
+ runInRender(() => fn(...args));
44
+ } finally {
45
+ React__default.default.useState = _useState;
46
+ React__default.default.useReducer = _useReducer;
47
+ }
37
48
  return refObs.current;
38
49
  };
39
50
  }
@@ -1,6 +1,14 @@
1
1
  import { observable, isFunction } from '@legendapp/state';
2
2
  import React from 'react';
3
3
 
4
+ // src/react-hooks/createObservableHook.ts
5
+ function runInRender(fn) {
6
+ try {
7
+ return fn();
8
+ } finally {
9
+ }
10
+ }
11
+
4
12
  // src/react-hooks/createObservableHook.ts
5
13
  function overrideHooks(refObs) {
6
14
  React.useState = function useState(initialState) {
@@ -24,10 +32,13 @@ function createObservableHook(fn) {
24
32
  const _useReducer = React.useReducer;
25
33
  return function(...args) {
26
34
  const refObs = React.useRef(void 0);
27
- overrideHooks(refObs);
28
- fn(...args);
29
- React.useState = _useState;
30
- React.useReducer = _useReducer;
35
+ try {
36
+ overrideHooks(refObs);
37
+ runInRender(() => fn(...args));
38
+ } finally {
39
+ React.useState = _useState;
40
+ React.useReducer = _useReducer;
41
+ }
31
42
  return refObs.current;
32
43
  };
33
44
  }
package/react-native.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var react = require('@legendapp/state/react');
4
- var react$1 = require('react');
5
4
  var reactNative = require('react-native');
6
5
 
7
6
  // src/react-reactive/Components.ts
@@ -10,9 +9,8 @@ var $Button = react.reactive(reactNative.Button);
10
9
  var $FlatList = react.reactive(reactNative.FlatList, void 0, {
11
10
  data: {
12
11
  selector: (propsOut, p) => {
13
- const state = react$1.useRef(0);
14
- const [renderNum, value] = react.use$(() => [state.current++, p.get(true)]);
15
- propsOut.extraData = renderNum;
12
+ const value = p.get(true);
13
+ propsOut.extraData = {};
16
14
  return value;
17
15
  }
18
16
  }
package/react-native.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { reactive, use$ } from '@legendapp/state/react';
2
- import { useRef } from 'react';
1
+ import { reactive } from '@legendapp/state/react';
3
2
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
3
 
5
4
  // src/react-reactive/Components.ts
@@ -8,9 +7,8 @@ var $Button = reactive(Button);
8
7
  var $FlatList = reactive(FlatList, void 0, {
9
8
  data: {
10
9
  selector: (propsOut, p) => {
11
- const state = useRef(0);
12
- const [renderNum, value] = use$(() => [state.current++, p.get(true)]);
13
- propsOut.extraData = renderNum;
10
+ const value = p.get(true);
11
+ propsOut.extraData = {};
14
12
  return value;
15
13
  }
16
14
  }
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var react = require('@legendapp/state/react');
4
- var react$1 = require('react');
5
4
  var reactNative = require('react-native');
6
5
 
7
6
  // src/react-reactive/Components.ts
@@ -10,9 +9,8 @@ var $Button = react.reactive(reactNative.Button);
10
9
  var $FlatList = react.reactive(reactNative.FlatList, void 0, {
11
10
  data: {
12
11
  selector: (propsOut, p) => {
13
- const state = react$1.useRef(0);
14
- const [renderNum, value] = react.use$(() => [state.current++, p.get(true)]);
15
- propsOut.extraData = renderNum;
12
+ const value = p.get(true);
13
+ propsOut.extraData = {};
16
14
  return value;
17
15
  }
18
16
  }
@@ -1,5 +1,4 @@
1
- import { reactive, use$ } from '@legendapp/state/react';
2
- import { useRef } from 'react';
1
+ import { reactive } from '@legendapp/state/react';
3
2
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
3
 
5
4
  // src/react-reactive/Components.ts
@@ -8,9 +7,8 @@ var $Button = reactive(Button);
8
7
  var $FlatList = reactive(FlatList, void 0, {
9
8
  data: {
10
9
  selector: (propsOut, p) => {
11
- const state = useRef(0);
12
- const [renderNum, value] = use$(() => [state.current++, p.get(true)]);
13
- propsOut.extraData = renderNum;
10
+ const value = p.get(true);
11
+ propsOut.extraData = {};
14
12
  return value;
15
13
  }
16
14
  }
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var react$1 = require('@legendapp/state/react');
4
- var react = require('react');
5
3
  var reactNative = require('react-native');
6
4
 
7
5
  // src/react-reactive/enableReactNativeComponents.ts
@@ -44,9 +42,8 @@ function enableReactNativeComponents_(configure) {
44
42
  FlatList: {
45
43
  data: {
46
44
  selector: (propsOut, p) => {
47
- const state = react.useRef(0);
48
- const [renderNum, value] = react$1.useSelector(() => [state.current++, p.get(true)]);
49
- propsOut.extraData = renderNum;
45
+ const value = p.get(true);
46
+ propsOut.extraData = {};
50
47
  return value;
51
48
  }
52
49
  }
@@ -1,5 +1,3 @@
1
- import { useSelector } from '@legendapp/state/react';
2
- import { useRef } from 'react';
3
1
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
2
 
5
3
  // src/react-reactive/enableReactNativeComponents.ts
@@ -42,9 +40,8 @@ function enableReactNativeComponents_(configure) {
42
40
  FlatList: {
43
41
  data: {
44
42
  selector: (propsOut, p) => {
45
- const state = useRef(0);
46
- const [renderNum, value] = useSelector(() => [state.current++, p.get(true)]);
47
- propsOut.extraData = renderNum;
43
+ const value = p.get(true);
44
+ propsOut.extraData = {};
48
45
  return value;
49
46
  }
50
47
  }
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var react$1 = require('@legendapp/state/react');
4
- var react = require('react');
5
3
  var reactNative = require('react-native');
6
4
 
7
5
  // src/react-reactive/enableReactNativeComponents.ts
@@ -44,9 +42,8 @@ function enableReactNativeComponents_(configure) {
44
42
  FlatList: {
45
43
  data: {
46
44
  selector: (propsOut, p) => {
47
- const state = react.useRef(0);
48
- const [renderNum, value] = react$1.useSelector(() => [state.current++, p.get(true)]);
49
- propsOut.extraData = renderNum;
45
+ const value = p.get(true);
46
+ propsOut.extraData = {};
50
47
  return value;
51
48
  }
52
49
  }
@@ -1,5 +1,3 @@
1
- import { useSelector } from '@legendapp/state/react';
2
- import { useRef } from 'react';
3
1
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
2
 
5
3
  // src/react-reactive/enableReactNativeComponents.ts
@@ -42,9 +40,8 @@ function enableReactNativeComponents_(configure) {
42
40
  FlatList: {
43
41
  data: {
44
42
  selector: (propsOut, p) => {
45
- const state = useRef(0);
46
- const [renderNum, value] = useSelector(() => [state.current++, p.get(true)]);
47
- propsOut.extraData = renderNum;
43
+ const value = p.get(true);
44
+ propsOut.extraData = {};
48
45
  return value;
49
46
  }
50
47
  }
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var react$1 = require('@legendapp/state/react');
4
- var react = require('react');
5
3
  var reactNative = require('react-native');
6
4
 
7
5
  // src/react-reactive/enableReactNativeComponents.ts
@@ -44,9 +42,8 @@ function enableReactNativeComponents_(configure) {
44
42
  FlatList: {
45
43
  data: {
46
44
  selector: (propsOut, p) => {
47
- const state = react.useRef(0);
48
- const [renderNum, value] = react$1.useSelector(() => [state.current++, p.get(true)]);
49
- propsOut.extraData = renderNum;
45
+ const value = p.get(true);
46
+ propsOut.extraData = {};
50
47
  return value;
51
48
  }
52
49
  }
@@ -1,5 +1,3 @@
1
- import { useSelector } from '@legendapp/state/react';
2
- import { useRef } from 'react';
3
1
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
2
 
5
3
  // src/react-reactive/enableReactNativeComponents.ts
@@ -42,9 +40,8 @@ function enableReactNativeComponents_(configure) {
42
40
  FlatList: {
43
41
  data: {
44
42
  selector: (propsOut, p) => {
45
- const state = useRef(0);
46
- const [renderNum, value] = useSelector(() => [state.current++, p.get(true)]);
47
- propsOut.extraData = renderNum;
43
+ const value = p.get(true);
44
+ propsOut.extraData = {};
48
45
  return value;
49
46
  }
50
47
  }