@legendapp/state 3.0.0-alpha.8 → 3.0.0-beta.0

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 (86) hide show
  1. package/.DS_Store +0 -0
  2. package/config/configureLegendState.d.mts +13 -0
  3. package/config/configureLegendState.d.ts +13 -0
  4. package/config/configureLegendState.js +45 -0
  5. package/config/configureLegendState.mjs +43 -0
  6. package/config/enable$GetSet.js +2 -1
  7. package/config/enable$GetSet.mjs +2 -1
  8. package/config/enableReactTracking.js +2 -1
  9. package/config/enableReactTracking.mjs +2 -1
  10. package/config/enableReactUse.js +2 -1
  11. package/config/enableReactUse.mjs +2 -1
  12. package/config/enable_PeekAssign.js +2 -1
  13. package/config/enable_PeekAssign.mjs +2 -1
  14. package/helpers/trackHistory.js +2 -2
  15. package/helpers/trackHistory.mjs +2 -2
  16. package/index.d.mts +104 -80
  17. package/index.d.ts +104 -80
  18. package/index.js +328 -318
  19. package/index.mjs +325 -316
  20. package/package.json +36 -1
  21. package/persist-plugins/async-storage.d.mts +6 -3
  22. package/persist-plugins/async-storage.d.ts +6 -3
  23. package/persist-plugins/async-storage.js +8 -4
  24. package/persist-plugins/async-storage.mjs +8 -5
  25. package/persist-plugins/indexeddb.d.mts +6 -4
  26. package/persist-plugins/indexeddb.d.ts +6 -4
  27. package/persist-plugins/indexeddb.js +35 -15
  28. package/persist-plugins/indexeddb.mjs +35 -16
  29. package/persist-plugins/mmkv.d.mts +5 -1
  30. package/persist-plugins/mmkv.d.ts +5 -1
  31. package/persist-plugins/mmkv.js +10 -5
  32. package/persist-plugins/mmkv.mjs +10 -6
  33. package/react-reactive/enableReactComponents.d.mts +9 -0
  34. package/react-reactive/enableReactComponents.d.ts +9 -0
  35. package/react-reactive/enableReactComponents.js +19 -0
  36. package/react-reactive/enableReactComponents.mjs +17 -0
  37. package/react-reactive/enableReactNativeComponents.d.mts +22 -0
  38. package/react-reactive/enableReactNativeComponents.d.ts +22 -0
  39. package/react-reactive/enableReactNativeComponents.js +53 -0
  40. package/react-reactive/enableReactNativeComponents.mjs +51 -0
  41. package/react-reactive/enableReactive.d.mts +5 -0
  42. package/react-reactive/enableReactive.d.ts +5 -0
  43. package/react-reactive/enableReactive.js +24 -0
  44. package/react-reactive/enableReactive.mjs +22 -0
  45. package/react-reactive/enableReactive.native.d.mts +5 -0
  46. package/react-reactive/enableReactive.native.d.ts +5 -0
  47. package/react-reactive/enableReactive.native.js +58 -0
  48. package/react-reactive/enableReactive.native.mjs +56 -0
  49. package/react-reactive/enableReactive.web.d.mts +5 -0
  50. package/react-reactive/enableReactive.web.d.ts +5 -0
  51. package/react-reactive/enableReactive.web.js +58 -0
  52. package/react-reactive/enableReactive.web.mjs +56 -0
  53. package/react.d.mts +39 -34
  54. package/react.d.ts +39 -34
  55. package/react.js +39 -17
  56. package/react.mjs +39 -17
  57. package/sync-plugins/crud.d.mts +21 -24
  58. package/sync-plugins/crud.d.ts +21 -24
  59. package/sync-plugins/crud.js +241 -140
  60. package/sync-plugins/crud.mjs +243 -142
  61. package/sync-plugins/fetch.js +12 -8
  62. package/sync-plugins/fetch.mjs +13 -9
  63. package/sync-plugins/firebase.d.mts +27 -0
  64. package/sync-plugins/firebase.d.ts +27 -0
  65. package/sync-plugins/firebase.js +373 -0
  66. package/sync-plugins/firebase.mjs +368 -0
  67. package/sync-plugins/keel.d.mts +43 -26
  68. package/sync-plugins/keel.d.ts +43 -26
  69. package/sync-plugins/keel.js +145 -100
  70. package/sync-plugins/keel.mjs +147 -100
  71. package/sync-plugins/supabase.d.mts +19 -9
  72. package/sync-plugins/supabase.d.ts +19 -9
  73. package/sync-plugins/supabase.js +52 -22
  74. package/sync-plugins/supabase.mjs +53 -23
  75. package/sync-plugins/tanstack-query.d.mts +2 -2
  76. package/sync-plugins/tanstack-query.d.ts +2 -2
  77. package/sync-plugins/tanstack-query.js +22 -5
  78. package/sync-plugins/tanstack-query.mjs +22 -5
  79. package/sync-plugins/tanstack-react-query.d.mts +1 -1
  80. package/sync-plugins/tanstack-react-query.d.ts +1 -1
  81. package/sync-plugins/tanstack-react-query.js +8 -1
  82. package/sync-plugins/tanstack-react-query.mjs +8 -1
  83. package/sync.d.mts +74 -200
  84. package/sync.d.ts +74 -200
  85. package/sync.js +492 -293
  86. package/sync.mjs +498 -299
package/.DS_Store CHANGED
Binary file
@@ -0,0 +1,13 @@
1
+ import { NodeInfo } from '@legendapp/state';
2
+
3
+ declare function configureLegendState({ observableFunctions, observableProperties, jsonReplacer, jsonReviver, }: {
4
+ observableFunctions?: Record<string, (node: NodeInfo, ...args: any[]) => any>;
5
+ observableProperties?: Record<string, {
6
+ get: (node: NodeInfo) => any;
7
+ set: (node: NodeInfo, value: any) => any;
8
+ }>;
9
+ jsonReplacer?: (this: any, key: string, value: any) => any;
10
+ jsonReviver?: (this: any, key: string, value: any) => any;
11
+ }): void;
12
+
13
+ export { configureLegendState };
@@ -0,0 +1,13 @@
1
+ import { NodeInfo } from '@legendapp/state';
2
+
3
+ declare function configureLegendState({ observableFunctions, observableProperties, jsonReplacer, jsonReviver, }: {
4
+ observableFunctions?: Record<string, (node: NodeInfo, ...args: any[]) => any>;
5
+ observableProperties?: Record<string, {
6
+ get: (node: NodeInfo) => any;
7
+ set: (node: NodeInfo, value: any) => any;
8
+ }>;
9
+ jsonReplacer?: (this: any, key: string, value: any) => any;
10
+ jsonReviver?: (this: any, key: string, value: any) => any;
11
+ }): void;
12
+
13
+ export { configureLegendState };
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ var state = require('@legendapp/state');
4
+
5
+ // src/config/configureLegendState.ts
6
+ var { globalState, observableProperties: _observableProperties, observableFns, ObservablePrimitiveClass } = state.internal;
7
+ function configureLegendState({
8
+ observableFunctions,
9
+ observableProperties,
10
+ jsonReplacer,
11
+ jsonReviver
12
+ }) {
13
+ if (observableFunctions) {
14
+ for (const key in observableFunctions) {
15
+ const fn = observableFunctions[key];
16
+ observableFns.set(key, fn);
17
+ ObservablePrimitiveClass.prototype[key] = function(...args) {
18
+ return fn.call(this, this._node, ...args);
19
+ };
20
+ }
21
+ }
22
+ if (observableProperties) {
23
+ for (const key in observableProperties) {
24
+ const fns = observableProperties[key];
25
+ _observableProperties.set(key, fns);
26
+ Object.defineProperty(ObservablePrimitiveClass.prototype, key, {
27
+ configurable: true,
28
+ get() {
29
+ return fns.get.call(this, this._node);
30
+ },
31
+ set(value) {
32
+ return fns.set.call(this, this._node, value);
33
+ }
34
+ });
35
+ }
36
+ }
37
+ if (jsonReplacer) {
38
+ globalState.replacer = jsonReplacer;
39
+ }
40
+ if (jsonReviver) {
41
+ globalState.reviver = jsonReviver;
42
+ }
43
+ }
44
+
45
+ exports.configureLegendState = configureLegendState;
@@ -0,0 +1,43 @@
1
+ import { internal } from '@legendapp/state';
2
+
3
+ // src/config/configureLegendState.ts
4
+ var { globalState, observableProperties: _observableProperties, observableFns, ObservablePrimitiveClass } = internal;
5
+ function configureLegendState({
6
+ observableFunctions,
7
+ observableProperties,
8
+ jsonReplacer,
9
+ jsonReviver
10
+ }) {
11
+ if (observableFunctions) {
12
+ for (const key in observableFunctions) {
13
+ const fn = observableFunctions[key];
14
+ observableFns.set(key, fn);
15
+ ObservablePrimitiveClass.prototype[key] = function(...args) {
16
+ return fn.call(this, this._node, ...args);
17
+ };
18
+ }
19
+ }
20
+ if (observableProperties) {
21
+ for (const key in observableProperties) {
22
+ const fns = observableProperties[key];
23
+ _observableProperties.set(key, fns);
24
+ Object.defineProperty(ObservablePrimitiveClass.prototype, key, {
25
+ configurable: true,
26
+ get() {
27
+ return fns.get.call(this, this._node);
28
+ },
29
+ set(value) {
30
+ return fns.set.call(this, this._node, value);
31
+ }
32
+ });
33
+ }
34
+ }
35
+ if (jsonReplacer) {
36
+ globalState.replacer = jsonReplacer;
37
+ }
38
+ if (jsonReviver) {
39
+ globalState.reviver = jsonReviver;
40
+ }
41
+ }
42
+
43
+ export { configureLegendState };
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var state = require('@legendapp/state');
4
+ var configureLegendState = require('@legendapp/state/config/configureLegendState');
4
5
 
5
6
  // src/config/enable$GetSet.ts
6
7
  function enable$GetSet() {
7
- state.configureLegendState({
8
+ configureLegendState.configureLegendState({
8
9
  observableProperties: {
9
10
  $: {
10
11
  get(node) {
@@ -1,4 +1,5 @@
1
- import { configureLegendState, internal } from '@legendapp/state';
1
+ import { internal } from '@legendapp/state';
2
+ import { configureLegendState } from '@legendapp/state/config/configureLegendState';
2
3
 
3
4
  // src/config/enable$GetSet.ts
4
5
  function enable$GetSet() {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var state = require('@legendapp/state');
4
+ var configureLegendState = require('@legendapp/state/config/configureLegendState');
4
5
  var react$1 = require('@legendapp/state/react');
5
6
  var react = require('react');
6
7
 
@@ -22,7 +23,7 @@ function enableReactTracking({ auto, warnUnobserved }) {
22
23
  }
23
24
  return false;
24
25
  };
25
- state.configureLegendState({
26
+ configureLegendState.configureLegendState({
26
27
  observableFunctions: {
27
28
  get: (node, options) => {
28
29
  if (needsSelector()) {
@@ -1,4 +1,5 @@
1
- import { configureLegendState, isObject, internal, tracking } from '@legendapp/state';
1
+ import { isObject, internal, tracking } from '@legendapp/state';
2
+ import { configureLegendState } from '@legendapp/state/config/configureLegendState';
2
3
  import { useSelector } from '@legendapp/state/react';
3
4
  import { createContext, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, useContext } from 'react';
4
5
 
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var state = require('@legendapp/state');
4
+ var configureLegendState = require('@legendapp/state/config/configureLegendState');
4
5
  var react = require('@legendapp/state/react');
5
6
 
6
7
  // src/config/enableReactUse.ts
7
8
  var didWarn = false;
8
9
  function enableReactUse() {
9
- state.configureLegendState({
10
+ configureLegendState.configureLegendState({
10
11
  observableFunctions: {
11
12
  use: (node, options) => {
12
13
  if (process.env.NODE_ENV === "development" && !didWarn) {
@@ -1,4 +1,5 @@
1
- import { configureLegendState, internal } from '@legendapp/state';
1
+ import { internal } from '@legendapp/state';
2
+ import { configureLegendState } from '@legendapp/state/config/configureLegendState';
2
3
  import { useSelector } from '@legendapp/state/react';
3
4
 
4
5
  // src/config/enableReactUse.ts
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var state = require('@legendapp/state');
4
+ var configureLegendState = require('@legendapp/state/config/configureLegendState');
4
5
 
5
6
  // src/config/enable_PeekAssign.ts
6
7
  function enable_PeekAssign() {
7
- state.configureLegendState({
8
+ configureLegendState.configureLegendState({
8
9
  observableProperties: {
9
10
  _: {
10
11
  get(node) {
@@ -1,4 +1,5 @@
1
- import { configureLegendState, internal } from '@legendapp/state';
1
+ import { internal } from '@legendapp/state';
2
+ import { configureLegendState } from '@legendapp/state/config/configureLegendState';
2
3
 
3
4
  // src/config/enable_PeekAssign.ts
4
5
  function enable_PeekAssign() {
@@ -5,8 +5,8 @@ var state = require('@legendapp/state');
5
5
  // src/helpers/trackHistory.ts
6
6
  function trackHistory(value$, targetObservable) {
7
7
  const history = targetObservable != null ? targetObservable : state.observable();
8
- value$.onChange(({ loading, remote, changes }) => {
9
- if (!loading && !remote) {
8
+ value$.onChange(({ isFromPersist, isFromSync, changes }) => {
9
+ if (!isFromPersist && !isFromSync) {
10
10
  const time = Date.now().toString();
11
11
  for (let i = 0; i < changes.length; i++) {
12
12
  const { path, prevAtPath, pathTypes } = changes[i];
@@ -3,8 +3,8 @@ import { observable, constructObjectWithPath, mergeIntoObservable } from '@legen
3
3
  // src/helpers/trackHistory.ts
4
4
  function trackHistory(value$, targetObservable) {
5
5
  const history = targetObservable != null ? targetObservable : observable();
6
- value$.onChange(({ loading, remote, changes }) => {
7
- if (!loading && !remote) {
6
+ value$.onChange(({ isFromPersist, isFromSync, changes }) => {
7
+ if (!isFromPersist && !isFromSync) {
8
8
  const time = Date.now().toString();
9
9
  for (let i = 0; i < changes.length; i++) {
10
10
  const { path, prevAtPath, pathTypes } = changes[i];