@frontegg/redux-store 7.3.0-alpha.0 → 7.4.0-alpha.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 (58) hide show
  1. package/auth/AcceptInvitationState/actions.d.ts +2 -5
  2. package/auth/AcceptInvitationState/actions.js +0 -2
  3. package/auth/AccountSettingsState/actions.d.ts +1 -12
  4. package/auth/AccountSettingsState/actions.js +0 -2
  5. package/auth/ActivateAccountState/actions.d.ts +2 -15
  6. package/auth/ActivateAccountState/actions.js +0 -2
  7. package/auth/UnlockAccountState/actions.d.ts +1 -5
  8. package/auth/UnlockAccountState/actions.js +0 -2
  9. package/index.js +1 -1
  10. package/mocks/auth-mocks/acceptInvitationActions.mocks.d.ts +1 -4
  11. package/mocks/auth-mocks/accountSettingsActions.mocks.d.ts +1 -12
  12. package/mocks/auth-mocks/activateAccountActions.mocks.d.ts +1 -14
  13. package/mocks/auth-mocks/unlockAccountActions.mocks.d.ts +1 -5
  14. package/node/auth/AcceptInvitationState/actions.js +0 -2
  15. package/node/auth/AccountSettingsState/actions.js +0 -2
  16. package/node/auth/ActivateAccountState/actions.js +0 -2
  17. package/node/auth/UnlockAccountState/actions.js +0 -2
  18. package/node/index.js +1 -1
  19. package/node/toolkit/index.js +12 -4
  20. package/node/toolkit/proxy.js +2 -2
  21. package/node/toolkit/store.js +4 -5
  22. package/node/valtio/index.js +27 -0
  23. package/node/valtio/utils/devtools.js +113 -0
  24. package/node/valtio/utils/index.js +54 -0
  25. package/node/valtio/utils/proxyMap.js +106 -0
  26. package/node/valtio/utils/proxySet.js +92 -0
  27. package/node/valtio/utils/proxyWithComputed.js +36 -0
  28. package/node/valtio/utils/proxyWithHistory.js +90 -0
  29. package/node/valtio/utils/subscribeKey.js +27 -0
  30. package/node/valtio/utils/watch.js +105 -0
  31. package/node/valtio/valtio.js +271 -0
  32. package/package.json +3 -3
  33. package/toolkit/index.d.ts +3 -2
  34. package/toolkit/index.js +2 -1
  35. package/toolkit/proxy.d.ts +0 -6
  36. package/toolkit/proxy.js +1 -1
  37. package/toolkit/store.js +1 -2
  38. package/valtio/index.d.ts +6 -0
  39. package/valtio/index.js +7 -0
  40. package/valtio/package.json +6 -0
  41. package/valtio/utils/devtools.d.ts +15 -0
  42. package/valtio/utils/devtools.js +106 -0
  43. package/valtio/utils/index.d.ts +7 -0
  44. package/valtio/utils/index.js +8 -0
  45. package/valtio/utils/proxyMap.d.ts +31 -0
  46. package/valtio/utils/proxyMap.js +100 -0
  47. package/valtio/utils/proxySet.d.ts +18 -0
  48. package/valtio/utils/proxySet.js +89 -0
  49. package/valtio/utils/proxyWithComputed.d.ts +12 -0
  50. package/valtio/utils/proxyWithComputed.js +30 -0
  51. package/valtio/utils/proxyWithHistory.d.ts +51 -0
  52. package/valtio/utils/proxyWithHistory.js +84 -0
  53. package/valtio/utils/subscribeKey.d.ts +12 -0
  54. package/valtio/utils/subscribeKey.js +22 -0
  55. package/valtio/utils/watch.d.ts +31 -0
  56. package/valtio/utils/watch.js +99 -0
  57. package/valtio/valtio.d.ts +47 -0
  58. package/valtio/valtio.js +259 -0
@@ -1,11 +1,8 @@
1
1
  import { FronteggState, RestApi, SharedActions } from '../../interfaces';
2
- import { AcceptInvitationState, AcceptInvitationStep } from './interfaces';
2
+ import { AcceptInvitationState } from './interfaces';
3
3
  import { IAcceptInvitation } from '@frontegg/rest-api';
4
4
  declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
5
- setAcceptInvitationState: (state: Partial<AcceptInvitationState>) => {
6
- readonly error?: string | undefined;
7
- readonly step: AcceptInvitationStep;
8
- };
5
+ setAcceptInvitationState: (state: Partial<AcceptInvitationState>) => void;
9
6
  resetAcceptInvitationState: () => void;
10
7
  acceptInvitation: (payload: IAcceptInvitation) => Promise<void>;
11
8
  };
@@ -1,4 +1,3 @@
1
- import { snapshot } from 'valtio/vanilla';
2
1
  import { AcceptInvitationStep } from './interfaces';
3
2
  import { initialState } from './state';
4
3
  import { deepClone, errorHandler } from '../../helpers';
@@ -6,7 +5,6 @@ export default ((store, api, sharedActions) => {
6
5
  const actions = sharedActions;
7
6
  const setAcceptInvitationState = state => {
8
7
  Object.assign(store.auth.acceptInvitationState, state);
9
- return snapshot(store.auth.acceptInvitationState);
10
8
  };
11
9
  const resetAcceptInvitationState = () => {
12
10
  store.auth.acceptInvitationState = deepClone(initialState);
@@ -2,18 +2,7 @@ import { FronteggState, RestApi, SharedActions, WithCallback, WithSilentLoad } f
2
2
  import { ISettingsResponse, IUpdateSettings } from '@frontegg/rest-api';
3
3
  import { AccountSettingsState } from './interfaces';
4
4
  declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
5
- setAccountSettingsState: (state: Partial<AccountSettingsState>) => {
6
- readonly loading: boolean;
7
- readonly name?: string | undefined;
8
- readonly website?: string | undefined;
9
- readonly error?: any;
10
- readonly address?: string | undefined;
11
- readonly timezone?: string | undefined;
12
- readonly dateFormat?: string | undefined;
13
- readonly timeFormat?: string | undefined;
14
- readonly currency?: string | undefined;
15
- readonly logo?: string | undefined;
16
- };
5
+ setAccountSettingsState: (state: Partial<AccountSettingsState>) => void;
17
6
  resetAccountSettingsState: () => void;
18
7
  saveAccountSettings: (payload: WithCallback<IUpdateSettings, ISettingsResponse>) => Promise<void>;
19
8
  loadAccountSettings: (payload?: WithCallback<WithSilentLoad>) => Promise<void>;
@@ -1,14 +1,12 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["activeTenant", "tenants"];
4
- import { snapshot } from 'valtio/vanilla';
5
4
  import { initialState } from './state';
6
5
  import { errorHandler, deepClone } from '../../helpers';
7
6
  export default ((store, api, sharedActions) => {
8
7
  const actions = sharedActions;
9
8
  const setAccountSettingsState = state => {
10
9
  Object.assign(store.auth.accountSettingsState, state);
11
- return snapshot(store.auth.accountSettingsState);
12
10
  };
13
11
  const resetAccountSettingsState = () => {
14
12
  store.auth.accountSettingsState = deepClone(initialState);
@@ -1,21 +1,8 @@
1
1
  import { FronteggState, WithCallback, SharedActions, RestApi } from '../../interfaces';
2
2
  import { IGetActivateAccountStrategy, IGetActivateAccountStrategyResponse, IResendActivationEmail } from '@frontegg/rest-api';
3
- import { ActivateAccountState, ActivateAccountStep, IActivateAccountPayload, IPreActivateAccount } from './interfaces';
3
+ import { ActivateAccountState, IActivateAccountPayload, IPreActivateAccount } from './interfaces';
4
4
  declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
5
- setActivateState: (state: Partial<ActivateAccountState>) => {
6
- readonly loading: boolean;
7
- readonly error?: any;
8
- readonly step: ActivateAccountStep;
9
- readonly resentEmail: boolean;
10
- readonly activationStrategy: {
11
- readonly loading: boolean;
12
- readonly error?: any;
13
- readonly saving?: boolean | undefined;
14
- readonly strategy?: {
15
- readonly shouldSetPassword: boolean;
16
- } | undefined;
17
- };
18
- };
5
+ setActivateState: (state: Partial<ActivateAccountState>) => void;
19
6
  resetActivateState: () => void;
20
7
  setActivateStrategyState: (state: Partial<ActivateAccountState["activationStrategy"]>) => void;
21
8
  activateAccount: (_payload: WithCallback<IActivateAccountPayload>) => Promise<void>;
@@ -4,7 +4,6 @@ const _excluded = ["callback", "events"],
4
4
  _excluded2 = ["user"],
5
5
  _excluded3 = ["callback"],
6
6
  _excluded4 = ["callback"];
7
- import { snapshot } from 'valtio/vanilla';
8
7
  import { initialState } from './state';
9
8
  import { ContextHolder } from '@frontegg/rest-api';
10
9
  import { errorHandler, deepClone, delay } from '../../helpers';
@@ -17,7 +16,6 @@ export default ((store, api, sharedActions) => {
17
16
  const actions = sharedActions;
18
17
  const setActivateState = state => {
19
18
  Object.assign(store.auth.activateAccountState, state);
20
- return snapshot(store.auth.activateAccountState);
21
19
  };
22
20
  const resetActivateState = () => {
23
21
  store.auth.activateAccountState = deepClone(initialState);
@@ -1,11 +1,7 @@
1
1
  import { FronteggState, SharedActions, RestApi } from '../../interfaces';
2
2
  import { UnlockAccountState, IUnlockAccountPayload } from './interfaces';
3
3
  declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
4
- setUnlockAccountState: (state: Partial<UnlockAccountState>) => {
5
- readonly loading?: boolean | undefined;
6
- readonly error?: any;
7
- readonly unlockAccountSuccess?: boolean | undefined;
8
- };
4
+ setUnlockAccountState: (state: Partial<UnlockAccountState>) => void;
9
5
  resetUnlockAccountState: () => void;
10
6
  unlockAccount: (_payload: IUnlockAccountPayload) => Promise<void>;
11
7
  };
@@ -1,11 +1,9 @@
1
- import { snapshot } from 'valtio/vanilla';
2
1
  import { initialState } from './state';
3
2
  import { errorHandler, deepClone, delay } from '../../helpers';
4
3
  import { ContextHolder } from '@frontegg/rest-api';
5
4
  export default ((store, api, sharedActions) => {
6
5
  const setUnlockAccountState = state => {
7
6
  Object.assign(store.auth.unlockAccountState, state);
8
- return snapshot(store.auth.unlockAccountState);
9
7
  };
10
8
  const resetUnlockAccountState = () => {
11
9
  store.auth.activateAccountState = deepClone(initialState);
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.3.0-alpha.0
1
+ /** @license Frontegg v7.4.0-alpha.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -1,9 +1,6 @@
1
1
  import { FronteggState, RestApi, SharedActions } from '../../interfaces';
2
2
  declare const _default: (store: FronteggState, api: RestApi, actions: SharedActions) => {
3
- setAcceptInvitationState: (state: Partial<import("../..").AcceptInvitationState>) => {
4
- readonly error?: string | undefined;
5
- readonly step: import("../..").AcceptInvitationStep;
6
- };
3
+ setAcceptInvitationState: (state: Partial<import("../..").AcceptInvitationState>) => void;
7
4
  resetAcceptInvitationState: () => void;
8
5
  acceptInvitation: (payload: import("@frontegg/rest-api").IAcceptInvitation) => Promise<void>;
9
6
  };
@@ -1,18 +1,7 @@
1
1
  import { FronteggState, RestApi, SharedActions, WithCallback, WithSilentLoad } from '../../interfaces';
2
2
  import { ISettingsResponse, IUpdateSettings } from '@frontegg/rest-api';
3
3
  declare const _default: (store: FronteggState, api: RestApi, actions: SharedActions) => {
4
- setAccountSettingsState: (state: Partial<import("../..").AccountSettingsState>) => {
5
- readonly loading: boolean;
6
- readonly name?: string | undefined;
7
- readonly website?: string | undefined;
8
- readonly error?: any;
9
- readonly address?: string | undefined;
10
- readonly timezone?: string | undefined;
11
- readonly dateFormat?: string | undefined;
12
- readonly timeFormat?: string | undefined;
13
- readonly currency?: string | undefined;
14
- readonly logo?: string | undefined;
15
- };
4
+ setAccountSettingsState: (state: Partial<import("../..").AccountSettingsState>) => void;
16
5
  resetAccountSettingsState: () => void;
17
6
  saveAccountSettings: (payload: WithCallback<IUpdateSettings, ISettingsResponse>) => Promise<void>;
18
7
  loadAccountSettings: (payload?: WithCallback<WithSilentLoad>) => Promise<void>;
@@ -1,19 +1,6 @@
1
1
  import { FronteggState, RestApi, SharedActions } from '../../interfaces';
2
2
  declare const _default: (store: FronteggState, api: RestApi, actions: SharedActions) => {
3
- setActivateState: (state: Partial<import("../..").ActivateAccountState>) => {
4
- readonly loading: boolean;
5
- readonly error?: any;
6
- readonly step: import("../..").ActivateAccountStep;
7
- readonly resentEmail: boolean;
8
- readonly activationStrategy: {
9
- readonly loading: boolean;
10
- readonly error?: any;
11
- readonly saving?: boolean | undefined;
12
- readonly strategy?: {
13
- readonly shouldSetPassword: boolean;
14
- } | undefined;
15
- };
16
- };
3
+ setActivateState: (state: Partial<import("../..").ActivateAccountState>) => void;
17
4
  resetActivateState: () => void;
18
5
  setActivateStrategyState: (state: Partial<import("../..").ActivateAccountState["activationStrategy"]>) => void;
19
6
  activateAccount: (_payload: import("../../interfaces").WithCallback<import("../..").IActivateAccountPayload>) => Promise<void>;
@@ -1,10 +1,6 @@
1
1
  import { FronteggState, RestApi, SharedActions } from '../../interfaces';
2
2
  declare const _default: (store: FronteggState, api: RestApi, actions: SharedActions) => {
3
- setUnlockAccountState: (state: Partial<import("../..").UnlockAccountState>) => {
4
- readonly loading?: boolean | undefined;
5
- readonly error?: any;
6
- readonly unlockAccountSuccess?: boolean | undefined;
7
- };
3
+ setUnlockAccountState: (state: Partial<import("../..").UnlockAccountState>) => void;
8
4
  resetUnlockAccountState: () => void;
9
5
  unlockAccount: (_payload: import("../..").IUnlockAccountPayload) => Promise<void>;
10
6
  };
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _vanilla = require("valtio/vanilla");
8
7
  var _interfaces = require("./interfaces");
9
8
  var _state = require("./state");
10
9
  var _helpers = require("../../helpers");
@@ -12,7 +11,6 @@ var _default = (store, api, sharedActions) => {
12
11
  const actions = sharedActions;
13
12
  const setAcceptInvitationState = state => {
14
13
  Object.assign(store.auth.acceptInvitationState, state);
15
- return (0, _vanilla.snapshot)(store.auth.acceptInvitationState);
16
14
  };
17
15
  const resetAcceptInvitationState = () => {
18
16
  store.auth.acceptInvitationState = (0, _helpers.deepClone)(_state.initialState);
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
- var _vanilla = require("valtio/vanilla");
11
10
  var _state = require("./state");
12
11
  var _helpers = require("../../helpers");
13
12
  const _excluded = ["activeTenant", "tenants"];
@@ -15,7 +14,6 @@ var _default = (store, api, sharedActions) => {
15
14
  const actions = sharedActions;
16
15
  const setAccountSettingsState = state => {
17
16
  Object.assign(store.auth.accountSettingsState, state);
18
- return (0, _vanilla.snapshot)(store.auth.accountSettingsState);
19
17
  };
20
18
  const resetAccountSettingsState = () => {
21
19
  store.auth.accountSettingsState = (0, _helpers.deepClone)(_state.initialState);
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
- var _vanilla = require("valtio/vanilla");
11
10
  var _state = require("./state");
12
11
  var _restApi = require("@frontegg/rest-api");
13
12
  var _helpers = require("../../helpers");
@@ -24,7 +23,6 @@ var _default = (store, api, sharedActions) => {
24
23
  const actions = sharedActions;
25
24
  const setActivateState = state => {
26
25
  Object.assign(store.auth.activateAccountState, state);
27
- return (0, _vanilla.snapshot)(store.auth.activateAccountState);
28
26
  };
29
27
  const resetActivateState = () => {
30
28
  store.auth.activateAccountState = (0, _helpers.deepClone)(_state.initialState);
@@ -4,14 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _vanilla = require("valtio/vanilla");
8
7
  var _state = require("./state");
9
8
  var _helpers = require("../../helpers");
10
9
  var _restApi = require("@frontegg/rest-api");
11
10
  var _default = (store, api, sharedActions) => {
12
11
  const setUnlockAccountState = state => {
13
12
  Object.assign(store.auth.unlockAccountState, state);
14
- return (0, _vanilla.snapshot)(store.auth.unlockAccountState);
15
13
  };
16
14
  const resetUnlockAccountState = () => {
17
15
  store.auth.activateAccountState = (0, _helpers.deepClone)(_state.initialState);
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.3.0-alpha.0
1
+ /** @license Frontegg v7.4.0-alpha.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  var _exportNames = {
8
8
  FronteggNativeModule: true,
9
9
  snapshot: true,
10
- subscribe: true
10
+ subscribe: true,
11
+ createProxy: true
11
12
  };
12
13
  Object.defineProperty(exports, "FronteggNativeModule", {
13
14
  enumerable: true,
@@ -15,16 +16,22 @@ Object.defineProperty(exports, "FronteggNativeModule", {
15
16
  return _FronteggNativeModule.default;
16
17
  }
17
18
  });
19
+ Object.defineProperty(exports, "createProxy", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _proxy.createProxy;
23
+ }
24
+ });
18
25
  Object.defineProperty(exports, "snapshot", {
19
26
  enumerable: true,
20
27
  get: function () {
21
- return _vanilla.snapshot;
28
+ return _valtio.snapshot;
22
29
  }
23
30
  });
24
31
  Object.defineProperty(exports, "subscribe", {
25
32
  enumerable: true,
26
33
  get: function () {
27
- return _vanilla.subscribe;
34
+ return _valtio.subscribe;
28
35
  }
29
36
  });
30
37
  var _FronteggNativeModule = _interopRequireDefault(require("./FronteggNativeModule"));
@@ -40,4 +47,5 @@ Object.keys(_store).forEach(function (key) {
40
47
  }
41
48
  });
42
49
  });
43
- var _vanilla = require("valtio/vanilla");
50
+ var _valtio = require("../valtio");
51
+ var _proxy = require("./proxy");
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.createProxy = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _vanilla = require("valtio/vanilla");
9
+ var _valtio = require("../valtio");
10
10
  var _deepmerge = _interopRequireDefault(require("deepmerge"));
11
11
  const createProxy = (initialState, overrideState) => {
12
12
  const deepMergedState = (0, _deepmerge.default)(initialState, (0, _extends2.default)({}, overrideState));
13
- return (0, _vanilla.proxy)((0, _extends2.default)({
13
+ return (0, _valtio.proxy)((0, _extends2.default)({
14
14
  __isProxy: true
15
15
  }, deepMergedState));
16
16
  };
@@ -10,7 +10,7 @@ var _exportNames = {
10
10
  };
11
11
  exports.createStore = exports.createFronteggStore = void 0;
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
- var _utils = require("valtio/vanilla/utils");
13
+ var _valtio = require("../valtio");
14
14
  var _restApi = require("@frontegg/rest-api");
15
15
  var _helpers = require("../helpers");
16
16
  var _auth = require("../auth");
@@ -30,7 +30,6 @@ var _subscriptions = require("../subscriptions");
30
30
  var _vendor = require("../vendor");
31
31
  var _audits = require("../audits");
32
32
  var _setValue = _interopRequireDefault(require("set-value"));
33
- var _vanilla = require("valtio/vanilla");
34
33
  var _auditsBackwardCompatibility = require("../audits-backward-compatibility");
35
34
  var _mocks = _interopRequireDefault(require("../mocks"));
36
35
  var _proxy = require("./proxy");
@@ -131,7 +130,7 @@ const createStore = options => {
131
130
  audits: oldAuditsState
132
131
  });
133
132
  if (typeof window !== 'undefined' && (localStorage['DEBUG_FRONTEGG_STORE'] === 'true' || process.env.NODE_ENV === 'development')) {
134
- (0, _utils.devtools)(store, {
133
+ (0, _valtio.devtools)(store, {
135
134
  name: `${appName} Store`,
136
135
  enabled: true
137
136
  });
@@ -179,7 +178,7 @@ const createStore = options => {
179
178
  });
180
179
  },
181
180
  getState: () => store,
182
- subscribe: callback => (0, _vanilla.subscribe)(store, callback),
181
+ subscribe: callback => (0, _valtio.subscribe)(store, callback),
183
182
  store,
184
183
  actions,
185
184
  stateActions
@@ -223,7 +222,7 @@ const createStore = options => {
223
222
  }
224
223
  },
225
224
  getState: () => store,
226
- subscribe: callback => (0, _vanilla.subscribe)(store, callback),
225
+ subscribe: callback => (0, _valtio.subscribe)(store, callback),
227
226
  store,
228
227
  actions,
229
228
  stateActions
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _utils = require("./utils");
7
+ Object.keys(_utils).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _utils[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _utils[key];
14
+ }
15
+ });
16
+ });
17
+ var _valtio = require("./valtio");
18
+ Object.keys(_valtio).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _valtio[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _valtio[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.devtools = devtools;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
+ var _valtio = require("../valtio");
11
+ const _excluded = ["enabled", "name"];
12
+ const DEVTOOLS = Symbol();
13
+ /**
14
+ * devtools
15
+ *
16
+ * This is to connect with [Redux DevTools Extension](https://github.com/reduxjs/redux-devtools).
17
+ * Limitation: Only plain objects/values are supported.
18
+ *
19
+ * @example
20
+ * import { devtools } from 'valtio/utils'
21
+ * const state = proxy({ count: 0, text: 'hello' })
22
+ * const unsub = devtools(state, { name: 'state name', enabled: true })
23
+ */
24
+ function devtools(proxyObject, options) {
25
+ if (typeof options === 'string') {
26
+ // console.warn('string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400');
27
+ options = {
28
+ name: options
29
+ };
30
+ }
31
+ const _ref = options || {},
32
+ {
33
+ enabled,
34
+ name = ''
35
+ } = _ref,
36
+ rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
37
+
38
+ // @ts-ignore
39
+ let extension;
40
+ try {
41
+ // @ts-ignore
42
+ extension = enabled && window.__REDUX_DEVTOOLS_EXTENSION__;
43
+ } catch {
44
+ // ignored
45
+ }
46
+ if (!extension) {
47
+ // @ts-ignore
48
+ // TODO: console.warn('[Warning] Please install/enable Redux devtools extension');
49
+ return;
50
+ }
51
+ let isTimeTraveling = false;
52
+ const devtools = extension.connect((0, _extends2.default)({
53
+ name
54
+ }, rest));
55
+ const unsub1 = (0, _valtio.subscribe)(proxyObject, ops => {
56
+ const action = ops.filter(([_, path]) => path[0] !== DEVTOOLS).map(([op, path]) => `${op}:${path.map(String).join('.')}`).join(', ');
57
+ if (!action) {
58
+ return;
59
+ }
60
+ if (isTimeTraveling) {
61
+ isTimeTraveling = false;
62
+ } else {
63
+ const snapWithoutDevtools = Object.assign({}, (0, _valtio.snapshot)(proxyObject));
64
+ delete snapWithoutDevtools[DEVTOOLS];
65
+ devtools.send({
66
+ type: action,
67
+ updatedAt: new Date().toLocaleString()
68
+ }, snapWithoutDevtools);
69
+ }
70
+ });
71
+ const unsub2 = devtools.subscribe(message => {
72
+ var _message$payload3, _message$payload4;
73
+ if (message.type === 'ACTION' && message.payload) {
74
+ try {
75
+ Object.assign(proxyObject, JSON.parse(message.payload));
76
+ } catch (e) {
77
+ console.error('please dispatch a serializable value that JSON.parse() and proxy() support\n', e);
78
+ }
79
+ }
80
+ if (message.type === 'DISPATCH' && message.state) {
81
+ var _message$payload, _message$payload2;
82
+ if (((_message$payload = message.payload) == null ? void 0 : _message$payload.type) === 'JUMP_TO_ACTION' || ((_message$payload2 = message.payload) == null ? void 0 : _message$payload2.type) === 'JUMP_TO_STATE') {
83
+ isTimeTraveling = true;
84
+ const state = JSON.parse(message.state);
85
+ Object.assign(proxyObject, state);
86
+ }
87
+ proxyObject[DEVTOOLS] = message;
88
+ } else if (message.type === 'DISPATCH' && ((_message$payload3 = message.payload) == null ? void 0 : _message$payload3.type) === 'COMMIT') {
89
+ devtools.init((0, _valtio.snapshot)(proxyObject));
90
+ } else if (message.type === 'DISPATCH' && ((_message$payload4 = message.payload) == null ? void 0 : _message$payload4.type) === 'IMPORT_STATE') {
91
+ var _message$payload$next, _message$payload$next2;
92
+ const actions = (_message$payload$next = message.payload.nextLiftedState) == null ? void 0 : _message$payload$next.actionsById;
93
+ const computedStates = ((_message$payload$next2 = message.payload.nextLiftedState) == null ? void 0 : _message$payload$next2.computedStates) || [];
94
+ isTimeTraveling = true;
95
+ computedStates.forEach(({
96
+ state
97
+ }, index) => {
98
+ const action = actions[index] || 'No action found';
99
+ Object.assign(proxyObject, state);
100
+ if (index === 0) {
101
+ devtools.init((0, _valtio.snapshot)(proxyObject));
102
+ } else {
103
+ devtools.send(action, (0, _valtio.snapshot)(proxyObject));
104
+ }
105
+ });
106
+ }
107
+ });
108
+ devtools.init((0, _valtio.snapshot)(proxyObject));
109
+ return () => {
110
+ unsub1();
111
+ unsub2 == null ? void 0 : unsub2();
112
+ };
113
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "devtools", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _devtools.devtools;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "proxyMap", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _proxyMap.proxyMap;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "proxySet", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _proxySet.proxySet;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "proxyWithComputed", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _proxyWithComputed.proxyWithComputed_DEPRECATED;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "proxyWithHistory", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _proxyWithHistory.proxyWithHistory_DEPRECATED;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "subscribeKey", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _subscribeKey.subscribeKey;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "watch", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _watch.watch;
46
+ }
47
+ });
48
+ var _subscribeKey = require("./subscribeKey");
49
+ var _watch = require("./watch");
50
+ var _devtools = require("./devtools");
51
+ var _proxyWithComputed = require("./proxyWithComputed");
52
+ var _proxyWithHistory = require("./proxyWithHistory");
53
+ var _proxySet = require("./proxySet");
54
+ var _proxyMap = require("./proxyMap");