valdres 0.2.0-alpha.37 → 0.2.0-alpha.39

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 (69) hide show
  1. package/dist/index.js +61 -61
  2. package/package.json +2 -2
  3. package/dist/types/index.d.ts +0 -29
  4. package/dist/types/src/atom.d.ts +0 -16
  5. package/dist/types/src/atomFamily.d.ts +0 -4
  6. package/dist/types/src/createStoreWithSelectorSet.d.ts +0 -2
  7. package/dist/types/src/globalStore.d.ts +0 -4
  8. package/dist/types/src/lib/atomFamilyAtom.d.ts +0 -8
  9. package/dist/types/src/lib/createAtomFamily.d.ts +0 -4
  10. package/dist/types/src/lib/createGlobalAtomFamily.d.ts +0 -5
  11. package/dist/types/src/lib/createStoreData.d.ts +0 -3
  12. package/dist/types/src/lib/equal.d.ts +0 -1
  13. package/dist/types/src/lib/getState.d.ts +0 -7
  14. package/dist/types/src/lib/globalAtom.d.ts +0 -4
  15. package/dist/types/src/lib/initAtom.d.ts +0 -5
  16. package/dist/types/src/lib/initSelector.d.ts +0 -4
  17. package/dist/types/src/lib/propagateUpdatedAtoms.d.ts +0 -4
  18. package/dist/types/src/lib/resetAtom.d.ts +0 -3
  19. package/dist/types/src/lib/setAtom.d.ts +0 -3
  20. package/dist/types/src/lib/setAtoms.d.ts +0 -3
  21. package/dist/types/src/lib/stableStringify.d.ts +0 -1
  22. package/dist/types/src/lib/storeFromStoreData.d.ts +0 -4
  23. package/dist/types/src/lib/subscribe.d.ts +0 -4
  24. package/dist/types/src/lib/transaction.d.ts +0 -9
  25. package/dist/types/src/lib/unsubscribe.d.ts +0 -5
  26. package/dist/types/src/lib/updateSelectorSubscribers.d.ts +0 -3
  27. package/dist/types/src/lib/updateStateSubscribers.d.ts +0 -3
  28. package/dist/types/src/selector.d.ts +0 -4
  29. package/dist/types/src/selectorFamily.d.ts +0 -4
  30. package/dist/types/src/store.d.ts +0 -1
  31. package/dist/types/src/types/Atom.d.ts +0 -14
  32. package/dist/types/src/types/AtomDefaultValue.d.ts +0 -2
  33. package/dist/types/src/types/AtomFamily.d.ts +0 -12
  34. package/dist/types/src/types/AtomFamilyAtom.d.ts +0 -6
  35. package/dist/types/src/types/AtomFamilyDefaultValue.d.ts +0 -5
  36. package/dist/types/src/types/AtomFamilyGlobalAtom.d.ts +0 -3
  37. package/dist/types/src/types/AtomFamilySelector.d.ts +0 -6
  38. package/dist/types/src/types/AtomOnInit.d.ts +0 -2
  39. package/dist/types/src/types/AtomOnSet.d.ts +0 -2
  40. package/dist/types/src/types/AtomOptions.d.ts +0 -13
  41. package/dist/types/src/types/EqualFunc.d.ts +0 -1
  42. package/dist/types/src/types/Family.d.ts +0 -3
  43. package/dist/types/src/types/FamilyKey.d.ts +0 -3
  44. package/dist/types/src/types/GetValue.d.ts +0 -8
  45. package/dist/types/src/types/GlobalAtom.d.ts +0 -11
  46. package/dist/types/src/types/GlobalAtomGetSelfFunc.d.ts +0 -1
  47. package/dist/types/src/types/GlobalAtomResetSelfFunc.d.ts +0 -1
  48. package/dist/types/src/types/GlobalAtomSetSelfFunc.d.ts +0 -1
  49. package/dist/types/src/types/ResetAtom.d.ts +0 -2
  50. package/dist/types/src/types/Selector.d.ts +0 -11
  51. package/dist/types/src/types/SelectorFamily.d.ts +0 -6
  52. package/dist/types/src/types/SelectorOptions.d.ts +0 -5
  53. package/dist/types/src/types/SetAtom.d.ts +0 -3
  54. package/dist/types/src/types/SetAtomValue.d.ts +0 -1
  55. package/dist/types/src/types/State.d.ts +0 -4
  56. package/dist/types/src/types/Store.d.ts +0 -24
  57. package/dist/types/src/types/StoreData.d.ts +0 -17
  58. package/dist/types/src/types/SubscribeFn.d.ts +0 -2
  59. package/dist/types/src/types/Subscription.d.ts +0 -1
  60. package/dist/types/src/types/TransactionFn.d.ts +0 -4
  61. package/dist/types/src/utils/isAtom.d.ts +0 -2
  62. package/dist/types/src/utils/isAtomFamily.d.ts +0 -2
  63. package/dist/types/src/utils/isFamily.d.ts +0 -1
  64. package/dist/types/src/utils/isFamilyAtom.d.ts +0 -2
  65. package/dist/types/src/utils/isFamilySelector.d.ts +0 -2
  66. package/dist/types/src/utils/isFamilyState.d.ts +0 -3
  67. package/dist/types/src/utils/isPromiseLike.d.ts +0 -1
  68. package/dist/types/src/utils/isSelector.d.ts +0 -2
  69. package/dist/types/src/utils/isSelectorFamily.d.ts +0 -2
package/dist/index.js CHANGED
@@ -132,7 +132,7 @@ var isSelectorFamily = (state) => state && Object.hasOwn(state, "__valdresSelect
132
132
 
133
133
  // src/lib/setAtom.ts
134
134
  var setAtom = (atom, newValue, data, skipOnSet = false) => {
135
- const currentValue = getState(atom, data);
135
+ const currentValue = getState2(atom, data);
136
136
  if (typeof newValue === "function") {
137
137
  newValue = newValue(currentValue);
138
138
  if (isPromiseLike(newValue) || isPromiseLike(currentValue))
@@ -146,7 +146,7 @@ var setAtom = (atom, newValue, data, skipOnSet = false) => {
146
146
  if (currentValue?.__isEmptyAtomPromise__) {
147
147
  currentValue.__resolveEmptyAtomPromise__(newValue);
148
148
  }
149
- propagateUpdatedAtoms([atom], data);
149
+ propagateUpdatedAtoms2([atom], data);
150
150
  };
151
151
 
152
152
  // src/lib/initAtom.ts
@@ -164,12 +164,12 @@ var getAtomInitValue = (atom, data) => {
164
164
  if (isPromiseLike(value)) {
165
165
  value.then((resolvedValue) => {
166
166
  data.values.set(atom, resolvedValue);
167
- propagateUpdatedAtoms([atom], data);
167
+ propagateUpdatedAtoms2([atom], data);
168
168
  });
169
169
  }
170
170
  return value;
171
171
  } else if (isSelector(atom.defaultValue)) {
172
- return getState(atom.defaultValue, data);
172
+ return getState2(atom.defaultValue, data);
173
173
  } else {
174
174
  return atom.defaultValue;
175
175
  }
@@ -178,7 +178,7 @@ var initAtom = (atom, data) => {
178
178
  let value = getAtomInitValue(atom, data);
179
179
  data.values.set(atom, value);
180
180
  if (isFamilyAtom(atom)) {
181
- const currentKeySet = getState(atom.family.__keysAtom, data);
181
+ const currentKeySet = getState2(atom.family.__keysAtom, data);
182
182
  if (!currentKeySet.has(atom.familyKey)) {
183
183
  const newSet = new Set(currentKeySet);
184
184
  newSet.add(atom.familyKey);
@@ -194,22 +194,22 @@ var initAtom = (atom, data) => {
194
194
  };
195
195
 
196
196
  // src/lib/getState.ts
197
- function getState(state, data) {
197
+ function getState2(state, data) {
198
198
  if (data.values.has(state))
199
199
  return data.values.get(state);
200
200
  if (isAtom(state)) {
201
201
  if ("parent" in data)
202
- return getState(state, data.parent);
202
+ return getState2(state, data.parent);
203
203
  return initAtom(state, data);
204
204
  }
205
205
  if (isSelector(state))
206
- return initSelector(state, data);
206
+ return initSelector2(state, data);
207
207
  if (isAtomFamily(state)) {
208
208
  if ("parent" in data) {
209
209
  const closestData = findClosestStoreWithAtomInitialized(state.__keysAtom, data);
210
- return getState(state.__keysSelector, closestData);
210
+ return getState2(state.__keysSelector, closestData);
211
211
  }
212
- return getState(state.__keysSelector, data);
212
+ return getState2(state.__keysSelector, data);
213
213
  }
214
214
  if (isSelectorFamily(state)) {
215
215
  const array = Array.from(state.__valdresSelectorFamilyMap.keys());
@@ -249,7 +249,7 @@ var evaluateSelector = (selector, data) => {
249
249
  let result;
250
250
  try {
251
251
  result = selector.get((state) => {
252
- const value = getState(state, data);
252
+ const value = getState2(state, data);
253
253
  updatedDependencies.add(state);
254
254
  if (isPromiseLike(value))
255
255
  throw new SuspendAndWaitForResolveError(value);
@@ -278,7 +278,7 @@ var evaluateSelector = (selector, data) => {
278
278
  };
279
279
  var handleSelectorResult = (value, selector, data) => {
280
280
  if (value instanceof SuspendAndWaitForResolveError) {
281
- value.promise.then(() => initSelector(selector, data));
281
+ value.promise.then(() => initSelector2(selector, data));
282
282
  return value.promise;
283
283
  } else if (isPromiseLike(value)) {
284
284
  value.then((resolved) => {
@@ -291,7 +291,7 @@ var handleSelectorResult = (value, selector, data) => {
291
291
  return value;
292
292
  }
293
293
  };
294
- var initSelector = (selector, data) => {
294
+ var initSelector2 = (selector, data) => {
295
295
  const tmpValue = evaluateSelector(selector, data);
296
296
  const value = handleSelectorResult(tmpValue, selector, data);
297
297
  if (data.expiredValues.has(selector)) {
@@ -314,7 +314,7 @@ var updateSelectorSubscribers = (selector, data) => {
314
314
  if (subscribtions?.size && data.subscriptionsRequireEqualCheck.get(selector) || familySubscriptions?.size && selector.family && data.subscriptionsRequireEqualCheck.get(selector.family)) {
315
315
  try {
316
316
  const oldValue = data.expiredValues.get(selector);
317
- const newValue = initSelector(selector, data);
317
+ const newValue = initSelector2(selector, data);
318
318
  if (selector.equal(newValue, oldValue))
319
319
  return;
320
320
  } catch (e) {
@@ -346,7 +346,7 @@ var recursivlyResetSelectorTree = (selectors, data, clearedSelectors) => {
346
346
  }
347
347
  }
348
348
  };
349
- var propagateUpdatedAtoms = (atoms, data) => {
349
+ var propagateUpdatedAtoms2 = (atoms, data) => {
350
350
  const clearedSelectors = new Set;
351
351
  for (const atom of atoms) {
352
352
  const consumers = data.stateConsumers.get(atom);
@@ -369,6 +369,17 @@ var propagateUpdatedAtoms = (atoms, data) => {
369
369
  };
370
370
 
371
371
  // src/lib/createStoreData.ts
372
+ function createStoreData(id, parent) {
373
+ if (parent) {
374
+ return {
375
+ ...generateStoreData(id),
376
+ parent,
377
+ scopeConsumers: parent ? new Set : undefined
378
+ };
379
+ } else {
380
+ return generateStoreData(id);
381
+ }
382
+ }
372
383
  var generateId = () => (Math.random() + 1).toString(36).substring(7);
373
384
  var generateStoreData = (id = generateId()) => {
374
385
  return {
@@ -382,24 +393,13 @@ var generateStoreData = (id = generateId()) => {
382
393
  scopes: {}
383
394
  };
384
395
  };
385
- function createStoreData(id, parent) {
386
- if (parent) {
387
- return {
388
- ...generateStoreData(id),
389
- parent,
390
- scopeConsumers: parent ? new Set : undefined
391
- };
392
- } else {
393
- return generateStoreData(id);
394
- }
395
- }
396
396
 
397
397
  // src/lib/resetAtom.ts
398
398
  var resetAtom = (atom, data) => {
399
399
  let value = getAtomInitValue(atom, data);
400
400
  data.values.set(atom, value);
401
401
  if (!isPromiseLike(value)) {
402
- propagateUpdatedAtoms([atom], data);
402
+ propagateUpdatedAtoms2([atom], data);
403
403
  }
404
404
  return value;
405
405
  };
@@ -461,7 +461,7 @@ var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) =>
461
461
  initAtom(state, data);
462
462
  }
463
463
  if (isSelector(state) && !data.values.has(state)) {
464
- initSelector(state, data);
464
+ initSelector2(state, data);
465
465
  }
466
466
  const subscribers = data.subscriptions.get(state) || initSubscribers(state, data);
467
467
  let subscription;
@@ -496,7 +496,7 @@ var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) =>
496
496
  }
497
497
  } else {
498
498
  data.values.set(state, value);
499
- propagateUpdatedAtoms([state], data);
499
+ propagateUpdatedAtoms2([state], data);
500
500
  }
501
501
  }, state.maxAge);
502
502
  maxAgeCleanup = () => {
@@ -506,7 +506,7 @@ var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) =>
506
506
  };
507
507
  }
508
508
  if (state.onMount) {
509
- const store = storeFromStoreData(data);
509
+ const store = storeFromStoreData2(data);
510
510
  const mountSubscriptions = new Set;
511
511
  const originalSub = store.sub;
512
512
  store.sub = (state2, callback2) => {
@@ -534,7 +534,7 @@ var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) =>
534
534
  var setAtoms = (pairs, data) => {
535
535
  const updatedAtoms = [];
536
536
  for (let [atom, value] of pairs) {
537
- const currentValue = getState(atom, data);
537
+ const currentValue = getState2(atom, data);
538
538
  if (!atom.equal(currentValue, value)) {
539
539
  updatedAtoms.push(atom);
540
540
  if (atom.onSet)
@@ -542,7 +542,7 @@ var setAtoms = (pairs, data) => {
542
542
  data.values.set(atom, value);
543
543
  }
544
544
  }
545
- propagateUpdatedAtoms(updatedAtoms, data);
545
+ propagateUpdatedAtoms2(updatedAtoms, data);
546
546
  };
547
547
 
548
548
  // src/lib/transaction.ts
@@ -573,7 +573,7 @@ var transaction = (callback, data) => {
573
573
  let dirtySelectors = new Set;
574
574
  const txnGet = (state) => {
575
575
  if (isAtom(state)) {
576
- return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState(state, data);
576
+ return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState2(state, data);
577
577
  } else if (isSelector(state)) {
578
578
  if (txnSelectorCache.has(state)) {
579
579
  return txnSelectorCache.get(state);
@@ -626,15 +626,8 @@ var transaction = (callback, data) => {
626
626
  };
627
627
 
628
628
  // src/lib/storeFromStoreData.ts
629
- var SelectorProvidedToSetError = `Invalid state object passed to set().
630
- You provided a \`selector\`.
631
- Only \`atom\` cam be set.
632
- `;
633
- var InvalidStateSetError = `Invalid state object passed to set().
634
- Only \`atom\` can be set.
635
- `;
636
- function storeFromStoreData(data, detach) {
637
- const get = (state) => getState(state, data);
629
+ function storeFromStoreData2(data, detach) {
630
+ const get = (state) => getState2(state, data);
638
631
  const set = (state, value) => {
639
632
  if (isAtom(state))
640
633
  return setAtom(state, value, data);
@@ -660,7 +653,7 @@ function storeFromStoreData(data, detach) {
660
653
  }
661
654
  };
662
655
  scopedStoreData.scopeConsumers.add(detach2);
663
- const newStore = storeFromStoreData(data.scopes[scopeId], detach2);
656
+ const newStore = storeFromStoreData2(data.scopes[scopeId], detach2);
664
657
  return newStore;
665
658
  };
666
659
  if (detach) {
@@ -686,14 +679,21 @@ function storeFromStoreData(data, detach) {
686
679
  };
687
680
  }
688
681
  }
682
+ var SelectorProvidedToSetError = `Invalid state object passed to set().
683
+ You provided a \`selector\`.
684
+ Only \`atom\` cam be set.
685
+ `;
686
+ var InvalidStateSetError = `Invalid state object passed to set().
687
+ Only \`atom\` can be set.
688
+ `;
689
689
 
690
690
  // src/store.ts
691
691
  var store = (id) => {
692
692
  const data = createStoreData(id);
693
- return storeFromStoreData(data);
693
+ return storeFromStoreData2(data);
694
694
  };
695
695
  // package.json
696
- var version = "0.2.0-alpha.36";
696
+ var version = "0.2.0-alpha.37";
697
697
 
698
698
  // src/globalStore.ts
699
699
  if (globalThis.__valdres__) {
@@ -728,9 +728,9 @@ var globalAtom = (defaultValue, options) => {
728
728
  const onSet = (newValue, currentStore) => {
729
729
  value = newValue;
730
730
  if (stores.size > 1) {
731
- for (const store2 of stores) {
732
- if (store2.id !== currentStore.id) {
733
- setAtom(atom, value, store2, true);
731
+ for (const store3 of stores) {
732
+ if (store3.id !== currentStore.id) {
733
+ setAtom(atom, value, store3, true);
734
734
  }
735
735
  }
736
736
  }
@@ -740,14 +740,14 @@ var globalAtom = (defaultValue, options) => {
740
740
  const resetSelf = () => {
741
741
  value = undefined;
742
742
  initialized = false;
743
- for (const store2 of stores) {
744
- if (store2.stateDependencies.has(atom)) {
743
+ for (const store3 of stores) {
744
+ if (store3.stateDependencies.has(atom)) {
745
745
  throw new Error("TODO: Reset support for stateDependencies");
746
746
  }
747
- store2.values.delete(atom);
748
- store2.expiredValues.delete(atom);
749
- propagateUpdatedAtoms([atom], store2);
750
- stores.delete(store2);
747
+ store3.values.delete(atom);
748
+ store3.expiredValues.delete(atom);
749
+ propagateUpdatedAtoms2([atom], store3);
750
+ stores.delete(store3);
751
751
  onReset?.();
752
752
  }
753
753
  };
@@ -918,21 +918,21 @@ function atomFamily(defaultValue, options) {
918
918
  return createAtomFamily(defaultValue, options);
919
919
  }
920
920
  // src/createStoreWithSelectorSet.ts
921
- var setSelector = (selector2, values, store2) => {
922
- return selector2.set(store2.set, store2.get, store2.reset, ...values);
921
+ var setSelector = (selector3, values, store3) => {
922
+ return selector3.set(store3.set, store3.get, store3.reset, ...values);
923
923
  };
924
924
  var createStoreWithSelectorSet = (id) => {
925
925
  const data = createStoreData(id);
926
- const store2 = storeFromStoreData(data);
927
- store2.set = (state, value, ...rest) => {
926
+ const store3 = storeFromStoreData2(data);
927
+ store3.set = (state, value, ...rest) => {
928
928
  if (isAtom(state))
929
929
  return setAtom(state, value, data);
930
930
  if (isSelector(state))
931
- return setSelector(state, [value, ...rest], store2);
931
+ return setSelector(state, [value, ...rest], store3);
932
932
  throw new Error("Invalid state object");
933
933
  };
934
- store2.kind = "storeWithSelectorSet";
935
- return store2;
934
+ store3.kind = "storeWithSelectorSet";
935
+ return store3;
936
936
  };
937
937
  // src/selectorFamily.ts
938
938
  var createOptions2 = (options = {}, family, familyKey, keyStringified) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.37",
3
+ "version": "0.2.0-alpha.39",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Eigil Sagafos"
@@ -36,5 +36,5 @@
36
36
  "access": "public",
37
37
  "registry": "https://registry.npmjs.org/"
38
38
  },
39
- "gitHead": "cdde539a5959c4f1da8da2155bf42c872d047997"
39
+ "gitHead": "53245fd1a080cdb1131f5be9056adc546d05ead4"
40
40
  }
@@ -1,29 +0,0 @@
1
- export { atom } from "./src/atom";
2
- export { atomFamily } from "./src/atomFamily";
3
- export { createStoreWithSelectorSet } from "./src/createStoreWithSelectorSet";
4
- export { globalStore } from "./src/globalStore";
5
- export { selector } from "./src/selector";
6
- export { selectorFamily } from "./src/selectorFamily";
7
- export { store } from "./src/store";
8
- export { isAtom } from "./src/utils/isAtom";
9
- export { isAtomFamily } from "./src/utils/isAtomFamily";
10
- export { isFamily } from "./src/utils/isFamily";
11
- export { isFamilyAtom } from "./src/utils/isFamilyAtom";
12
- export { isFamilySelector } from "./src/utils/isFamilySelector";
13
- export { isFamilyState } from "./src/utils/isFamilyState";
14
- export { isPromiseLike } from "./src/utils/isPromiseLike";
15
- export { isSelector } from "./src/utils/isSelector";
16
- export { isSelectorFamily } from "./src/utils/isSelectorFamily";
17
- export type { Atom } from "./src/types/Atom";
18
- export type { AtomFamily } from "./src/types/AtomFamily";
19
- export type { FamilyKey } from "./src/types/FamilyKey";
20
- export type { GetValue } from "./src/types/GetValue";
21
- export type { GlobalAtom } from "./src/types/GlobalAtom";
22
- export type { ResetAtom } from "./src/types/ResetAtom";
23
- export type { Selector } from "./src/types/Selector";
24
- export type { SelectorFamily } from "./src/types/SelectorFamily";
25
- export type { SetAtom } from "./src/types/SetAtom";
26
- export type { SetAtomValue } from "./src/types/SetAtomValue";
27
- export type { State } from "./src/types/State";
28
- export type { Store } from "./src/types/Store";
29
- export type { StoreData } from "./src/types/StoreData";
@@ -1,16 +0,0 @@
1
- import type { Atom } from "./types/Atom";
2
- import type { AtomDefaultValue } from "./types/AtomDefaultValue";
3
- import type { AtomOptions } from "./types/AtomOptions";
4
- import type { GlobalAtom } from "./types/GlobalAtom";
5
- /**
6
- * [Docs Reference](https://valdres.dev/valdres/api/atom)
7
- *
8
- * @example
9
- *
10
- * const user = atom<string>("Default Value", { name: "userAtom"})
11
- *
12
- */
13
- export declare function atom<V>(defaultValue: AtomDefaultValue<V>, options: AtomOptions<V> & {
14
- global: true;
15
- }): GlobalAtom<V>;
16
- export declare function atom<V>(defaultValue?: AtomDefaultValue<V>, options?: AtomOptions<V>): Atom<V>;
@@ -1,4 +0,0 @@
1
- import type { AtomOptions } from "./types/AtomOptions";
2
- import type { FamilyKey } from "./types/FamilyKey";
3
- import type { AtomFamilyDefaultValue } from "./types/AtomFamilyDefaultValue";
4
- export declare function atomFamily<Key = FamilyKey, Value = unknown>(defaultValue?: AtomFamilyDefaultValue<Key, Value>, options?: AtomOptions<Value>): import("..").AtomFamily<Key, Value>;
@@ -1,2 +0,0 @@
1
- import type { Store } from "./types/Store";
2
- export declare const createStoreWithSelectorSet: (id?: string) => Store;
@@ -1,4 +0,0 @@
1
- export declare const globalStore: import("..").Store & {
2
- atoms: Map<any, any>;
3
- atomFamilies: Map<any, any>;
4
- };
@@ -1,8 +0,0 @@
1
- import type { AtomDefaultValue } from "../types/AtomDefaultValue";
2
- import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
3
- import type { AtomFamilyGlobalAtom } from "../types/AtomFamilyGlobalAtom";
4
- import type { AtomOptions } from "../types/AtomOptions";
5
- export declare function atomFamilyAtom<Key, Value>(defaultValue: AtomDefaultValue<Value>, options: AtomOptions<Value> & {
6
- global: true;
7
- }): AtomFamilyGlobalAtom<Key, Value>;
8
- export declare function atomFamilyAtom<Key, Value>(defaultValue: AtomDefaultValue<Value>, options: AtomOptions<Value>): AtomFamilyAtom<Key, Value>;
@@ -1,4 +0,0 @@
1
- import type { AtomFamily } from "../types/AtomFamily";
2
- import type { AtomOptions } from "../types/AtomOptions";
3
- import type { AtomFamilyDefaultValue } from "../types/AtomFamilyDefaultValue";
4
- export declare const createAtomFamily: <Key, Value>(defaultValue: AtomFamilyDefaultValue<Key, Value>, options?: AtomOptions<Value>) => AtomFamily<Key, Value>;
@@ -1,5 +0,0 @@
1
- import type { AtomOptions } from "../types/AtomOptions";
2
- import type { FamilyKey } from "../types/FamilyKey";
3
- import type { AtomFamilyDefaultValue } from "../types/AtomFamilyDefaultValue";
4
- import type { AtomFamily } from "../types/AtomFamily";
5
- export declare const createGlobalAtomFamily: <Key = FamilyKey, Value = unknown>(defaultValue: AtomFamilyDefaultValue<Key, Value>, options: AtomOptions<Value>) => AtomFamily<Key, Value>;
@@ -1,3 +0,0 @@
1
- import type { ScopedStoreData, StoreData } from "../types/StoreData";
2
- export declare function createStoreData(id?: string, parent?: undefined): StoreData;
3
- export declare function createStoreData(id: string, parent: StoreData): ScopedStoreData;
@@ -1 +0,0 @@
1
- export declare const equal: (a: any, b: any) => boolean;
@@ -1,7 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { AtomFamily } from "../types/AtomFamily";
3
- import type { Selector } from "../types/Selector";
4
- import type { StoreData } from "../types/StoreData";
5
- export declare function getState<V, K>(atom: Atom<V>, data: StoreData): V;
6
- export declare function getState<V, K>(selector: Selector<V>, data: StoreData): V;
7
- export declare function getState<V, K>(family: AtomFamily<V, K>, data: StoreData): K[];
@@ -1,4 +0,0 @@
1
- import type { AtomDefaultValue } from "../types/AtomDefaultValue";
2
- import type { AtomOptions } from "./../types/AtomOptions";
3
- import type { GlobalAtom } from "./../types/GlobalAtom";
4
- export declare const globalAtom: <Value = unknown>(defaultValue: AtomDefaultValue<Value>, options: AtomOptions<Value>) => GlobalAtom<Value>;
@@ -1,5 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
3
- import type { StoreData } from "../types/StoreData";
4
- export declare const getAtomInitValue: <V>(atom: Atom<V>, data: StoreData) => any;
5
- export declare const initAtom: <V, K>(atom: Atom<V> | AtomFamilyAtom<K, V>, data: StoreData) => any;
@@ -1,4 +0,0 @@
1
- import type { StoreData } from "../types/StoreData";
2
- import type { Selector } from "../types/Selector";
3
- export declare const reEvaluateSelector: <V>(selector: Selector<V>, data: StoreData) => void;
4
- export declare const initSelector: <V>(selector: Selector<V>, data: StoreData) => V | Promise<V>;
@@ -1,4 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { StoreData } from "../types/StoreData";
3
- import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
4
- export declare const propagateUpdatedAtoms: (atoms: (Atom<any> | AtomFamilyAtom<any, any>)[], data: StoreData) => void;
@@ -1,3 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const resetAtom: <V>(atom: Atom<V>, data: StoreData) => V | Promise<V>;
@@ -1,3 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const setAtom: <Value = any>(atom: Atom<Value>, newValue: Value, data: StoreData, skipOnSet?: boolean) => void;
@@ -1,3 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const setAtoms: (pairs: Map<Atom<any>, any>, data: StoreData) => void;
@@ -1 +0,0 @@
1
- export declare const stableStringify: (x: any) => string | number | boolean;
@@ -1,4 +0,0 @@
1
- import type { ScopedStore, Store } from "../types/Store";
2
- import type { ScopedStoreData, StoreData } from "../types/StoreData";
3
- export declare function storeFromStoreData(data: ScopedStoreData, detach: () => void): ScopedStore;
4
- export declare function storeFromStoreData(data: StoreData): Store;
@@ -1,4 +0,0 @@
1
- import type { Family } from "../types/Family";
2
- import type { State } from "../types/State";
3
- import type { StoreData } from "../types/StoreData";
4
- export declare const subscribe: <V>(state: State<V> | Family<V>, callback: () => void, requireDeepEqualCheckBeforeCallback: boolean, data: StoreData) => () => void;
@@ -1,9 +0,0 @@
1
- import type { State } from "../types/State";
2
- import type { StoreData } from "../types/StoreData";
3
- import type { Atom } from "../types/Atom";
4
- type GetValdresValue = <V>(state: State<V>) => V;
5
- type SetValdresValue = <V>(state: State<V>, value: V) => void;
6
- type ResetValdresValue = <V>(atom: Atom<V>) => V;
7
- type TransactionInterface = (set: SetValdresValue, get: GetValdresValue, reset: ResetValdresValue, commit: () => void) => void;
8
- export declare const transaction: (callback: TransactionInterface, data: StoreData) => void;
9
- export {};
@@ -1,5 +0,0 @@
1
- import type { Family } from "../types/Family";
2
- import type { State } from "../types/State";
3
- import type { StoreData } from "../types/StoreData";
4
- import type { Subscription } from "../types/Subscription";
5
- export declare const unsubscribe: <V>(state: State<V> | Family<V>, subscription: Subscription, data: StoreData, mount?: any, maxAgeCleanup?: any) => void;
@@ -1,3 +0,0 @@
1
- import type { Selector } from "../types/Selector";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const updateSelectorSubscribers: (selector: Selector, data: StoreData) => void;
@@ -1,3 +0,0 @@
1
- import type { State } from "../types/State";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const updateStateSubscribers: <V>(state: State, data: StoreData) => void;
@@ -1,4 +0,0 @@
1
- import type { GetValue } from "./types/GetValue";
2
- import type { Selector } from "./types/Selector";
3
- import type { SelectorOptions } from "./types/SelectorOptions";
4
- export declare const selector: <Value, FamilyKey = undefined>(get: (get: GetValue, storeId: string) => Value, options?: SelectorOptions<Value>) => Selector<Value, FamilyKey>;
@@ -1,4 +0,0 @@
1
- import type { SelectorFamily } from "./types/SelectorFamily";
2
- import type { SelectorOptions } from "./types/SelectorOptions";
3
- import type { GetValue } from "./types/GetValue";
4
- export declare const selectorFamily: <Key, Value>(get: (key: Key) => (get: GetValue) => Value, options?: SelectorOptions<Value>) => SelectorFamily<Key, Value>;
@@ -1 +0,0 @@
1
- export declare const store: (id?: string) => import("..").Store;
@@ -1,14 +0,0 @@
1
- import type { AtomDefaultValue } from "./AtomDefaultValue";
2
- import type { AtomOnInit } from "./AtomOnInit";
3
- import type { AtomOnSet } from "./AtomOnSet";
4
- import type { EqualFunc } from "./EqualFunc";
5
- export type Atom<Value = unknown> = {
6
- equal: EqualFunc<Value>;
7
- defaultValue?: AtomDefaultValue<Value>;
8
- name?: string;
9
- onInit?: AtomOnInit<Value>;
10
- onSet?: AtomOnSet<Value>;
11
- onMount?: () => void | (() => void);
12
- maxAge?: number;
13
- staleWhileRevalidate?: number;
14
- };
@@ -1,2 +0,0 @@
1
- import type { Selector } from "./Selector";
2
- export type AtomDefaultValue<Value = any> = Value | (() => Value | Promise<Value>) | Selector<Value> | undefined;
@@ -1,12 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { AtomFamilyAtom } from "./AtomFamilyAtom";
3
- import type { FamilyKey } from "./FamilyKey";
4
- import type { Selector } from "./Selector";
5
- export type AtomFamily<Key = FamilyKey, Value = unknown> = {
6
- (key: Key): AtomFamilyAtom<Key, Value>;
7
- release: (key: Key) => void;
8
- name?: string;
9
- __valdresAtomFamilyMap: Map<Key, AtomFamilyAtom<Key, Value>>;
10
- __keysAtom: Atom<Set<Key>>;
11
- __keysSelector: Selector<Key[]>;
12
- };
@@ -1,6 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { AtomFamily } from "./AtomFamily";
3
- export type AtomFamilyAtom<Key = unknown, Value = unknown> = Atom<Value> & {
4
- family: AtomFamily<Key, Value>;
5
- familyKey: Key;
6
- };
@@ -1,5 +0,0 @@
1
- import type { Selector } from "./Selector";
2
- import type { SelectorFamily } from "./SelectorFamily";
3
- type DefaultValueCallback<Key, Value> = (arg: Key) => Value | Promise<Value>;
4
- export type AtomFamilyDefaultValue<Key, Value> = undefined | Value | DefaultValueCallback<Key, Value> | Selector<Value> | SelectorFamily<Key, Value>;
5
- export {};
@@ -1,3 +0,0 @@
1
- import type { AtomFamilyAtom } from "./AtomFamilyAtom";
2
- import type { GlobalAtom } from "./GlobalAtom";
3
- export type AtomFamilyGlobalAtom<Key = unknown, Value = unknown> = AtomFamilyAtom<Key, Value> & GlobalAtom<Value>;
@@ -1,6 +0,0 @@
1
- import type { Selector } from "./Selector";
2
- import type { SelectorFamily } from "./SelectorFamily";
3
- export type AtomFamilySelector<Value = unknown, Key = unknown> = Selector<Value> & {
4
- family: SelectorFamily<Key, Value>;
5
- familyKey: Key;
6
- };
@@ -1,2 +0,0 @@
1
- import type { StoreData } from "./StoreData";
2
- export type AtomOnInit<Value = unknown> = (setSelf: (value: Value) => void, store: StoreData) => void;
@@ -1,2 +0,0 @@
1
- import type { StoreData } from "./StoreData";
2
- export type AtomOnSet<Value = any> = (value: Value, store: StoreData) => void;
@@ -1,13 +0,0 @@
1
- import type { AtomOnSet } from "./AtomOnSet";
2
- import type { EqualFunc } from "./EqualFunc";
3
- import type { StoreData } from "./StoreData";
4
- export type AtomOptions<Value = unknown> = {
5
- global?: boolean;
6
- name?: string;
7
- onInit?: (setSelf: (value: Value) => void, store: StoreData) => (() => void) | void;
8
- onSet?: AtomOnSet<Value>;
9
- onMount?: () => () => void;
10
- maxAge?: number;
11
- staleWhileRevalidate?: number;
12
- equal?: EqualFunc<Value>;
13
- };
@@ -1 +0,0 @@
1
- export type EqualFunc<Value> = (a: Value, b: Value) => boolean;
@@ -1,3 +0,0 @@
1
- import type { SelectorFamily } from "./SelectorFamily";
2
- import type { AtomFamily } from "./AtomFamily";
3
- export type Family<Key, Value = any> = AtomFamily<Key, Value> | SelectorFamily<Key, Value>;
@@ -1,3 +0,0 @@
1
- export type FamilyKey = PropertyKey | PropertyKey[] | {
2
- [key: PropertyKey]: FamilyKey;
3
- };
@@ -1,8 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { AtomFamily } from "./AtomFamily";
3
- import type { Selector } from "./Selector";
4
- export type GetValue = {
5
- <V>(atom: Atom<V>): V;
6
- <V>(selector: Selector<V>): V;
7
- <V, K>(family: AtomFamily<K, V>): K[];
8
- };
@@ -1,11 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { GlobalAtomGetSelfFunc } from "./GlobalAtomGetSelfFunc";
3
- import type { GlobalAtomResetSelfFunc } from "./GlobalAtomResetSelfFunc";
4
- import type { GlobalAtomSetSelfFunc } from "./GlobalAtomSetSelfFunc";
5
- import type { StoreData } from "./StoreData";
6
- export type GlobalAtom<Value = unknown> = Atom<Value> & {
7
- setSelf: GlobalAtomSetSelfFunc<Value>;
8
- resetSelf: GlobalAtomResetSelfFunc;
9
- getSelf: GlobalAtomGetSelfFunc<Value>;
10
- stores: Set<StoreData>;
11
- };
@@ -1 +0,0 @@
1
- export type GlobalAtomGetSelfFunc<Value = unknown> = () => Value;
@@ -1 +0,0 @@
1
- export type GlobalAtomResetSelfFunc = () => void;
@@ -1 +0,0 @@
1
- export type GlobalAtomSetSelfFunc<Value = unknown> = (value: Value) => void;
@@ -1,2 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- export type ResetAtom = <V>(state: Atom<V>) => V | Promise<V>;
@@ -1,11 +0,0 @@
1
- import type { EqualFunc } from "./EqualFunc";
2
- import type { GetValue } from "./GetValue";
3
- import type { SelectorFamily } from "./SelectorFamily";
4
- export type Selector<Value = unknown, FamilyKey = undefined> = {
5
- get: (get: GetValue, storeId: string) => Value;
6
- equal: EqualFunc<Value>;
7
- name?: string;
8
- family?: SelectorFamily<FamilyKey, Value>;
9
- familyKey?: FamilyKey;
10
- onMount?: () => void | (() => void);
11
- };
@@ -1,6 +0,0 @@
1
- import type { FamilyKey } from "./FamilyKey";
2
- import type { Selector } from "./Selector";
3
- export type SelectorFamily<Key = FamilyKey, Value = unknown> = {
4
- (key: Key, defaultOverride?: any): Selector<Value>;
5
- __valdresSelectorFamilyMap: Map<Key, Selector<Value, Key>>;
6
- };
@@ -1,5 +0,0 @@
1
- import type { EqualFunc } from "./EqualFunc";
2
- export type SelectorOptions<Value> = {
3
- name?: string;
4
- equal?: EqualFunc<Value>;
5
- };
@@ -1,3 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { SetAtomValue } from "./SetAtomValue";
3
- export type SetAtom<Value = any> = (atom: Atom<Value>, value: SetAtomValue<Value>) => void;
@@ -1 +0,0 @@
1
- export type SetAtomValue<Value> = Value | ((current: Value) => Value);
@@ -1,4 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { AtomFamily } from "./AtomFamily";
3
- import type { Selector } from "./Selector";
4
- export type State<K = any, V = any> = Atom<V> | Selector<V> | AtomFamily<K, V>;
@@ -1,24 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { AtomFamilyAtom } from "./AtomFamilyAtom";
3
- import type { GetValue } from "./GetValue";
4
- import type { ResetAtom } from "./ResetAtom";
5
- import type { ScopedStoreData, StoreData } from "./StoreData";
6
- import type { SubscribeFn } from "./SubscribeFn";
7
- import type { TransactionFn } from "./TransactionFn";
8
- type SetAtom = {
9
- <V, K>(atom: AtomFamilyAtom<K, V>, value: V): void;
10
- <V>(atom: Atom<V>, value: V): void;
11
- };
12
- export type Store<T = StoreData> = {
13
- data: T;
14
- get: GetValue;
15
- set: SetAtom;
16
- sub: SubscribeFn;
17
- reset: ResetAtom;
18
- txn: (callback: TransactionFn) => void;
19
- scope: (scopeId: string) => ScopedStore;
20
- };
21
- export type ScopedStore = Store<ScopedStoreData> & {
22
- detach: () => void;
23
- };
24
- export {};
@@ -1,17 +0,0 @@
1
- export type RootStoreData = {
2
- id: string;
3
- values: WeakMap<WeakKey, any>;
4
- expiredValues: WeakMap<WeakKey, any>;
5
- subscriptions: WeakMap<WeakKey, Set<any>>;
6
- subscriptionsRequireEqualCheck: WeakMap<WeakKey, boolean>;
7
- stateConsumers: WeakMap<WeakKey, any>;
8
- stateDependencies: WeakMap<WeakKey, any>;
9
- scopes: {
10
- [scopeId: string]: ScopedStoreData;
11
- };
12
- };
13
- export type ScopedStoreData = RootStoreData & {
14
- parent: StoreData;
15
- scopeConsumers: Set<() => void>;
16
- };
17
- export type StoreData = RootStoreData | ScopedStoreData;
@@ -1,2 +0,0 @@
1
- import type { State } from "./State";
2
- export type SubscribeFn = <V>(state: State<V>, callback: () => void, requireDeepEqualCheckBeforeCallback?: boolean) => () => void;
@@ -1 +0,0 @@
1
- export type Subscription = {};
@@ -1,4 +0,0 @@
1
- import type { GetValue } from "./GetValue";
2
- import type { ResetAtom } from "./ResetAtom";
3
- import type { SetAtom } from "./SetAtom";
4
- export type TransactionFn = (set: SetAtom, get: GetValue, reset: ResetAtom, commit: () => void) => void;
@@ -1,2 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- export declare const isAtom: <V>(state: any) => state is Atom<V>;
@@ -1,2 +0,0 @@
1
- import type { AtomFamily } from "../types/AtomFamily";
2
- export declare const isAtomFamily: <K, V>(state: any) => state is AtomFamily<K, V>;
@@ -1 +0,0 @@
1
- export declare const isFamily: (state: any) => state is import("../..").SelectorFamily<unknown, unknown> | import("../..").AtomFamily<unknown, unknown>;
@@ -1,2 +0,0 @@
1
- import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
2
- export declare const isFamilyAtom: <K, V>(state: any) => state is AtomFamilyAtom<K, V>;
@@ -1,2 +0,0 @@
1
- import type { AtomFamilySelector } from "../types/AtomFamilySelector";
2
- export declare const isFamilySelector: <K, V>(state: any) => state is AtomFamilySelector<K, V>;
@@ -1,3 +0,0 @@
1
- import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
2
- import type { AtomFamilySelector } from "../types/AtomFamilySelector";
3
- export declare const isFamilyState: <K, V>(state: any) => state is AtomFamilyAtom<K, V> | AtomFamilySelector<K, V>;
@@ -1 +0,0 @@
1
- export declare const isPromiseLike: <T>(object: any) => object is Promise<T>;
@@ -1,2 +0,0 @@
1
- import type { Selector } from "../types/Selector";
2
- export declare const isSelector: <V>(state: any) => state is Selector<V>;
@@ -1,2 +0,0 @@
1
- import type { SelectorFamily } from "../types/SelectorFamily";
2
- export declare const isSelectorFamily: <K, V>(state: any) => state is SelectorFamily<K, V>;