valdres 0.2.0-alpha.5 → 0.2.0-alpha.7

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 (41) hide show
  1. package/dist/index.js +88 -75
  2. package/package.json +8 -3
  3. package/dist/index.d.ts +0 -19
  4. package/dist/src/atom.d.ts +0 -9
  5. package/dist/src/atomFamily.d.ts +0 -4
  6. package/dist/src/createStore.d.ts +0 -2
  7. package/dist/src/getDefaultStore.d.ts +0 -2
  8. package/dist/src/lib/createStoreData.d.ts +0 -2
  9. package/dist/src/lib/getState.d.ts +0 -3
  10. package/dist/src/lib/initAtom.d.ts +0 -4
  11. package/dist/src/lib/initSelector.d.ts +0 -4
  12. package/dist/src/lib/propagateUpdatedAtoms.d.ts +0 -3
  13. package/dist/src/lib/resetAtom.d.ts +0 -3
  14. package/dist/src/lib/setAtom.d.ts +0 -3
  15. package/dist/src/lib/setAtoms.d.ts +0 -3
  16. package/dist/src/lib/stableStringify.d.ts +0 -1
  17. package/dist/src/lib/storeFromStoreData.d.ts +0 -3
  18. package/dist/src/lib/subscribe.d.ts +0 -4
  19. package/dist/src/lib/transaction.d.ts +0 -8
  20. package/dist/src/lib/unsubscribe.d.ts +0 -3
  21. package/dist/src/lib/updateSelectorSubscribers.d.ts +0 -3
  22. package/dist/src/lib/updateStateSubscribers.d.ts +0 -3
  23. package/dist/src/selector.d.ts +0 -3
  24. package/dist/src/selectorFamily.d.ts +0 -2
  25. package/dist/src/types/Atom.d.ts +0 -10
  26. package/dist/src/types/AtomFamily.d.ts +0 -5
  27. package/dist/src/types/Family.d.ts +0 -3
  28. package/dist/src/types/GetValue.d.ts +0 -2
  29. package/dist/src/types/ResetAtom.d.ts +0 -2
  30. package/dist/src/types/Selector.d.ts +0 -8
  31. package/dist/src/types/SelectorFamily.d.ts +0 -5
  32. package/dist/src/types/SetAtom.d.ts +0 -2
  33. package/dist/src/types/State.d.ts +0 -3
  34. package/dist/src/types/Store.d.ts +0 -14
  35. package/dist/src/types/StoreData.d.ts +0 -9
  36. package/dist/src/types/SubscribeFn.d.ts +0 -2
  37. package/dist/src/types/TransactionFn.d.ts +0 -4
  38. package/dist/src/utils/isAtom.d.ts +0 -2
  39. package/dist/src/utils/isFamily.d.ts +0 -1
  40. package/dist/src/utils/isPromiseLike.d.ts +0 -1
  41. package/dist/src/utils/isSelector.d.ts +0 -2
package/dist/index.js CHANGED
@@ -101,8 +101,8 @@ var createStoreData = (id = generateId()) => ({
101
101
  // src/utils/isAtom.ts
102
102
  var isAtom = (state) => Object.hasOwn(state, "defaultValue");
103
103
 
104
- // src/utils/isSelector.ts
105
- var isSelector = (state) => Object.hasOwn(state, "get");
104
+ // src/lib/getState.ts
105
+ import equal4 from "fast-deep-equal";
106
106
 
107
107
  // src/lib/updateStateSubscribers.ts
108
108
  var updateStateSubscribers = (state, data) => {
@@ -148,7 +148,7 @@ var evaluateSelector = (selector, data) => {
148
148
  let result;
149
149
  try {
150
150
  result = selector.get((state) => {
151
- const value = getState2(state, data);
151
+ const value = getState(state, data);
152
152
  updatedDependencies.add(state);
153
153
  if (isPromiseLike(value))
154
154
  throw new SuspendAndWaitForResolveError(value);
@@ -182,6 +182,7 @@ var handleSelectorResult = (value, selector, data) => {
182
182
  value.then((resolved) => {
183
183
  data.values.set(selector, resolved);
184
184
  updateStateSubscribers(selector, data);
185
+ console.log("Should we reEvaluate?");
185
186
  });
186
187
  return value;
187
188
  } else {
@@ -208,7 +209,7 @@ var updateSelectorSubscribers = (selector, data) => {
208
209
  const familySubscriptions = selector.family && data.subscriptions.get(selector.family);
209
210
  if (!subscribtions?.size && !familySubscriptions?.size)
210
211
  return;
211
- if (subscribtions?.size && data.subscriptionsRequireEqualCheck.get(selector) || familySubscriptions?.size && data.subscriptionsRequireEqualCheck.get(selector.family)) {
212
+ if (subscribtions?.size && data.subscriptionsRequireEqualCheck.get(selector) || familySubscriptions?.size && selector.family && data.subscriptionsRequireEqualCheck.get(selector.family)) {
212
213
  try {
213
214
  const oldValue = data.expiredValues.get(selector);
214
215
  const newValue = initSelector(selector, data);
@@ -245,13 +246,13 @@ var recursivlyResetSelectorTree = (selectors, data, clearedSelectors) => {
245
246
  };
246
247
  var propagateUpdatedAtoms = (atoms, data) => {
247
248
  const clearedSelectors = new Set;
248
- for (const atom3 of atoms) {
249
- const consumers = data.stateConsumers.get(atom3);
249
+ for (const atom2 of atoms) {
250
+ const consumers = data.stateConsumers.get(atom2);
250
251
  if (consumers && consumers.size) {
251
252
  recursivlyResetSelectorTree(consumers, data, clearedSelectors);
252
253
  }
253
- if (atom3.family) {
254
- const consumersFamily = data.stateConsumers.get(atom3.family);
254
+ if (atom2.family) {
255
+ const consumersFamily = data.stateConsumers.get(atom2.family);
255
256
  if (consumersFamily?.size) {
256
257
  recursivlyResetSelectorTree(consumersFamily, data, clearedSelectors);
257
258
  }
@@ -260,15 +261,15 @@ var propagateUpdatedAtoms = (atoms, data) => {
260
261
  for (const selector of clearedSelectors) {
261
262
  updateSelectorSubscribers(selector, data);
262
263
  }
263
- for (const atom3 of atoms) {
264
- updateStateSubscribers(atom3, data);
264
+ for (const atom2 of atoms) {
265
+ updateStateSubscribers(atom2, data);
265
266
  }
266
267
  };
267
268
 
268
269
  // src/lib/setAtom.ts
269
270
  import equal3 from "fast-deep-equal";
270
- var setAtom = (atom3, newValue, data) => {
271
- const currentValue = getState2(atom3, data);
271
+ var setAtom = (atom2, newValue, data) => {
272
+ const currentValue = getState(atom2, data);
272
273
  if (typeof newValue === "function") {
273
274
  newValue = newValue(currentValue);
274
275
  if (isPromiseLike(newValue) || isPromiseLike(currentValue))
@@ -276,16 +277,16 @@ var setAtom = (atom3, newValue, data) => {
276
277
  }
277
278
  if (equal3(currentValue, newValue))
278
279
  return;
279
- data.values.set(atom3, newValue);
280
+ data.values.set(atom2, newValue);
280
281
  if (currentValue?.__isEmptyAtomPromise__) {
281
282
  currentValue.__resolveEmptyAtomPromise__(newValue);
282
283
  }
283
- propagateUpdatedAtoms([atom3], data);
284
+ propagateUpdatedAtoms([atom2], data);
284
285
  };
285
286
 
286
287
  // src/lib/initAtom.ts
287
- var getAtomInitValue = (atom3, data) => {
288
- if (atom3.defaultValue === undefined) {
288
+ var getAtomInitValue = (atom2, data) => {
289
+ if (atom2.defaultValue === undefined) {
289
290
  let promiseResolve;
290
291
  const promise = new Promise((resolve) => {
291
292
  promiseResolve = resolve;
@@ -293,34 +294,38 @@ var getAtomInitValue = (atom3, data) => {
293
294
  promise.__isEmptyAtomPromise__ = true;
294
295
  promise.__resolveEmptyAtomPromise__ = promiseResolve;
295
296
  return promise;
296
- } else if (typeof atom3.defaultValue === "function") {
297
- const value = atom3.defaultValue();
297
+ } else if (typeof atom2.defaultValue === "function") {
298
+ const value = atom2.defaultValue();
298
299
  if (isPromiseLike(value)) {
299
300
  value.then((resolvedValue) => {
300
- data.values.set(atom3, resolvedValue);
301
- propagateUpdatedAtoms([atom3], data);
301
+ data.values.set(atom2, resolvedValue);
302
+ propagateUpdatedAtoms([atom2], data);
302
303
  });
303
304
  }
304
305
  return value;
305
306
  } else {
306
- return atom3.defaultValue;
307
+ return atom2.defaultValue;
307
308
  }
308
309
  };
309
- var initAtom = (atom3, data) => {
310
- const value = getAtomInitValue(atom3, data);
311
- data.values.set(atom3, value);
312
- if (atom3.onInit)
313
- atom3.onInit((newVal) => {
314
- setAtom(atom3, newVal, data);
310
+ var initAtom = (atom2, data) => {
311
+ let value = getAtomInitValue(atom2, data);
312
+ data.values.set(atom2, value);
313
+ if (atom2.onInit)
314
+ atom2.onInit((newVal) => {
315
+ value = newVal;
316
+ setAtom(atom2, newVal, data);
315
317
  });
316
318
  return value;
317
319
  };
318
320
 
321
+ // src/utils/isSelector.ts
322
+ var isSelector = (state) => Object.hasOwn(state, "get");
323
+
319
324
  // src/utils/isFamily.ts
320
325
  var isFamily = (state) => Object.hasOwn(state, "_map");
321
326
 
322
327
  // src/lib/getState.ts
323
- var getState2 = (state, data) => {
328
+ function getState(state, data) {
324
329
  if (data.values.has(state))
325
330
  return data.values.get(state);
326
331
  if (isAtom(state))
@@ -328,20 +333,20 @@ var getState2 = (state, data) => {
328
333
  if (isSelector(state))
329
334
  return initSelector(state, data);
330
335
  if (isFamily(state)) {
331
- const res = [];
332
- for (const atom3 of state._map.values()) {
333
- res.push([atom3.familyKey, getState2(atom3, data)]);
334
- }
335
- return res;
336
+ const array = Array.from(state._map.keys());
337
+ if (equal4(array, state._keyArray))
338
+ return state._keyArray;
339
+ state._keyArray = array;
340
+ return array;
336
341
  }
337
342
  throw new Error("Invalid object passed to get");
338
- };
343
+ }
339
344
 
340
345
  // src/lib/resetAtom.ts
341
- var resetAtom = (atom3, data) => {
342
- const res = initAtom(atom3, data);
346
+ var resetAtom = (atom2, data) => {
347
+ const res = initAtom(atom2, data);
343
348
  if (!isPromiseLike(res)) {
344
- propagateUpdatedAtoms([atom3], data);
349
+ propagateUpdatedAtoms([atom2], data);
345
350
  }
346
351
  return res;
347
352
  };
@@ -365,8 +370,8 @@ var unsubscribe = (state, subscription, data, mount) => {
365
370
  }
366
371
  if (mount) {
367
372
  if (subscribers.size === mount.mountSubscriptions.size) {
368
- if (state.onUnmount) {
369
- state.onUnmount(mount.onMountRes);
373
+ if (typeof mount.onUnmount === "function") {
374
+ mount.onUnmount();
370
375
  }
371
376
  }
372
377
  }
@@ -400,7 +405,7 @@ var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) =>
400
405
  subscribers.add(subscription);
401
406
  let mount;
402
407
  if (subscribers.size === 1 && state.onMount) {
403
- const store = storeFromStoreData2(data);
408
+ const store = storeFromStoreData(data);
404
409
  const mountSubscriptions = new Set;
405
410
  const originalSub = store.sub;
406
411
  store.sub = (state2, callback2) => {
@@ -408,7 +413,7 @@ var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) =>
408
413
  return originalSub(state2, callback2);
409
414
  };
410
415
  mount = {
411
- onMountRes: state.onMount(store, state),
416
+ onUnmount: state.onMount(store, state),
412
417
  mountSubscriptions
413
418
  };
414
419
  }
@@ -419,14 +424,14 @@ var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) =>
419
424
  };
420
425
 
421
426
  // src/lib/setAtoms.ts
422
- import equal4 from "fast-deep-equal";
427
+ import equal5 from "fast-deep-equal";
423
428
  var setAtoms = (pairs, data) => {
424
429
  const updatedAtoms = [];
425
- for (let [atom3, value] of pairs) {
426
- const currentValue = getState2(atom3, data);
427
- if (!equal4(currentValue, value)) {
428
- updatedAtoms.push(atom3);
429
- data.values.set(atom3, value);
430
+ for (let [atom2, value] of pairs) {
431
+ const currentValue = getState(atom2, data);
432
+ if (!equal5(currentValue, value)) {
433
+ updatedAtoms.push(atom2);
434
+ data.values.set(atom2, value);
430
435
  }
431
436
  }
432
437
  propagateUpdatedAtoms(updatedAtoms, data);
@@ -460,7 +465,7 @@ var transaction = (callback, data) => {
460
465
  let dirtySelectors = new Set;
461
466
  const txnGet = (state) => {
462
467
  if (isAtom(state)) {
463
- return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState2(state, data);
468
+ return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState(state, data);
464
469
  } else if (isSelector(state)) {
465
470
  if (txnSelectorCache.has(state)) {
466
471
  return txnSelectorCache.get(state);
@@ -482,25 +487,25 @@ var transaction = (callback, data) => {
482
487
  throw new Error("Unsupported state");
483
488
  }
484
489
  };
485
- const txnSet = (atom3, value) => {
486
- if (!isAtom(atom3))
490
+ const txnSet = (atom2, value) => {
491
+ if (!isAtom(atom2))
487
492
  throw new Error("Not an atom");
488
493
  if (typeof value === "function") {
489
- const currentValue = txnGet(atom3);
494
+ const currentValue = txnGet(atom2);
490
495
  value = value(currentValue);
491
496
  }
492
- for (const selector of findDependencies(atom3, data)) {
497
+ for (const selector of findDependencies(atom2, data)) {
493
498
  dirtySelectors.add(selector);
494
499
  txnSelectorCache.delete(selector);
495
500
  }
496
- if (txnSubscribers.get(atom3)?.size) {
497
- recursivlyResetTxnSelectorCache(atom3, txnSubscribers, txnSelectorCache);
501
+ if (txnSubscribers.get(atom2)?.size) {
502
+ recursivlyResetTxnSelectorCache(atom2, txnSubscribers, txnSelectorCache);
498
503
  }
499
- txnAtomMap.set(atom3, value);
504
+ txnAtomMap.set(atom2, value);
500
505
  };
501
- const txnReset = (atom3) => {
502
- const value = getAtomInitValue(atom3, data);
503
- txnAtomMap.set(atom3, value);
506
+ const txnReset = (atom2) => {
507
+ const value = getAtomInitValue(atom2, data);
508
+ txnAtomMap.set(atom2, value);
504
509
  return value;
505
510
  };
506
511
  const commit = () => {
@@ -513,24 +518,14 @@ var transaction = (callback, data) => {
513
518
  };
514
519
 
515
520
  // src/lib/storeFromStoreData.ts
516
- var storeFromStoreData2 = (data) => {
517
- const get = (state) => getState2(state, data);
521
+ var storeFromStoreData = (data) => {
522
+ const get = (state) => getState(state, data);
518
523
  const set = (state, value) => {
519
- if (isAtom(state)) {
520
- return setAtom(state, value, data);
521
- } else {
522
- if (isSelector(state)) {
523
- if (state.set) {
524
- txn((set2, get2) => state.set({ get: get2, set: set2 }, value));
525
- return;
526
- } else {
527
- throw new Error("set on selector is not supported");
528
- }
529
- }
530
- throw new Error("Invalid state object passed to set");
531
- }
524
+ if (!isAtom(state))
525
+ throw new Error("Invalid state object");
526
+ return setAtom(state, value, data);
532
527
  };
533
- const reset = (atom3) => resetAtom(atom3, data);
528
+ const reset = (atom2) => resetAtom(atom2, data);
534
529
  const sub = (state, callback, deepEqualCheckBeforeCallback = true) => subscribe(state, callback, deepEqualCheckBeforeCallback, data);
535
530
  const txn = (callback) => transaction(callback, data);
536
531
  return {
@@ -546,7 +541,24 @@ var storeFromStoreData2 = (data) => {
546
541
  // src/createStore.ts
547
542
  var createStore = (id) => {
548
543
  const data = createStoreData(id);
549
- return storeFromStoreData2(data);
544
+ return storeFromStoreData(data);
545
+ };
546
+ // src/createStoreWithSelectorSet.ts
547
+ var setSelector = (selector, values, store) => {
548
+ return selector.set(store.set, store.get, store.reset, ...values);
549
+ };
550
+ var createStoreWithSelectorSet = (id) => {
551
+ const data = createStoreData(id);
552
+ const store = storeFromStoreData(data);
553
+ store.set = (state, value, ...rest) => {
554
+ if (isAtom(state))
555
+ return setAtom(state, value, data);
556
+ if (isSelector(state))
557
+ return setSelector(state, [value, ...rest], store);
558
+ throw new Error("Invalid state object");
559
+ };
560
+ store.kind = "storeWithSelectorSet";
561
+ return store;
550
562
  };
551
563
  // src/getDefaultStore.ts
552
564
  if (!globalThis._valdresStore) {
@@ -590,6 +602,7 @@ export {
590
602
  isFamily,
591
603
  isAtom,
592
604
  getDefaultStore,
605
+ createStoreWithSelectorSet,
593
606
  createStore,
594
607
  atomFamily,
595
608
  atom
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.5",
3
+ "version": "0.2.0-alpha.7",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Eigil Sagafos"
7
7
  },
8
+ "homepage": "https://valdres.dev",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/eigilsagafos/valdres.git"
12
+ },
8
13
  "type": "module",
9
14
  "exports": {
10
15
  "types": "./dist/index.d.ts",
@@ -28,11 +33,11 @@
28
33
  "react": ">=18",
29
34
  "react-dom": ">=18",
30
35
  "recoil": "0.7.7",
31
- "typescript": "5.5.4"
36
+ "typescript": "5.6.2"
32
37
  },
33
38
  "publishConfig": {
34
39
  "access": "public",
35
40
  "registry": "https://registry.npmjs.org/"
36
41
  },
37
- "gitHead": "75721256957ea160c2a82ac4ebb5a12e4c447f1f"
42
+ "gitHead": "3ef9fcf34827ece4d4e32b81b28b4b21aaa1b887"
38
43
  }
package/dist/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- export { atom } from "./src/atom";
2
- export { atomFamily } from "./src/atomFamily";
3
- export { createStore } from "./src/createStore";
4
- export { getDefaultStore, resetDefaultStore } from "./src/getDefaultStore";
5
- export { selector } from "./src/selector";
6
- export { selectorFamily } from "./src/selectorFamily";
7
- export { isAtom } from "./src/utils/isAtom";
8
- export { isSelector } from "./src/utils/isSelector";
9
- export { isFamily } from "./src/utils/isFamily";
10
- export { isPromiseLike } from "./src/utils/isPromiseLike";
11
- export type { Atom } from "./src/types/Atom";
12
- export type { AtomFamily } from "./src/types/AtomFamily";
13
- export type { GetValue } from "./src/types/GetValue";
14
- export type { Selector } from "./src/types/Selector";
15
- export type { SelectorFamily } from "./src/types/SelectorFamily";
16
- export type { SetAtom } from "./src/types/SetAtom";
17
- export type { State } from "./src/types/State";
18
- export type { Store } from "./src/types/Store";
19
- export type { StoreData } from "./src/types/StoreData";
@@ -1,9 +0,0 @@
1
- import type { Atom } from "./types/Atom";
2
- type AtomOptions<MountRes = undefined> = {
3
- label?: string;
4
- onInit?: () => void;
5
- onMount?: () => MountRes;
6
- onUnmount?: (mountRes?: MountRes) => void;
7
- };
8
- export declare const atom: <Value, FamilyKey = undefined, MountReturnValue = undefined>(defaultValue?: Value | (() => Value | Promise<Value>), options?: AtomOptions<MountReturnValue>) => Atom<Value, FamilyKey>;
9
- export {};
@@ -1,4 +0,0 @@
1
- import type { AtomFamily } from "./types/AtomFamily";
2
- type DefaultValueCallback<Key, Value> = (arg: Key) => Value | Promise<Value>;
3
- export declare const atomFamily: <Value, Key>(defaultValue?: Value | DefaultValueCallback<Key, Value>, debugLabel?: string) => AtomFamily<Value, Key>;
4
- export {};
@@ -1,2 +0,0 @@
1
- import type { Store } from "./types/Store";
2
- export declare const createStore: (id?: string) => Store;
@@ -1,2 +0,0 @@
1
- export declare const getDefaultStore: () => any;
2
- export declare const resetDefaultStore: () => import("..").Store;
@@ -1,2 +0,0 @@
1
- import type { StoreData } from "../types/StoreData";
2
- export declare const createStoreData: (id?: string) => StoreData;
@@ -1,3 +0,0 @@
1
- import type { State } from "../types/State";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const getState: <V>(state: State<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
- export declare const getAtomInitValue: <V>(atom: Atom<V>, data: StoreData) => any;
4
- export declare const initAtom: <V>(atom: Atom<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,3 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const propagateUpdatedAtoms: (atoms: Atom[], 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: <V>(atom: Atom<V>, newValue: V, 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 setAtoms: (pairs: Map<Atom<any>, any>, data: StoreData) => void;
@@ -1 +0,0 @@
1
- export declare const stableStringify: (x: any) => string | number | boolean;
@@ -1,3 +0,0 @@
1
- import type { Store } from "../types/Store";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const 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: any, requireDeepEqualCheckBeforeCallback: boolean, data: StoreData) => () => void;
@@ -1,8 +0,0 @@
1
- import type { State } from "../types/State";
2
- import type { StoreData } from "../types/StoreData";
3
- type GetValdresValue = <V>(state: State<V>) => V;
4
- type SetValdresValue = <V>(state: State<V>, value: V) => void;
5
- type ResetValdresValue = <V>(state: State<V>) => V;
6
- type TransactionInterface = (set: SetValdresValue, get: GetValdresValue, reset: ResetValdresValue, commit: () => void) => void;
7
- export declare const transaction: (callback: TransactionInterface, data: StoreData) => void;
8
- export {};
@@ -1,3 +0,0 @@
1
- import type { State } from "../types/State";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const unsubscribe: <V>(state: State<V>, subscription: any, data: StoreData, mount?: 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: (state: State, data: StoreData) => void;
@@ -1,3 +0,0 @@
1
- import type { GetValue } from "./types/GetValue";
2
- import type { Selector } from "./types/Selector";
3
- export declare const selector: <Value, FamilyKey = undefined>(get: (get: GetValue) => Value, debugLabel?: string) => Selector<Value, FamilyKey>;
@@ -1,2 +0,0 @@
1
- import type { SelectorFamily } from "./types/SelectorFamily";
2
- export declare const selectorFamily: <Value, Key>(get: any, debugLabel?: string) => SelectorFamily<Value, Key>;
@@ -1,10 +0,0 @@
1
- import type { AtomFamily } from "./AtomFamily";
2
- export type Atom<Value = unknown, FamilyKey = undefined, MountRes = undefined> = {
3
- defaultValue?: Value | (() => Value | Promise<Value>);
4
- label?: string;
5
- family?: AtomFamily<Value, FamilyKey>;
6
- familyKey?: FamilyKey;
7
- onInit?: () => void;
8
- onMount?: () => MountRes;
9
- onUnmount?: (mountRes?: MountRes) => void;
10
- };
@@ -1,5 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- export type AtomFamily<Value, Key> = {
3
- (key: Key, defaultOverride?: any): Atom<Value>;
4
- _map: Map<Key, Atom<Value, Key>>;
5
- };
@@ -1,3 +0,0 @@
1
- import type { SelectorFamily } from "./SelectorFamily";
2
- import type { AtomFamily } from "./AtomFamily";
3
- export type Family<V, K = any> = AtomFamily<V, K> | SelectorFamily<V, K>;
@@ -1,2 +0,0 @@
1
- import type { State } from "./State";
2
- export type GetValue = <V>(state: State<V>) => V | Promise<V>;
@@ -1,2 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- export type ResetAtom = <V>(state: Atom<V>) => V | Promise<V>;
@@ -1,8 +0,0 @@
1
- import type { GetValue } from "./GetValue";
2
- import type { SelectorFamily } from "./SelectorFamily";
3
- export type Selector<Value = any, FamilyKey = undefined> = {
4
- get: (get: GetValue) => Value;
5
- debugLabel?: string;
6
- family?: SelectorFamily<Value, FamilyKey>;
7
- familyKey?: FamilyKey;
8
- };
@@ -1,5 +0,0 @@
1
- import type { Selector } from "./Selector";
2
- export type SelectorFamily<Value, Key> = {
3
- (key: Key, defaultOverride?: any): Selector<Value>;
4
- _map: Map<Key, Selector<Value, Key>>;
5
- };
@@ -1,2 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- export type SetAtom = <V>(atom: Atom<V>, value: V | ((current: V) => V)) => void;
@@ -1,3 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- import type { Selector } from "./Selector";
3
- export type State<V = any> = Atom<V> | Selector<V>;
@@ -1,14 +0,0 @@
1
- import type { GetValue } from "./GetValue";
2
- import type { ResetAtom } from "./ResetAtom";
3
- import type { SetAtom } from "./SetAtom";
4
- import type { StoreData } from "./StoreData";
5
- import type { SubscribeFn } from "./SubscribeFn";
6
- import type { TransactionFn } from "./TransactionFn";
7
- export type Store = {
8
- data: StoreData;
9
- get: GetValue;
10
- set: SetAtom;
11
- sub: SubscribeFn;
12
- reset: ResetAtom;
13
- txn: (callback: TransactionFn) => void;
14
- };
@@ -1,9 +0,0 @@
1
- export type StoreData = {
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
- };
@@ -1,2 +0,0 @@
1
- import type { State } from "./State";
2
- export type SubscribeFn = <V>(state: State<V>, callback: () => void, requireDeepEqualCheckBeforeCallback?: boolean) => () => void;
@@ -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: (state: any) => state is Atom;
@@ -1 +0,0 @@
1
- export declare const isFamily: (state: any) => boolean;
@@ -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: (state: any) => state is Selector;