@tamagui/use-store 1.114.4 → 1.115.1

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.
@@ -3,15 +3,21 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
15
21
  var comparators_exports = {};
16
22
  __export(comparators_exports, {
17
23
  isEqualSubsetShallow: () => isEqualSubsetShallow
@@ -23,11 +29,9 @@ const isEqualSubsetShallow = (a, b, opts) => {
23
29
  if (typeof b == "object") {
24
30
  for (const key in b) {
25
31
  const compare = opts?.keyComparators?.[key];
26
- if (compare ? !compare(a[key], b[key]) : b[key] !== a[key])
27
- return !1;
32
+ if (compare ? !compare(a[key], b[key]) : b[key] !== a[key]) return !1;
28
33
  }
29
34
  return !0;
30
35
  }
31
36
  return a === b;
32
- };
33
- //# sourceMappingURL=comparators.js.map
37
+ };
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var configureUseStore_exports = {};
22
+ __export(configureUseStore_exports, {
23
+ configureOpts: () => configureOpts,
24
+ configureUseStore: () => configureUseStore
25
+ });
26
+ module.exports = __toCommonJS(configureUseStore_exports);
27
+ let configureOpts = {};
28
+ function configureUseStore(opts) {
29
+ configureOpts = opts;
30
+ }
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var constants_exports = {};
22
+ __export(constants_exports, {
23
+ UNWRAP_PROXY: () => UNWRAP_PROXY,
24
+ defaultOptions: () => defaultOptions
25
+ });
26
+ module.exports = __toCommonJS(constants_exports);
27
+ const UNWRAP_PROXY = Symbol(),
28
+ defaultOptions = {
29
+ once: !1,
30
+ selector: void 0
31
+ };
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var decorators_exports = {};
22
+ __export(decorators_exports, {
23
+ compare: () => compare
24
+ });
25
+ module.exports = __toCommonJS(decorators_exports);
26
+ function compare(comparator) {
27
+ return (target, propertyKey) => {
28
+ target._comparators = target._comparators || {}, target._comparators[propertyKey] = comparator;
29
+ };
30
+ }
@@ -3,15 +3,21 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
15
21
  var helpers_exports = {};
16
22
  __export(helpers_exports, {
17
23
  UNWRAP_STORE_INFO: () => UNWRAP_STORE_INFO,
@@ -25,17 +31,17 @@ __export(helpers_exports, {
25
31
  module.exports = __toCommonJS(helpers_exports);
26
32
  var import_simple_hash = require("@tamagui/simple-hash");
27
33
  function getStoreUid(Constructor, props) {
28
- return (0, import_simple_hash.simpleHash)(
29
- `${Constructor}${props ? typeof props == "string" ? props : JSON.stringify(props) : ""}`,
30
- "strict"
31
- );
34
+ return (0, import_simple_hash.simpleHash)(`${Constructor}${props ? typeof props == "string" ? props : JSON.stringify(props) : ""}`, "strict");
32
35
  }
33
- const UNWRAP_STORE_INFO = Symbol("UNWRAP_STORE_INFO"), cache = /* @__PURE__ */ new Map();
36
+ const UNWRAP_STORE_INFO = Symbol("UNWRAP_STORE_INFO"),
37
+ cache = /* @__PURE__ */new Map();
34
38
  function getStoreDescriptors(storeInstance) {
35
- const proto = Object.getPrototypeOf(storeInstance), instanceDescriptors = Object.getOwnPropertyDescriptors(storeInstance), descriptors = {
36
- ...Object.getOwnPropertyDescriptors(proto),
37
- ...instanceDescriptors
38
- };
39
+ const proto = Object.getPrototypeOf(storeInstance),
40
+ instanceDescriptors = Object.getOwnPropertyDescriptors(storeInstance),
41
+ descriptors = {
42
+ ...Object.getOwnPropertyDescriptors(proto),
43
+ ...instanceDescriptors
44
+ };
39
45
  return delete descriptors.constructor, descriptors;
40
46
  }
41
47
  function get(_, b) {
@@ -46,5 +52,4 @@ function simpleStr(arg) {
46
52
  }
47
53
  function getStoreDebugInfo(store) {
48
54
  return store[UNWRAP_STORE_INFO] ?? cache.get(getStoreUid(store.constructor, store.props));
49
- }
50
- //# sourceMappingURL=helpers.js.map
55
+ }
@@ -0,0 +1,40 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ },
18
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
20
+ value: !0
21
+ }), mod);
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ Store: () => Store,
25
+ UNWRAP_PROXY: () => import_constants.UNWRAP_PROXY,
26
+ configureUseStore: () => import_configureUseStore.configureUseStore
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+ __reExport(src_exports, require("./useStore.cjs"), module.exports);
30
+ var import_configureUseStore = require("./configureUseStore.cjs");
31
+ __reExport(src_exports, require("./interfaces.cjs"), module.exports);
32
+ __reExport(src_exports, require("./observe.cjs"), module.exports);
33
+ var import_constants = require("./constants.cjs");
34
+ __reExport(src_exports, require("./comparators.cjs"), module.exports);
35
+ __reExport(src_exports, require("./decorators.cjs"), module.exports);
36
+ class Store {
37
+ constructor(props) {
38
+ this.props = props;
39
+ }
40
+ }
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
+ get: () => from[key],
8
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
+ });
10
+ return to;
11
+ };
12
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
13
+ value: !0
14
+ }), mod);
15
+ var interfaces_exports = {};
16
+ module.exports = __toCommonJS(interfaces_exports);
@@ -2,37 +2,52 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
6
7
  var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
15
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
21
  // If the importer is in node compatibility mode or this is not an ESM
17
22
  // file that has been converted to a CommonJS file using a Babel-
18
23
  // compatible transform (i.e. "__esModule" has not been set), then set
19
24
  // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
23
32
  var observe_exports = {};
24
33
  __export(observe_exports, {
25
34
  observe: () => observe,
26
35
  useObserve: () => useObserve
27
36
  });
28
37
  module.exports = __toCommonJS(observe_exports);
29
- var import_react = __toESM(require("react")), import_comparators = require("./comparators"), import_constants = require("./constants"), import_useStore = require("./useStore");
38
+ var import_react = __toESM(require("react")),
39
+ import_comparators = require("./comparators.cjs"),
40
+ import_constants = require("./constants.cjs"),
41
+ import_useStore = require("./useStore.cjs");
30
42
  const logUpdate = process.env.NODE_ENV === "development" ? (fn, stores, last, next) => {
31
- const getStoreLogName = (store) => `${(store[import_constants.UNWRAP_PROXY] ?? store).constructor.name}${store.props?.id ? `:${store.props.id}` : ""}`, storeNames = stores.map(getStoreLogName).join(", "), name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
43
+ const getStoreLogName = store => `${(store[import_constants.UNWRAP_PROXY] ?? store).constructor.name}${store.props?.id ? `:${store.props.id}` : ""}`,
44
+ storeNames = stores.map(getStoreLogName).join(", "),
45
+ name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
32
46
  console.groupCollapsed(name, "color: tomato;"), console.groupCollapsed("trace >"), console.trace(), console.groupEnd(), console.info(" next", next), console.groupEnd();
33
47
  } : null;
34
48
  function observe(fn) {
35
- let prev = getObserverValueAndStoresAccessed(fn), disposeValue = null;
49
+ let prev = getObserverValueAndStoresAccessed(fn),
50
+ disposeValue = null;
36
51
  const subscribe = () => {
37
52
  const stores = [...prev.storeInfos];
38
53
  return subscribeToStores(stores, () => {
@@ -59,22 +74,26 @@ function useObserve(fn) {
59
74
  let dispose;
60
75
  const unsub = subscribeToStores([...state.storeInfos], () => {
61
76
  dispose?.();
62
- const next = getObserverValueAndStoresAccessed(fn), nextStoreInfos = [...next.storeInfos], prevStoreInfos = [...state.storeInfos];
77
+ const next = getObserverValueAndStoresAccessed(fn),
78
+ nextStoreInfos = [...next.storeInfos],
79
+ prevStoreInfos = [...state.storeInfos];
63
80
  if (typeof next.value == "function") {
64
81
  process.env.NODE_ENV === "development" && logUpdate(fn, nextStoreInfos, "(fn)", "(fn)"), dispose = next.value;
65
82
  return;
66
83
  }
67
- setState((prev) => (0, import_comparators.isEqualSubsetShallow)(prevStoreInfos, nextStoreInfos) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value) ? prev : (process.env.NODE_ENV === "development" && logUpdate(fn, nextStoreInfos, prev.value, next.value), next));
84
+ setState(prev => (0, import_comparators.isEqualSubsetShallow)(prevStoreInfos, nextStoreInfos) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value) ? prev : (process.env.NODE_ENV === "development" && logUpdate(fn, nextStoreInfos, prev.value, next.value), next));
68
85
  });
69
86
  return () => {
70
87
  unsub(), dispose?.();
71
88
  };
72
- }, [[...state.storeInfos].map((i) => i.uid).join(",")]), state.value;
89
+ }, [[...state.storeInfos].map(i => i.uid).join(",")]), state.value;
73
90
  }
74
91
  function getObserverValueAndStoresAccessed(selector) {
75
- const storeInfos = /* @__PURE__ */ new Set(), dispose = (0, import_useStore.trackStoresAccess)((storeInfo) => {
76
- storeInfos.add(storeInfo);
77
- }), value = selector();
92
+ const storeInfos = /* @__PURE__ */new Set(),
93
+ dispose = (0, import_useStore.trackStoresAccess)(storeInfo => {
94
+ storeInfos.add(storeInfo);
95
+ }),
96
+ value = selector();
78
97
  return dispose(), {
79
98
  value,
80
99
  storeInfos
@@ -86,20 +105,16 @@ function subscribeToStores(storeInfos, onUpdate) {
86
105
  const onUpdateDebouncedWithoutTracking = () => {
87
106
  isUpdating || (isUpdating = !0, queueMicrotask(() => {
88
107
  try {
89
- for (const storeInfo of storeInfos)
90
- storeInfo.disableTracking = !0;
108
+ for (const storeInfo of storeInfos) storeInfo.disableTracking = !0;
91
109
  onUpdate();
92
110
  } finally {
93
111
  isUpdating = !1;
94
- for (const storeInfo of storeInfos)
95
- storeInfo.disableTracking = !1;
112
+ for (const storeInfo of storeInfos) storeInfo.disableTracking = !1;
96
113
  }
97
114
  }));
98
115
  };
99
- for (const storeInfo of storeInfos)
100
- disposes.push(storeInfo.subscribe(onUpdateDebouncedWithoutTracking));
116
+ for (const storeInfo of storeInfos) disposes.push(storeInfo.subscribe(onUpdateDebouncedWithoutTracking));
101
117
  return () => {
102
- disposes.forEach((x) => x());
118
+ disposes.forEach(x => x());
103
119
  };
104
- }
105
- //# sourceMappingURL=observe.js.map
120
+ }