atom.io 0.6.2 → 0.6.3

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 (110) hide show
  1. package/dist/index.d.mts +2 -2
  2. package/dist/index.d.ts +2 -2
  3. package/dist/index.js +7 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +7 -2
  6. package/dist/index.mjs.map +1 -1
  7. package/json/dist/index.d.mts +18 -0
  8. package/json/dist/index.d.ts +18 -0
  9. package/json/dist/index.js +51 -0
  10. package/json/dist/index.js.map +1 -0
  11. package/json/dist/index.mjs +15 -0
  12. package/json/dist/index.mjs.map +1 -0
  13. package/package.json +13 -3
  14. package/react/dist/index.d.mts +24 -0
  15. package/react/dist/index.d.ts +24 -0
  16. package/react/dist/index.js +83 -0
  17. package/react/dist/index.js.map +1 -0
  18. package/react/dist/index.mjs +41 -0
  19. package/react/dist/index.mjs.map +1 -0
  20. package/react-devtools/dist/index.css +26 -0
  21. package/react-devtools/dist/index.css.map +1 -0
  22. package/react-devtools/dist/index.d.mts +15 -0
  23. package/react-devtools/dist/index.d.ts +15 -0
  24. package/react-devtools/dist/index.js +1596 -0
  25. package/react-devtools/dist/index.js.map +1 -0
  26. package/react-devtools/dist/index.mjs +1568 -0
  27. package/react-devtools/dist/index.mjs.map +1 -0
  28. package/realtime/dist/index.d.mts +27 -0
  29. package/realtime/dist/index.d.ts +27 -0
  30. package/realtime/dist/index.js +191 -0
  31. package/realtime/dist/index.js.map +1 -0
  32. package/realtime/dist/index.mjs +152 -0
  33. package/realtime/dist/index.mjs.map +1 -0
  34. package/realtime-react/dist/index.d.mts +45 -0
  35. package/realtime-react/dist/index.d.ts +45 -0
  36. package/realtime-react/dist/index.js +213 -0
  37. package/realtime-react/dist/index.js.map +1 -0
  38. package/realtime-react/dist/index.mjs +168 -0
  39. package/realtime-react/dist/index.mjs.map +1 -0
  40. package/realtime-testing/dist/index.d.mts +49 -0
  41. package/realtime-testing/dist/index.d.ts +49 -0
  42. package/realtime-testing/dist/index.js +153 -0
  43. package/realtime-testing/dist/index.js.map +1 -0
  44. package/realtime-testing/dist/index.mjs +117 -0
  45. package/realtime-testing/dist/index.mjs.map +1 -0
  46. package/realtime-testing/package.json +15 -0
  47. package/src/atom.ts +15 -15
  48. package/src/index.ts +59 -59
  49. package/src/internal/atom-internal.ts +36 -36
  50. package/src/internal/families-internal.ts +114 -114
  51. package/src/internal/get.ts +83 -83
  52. package/src/internal/is-default.ts +17 -17
  53. package/src/internal/meta/attach-meta.ts +7 -7
  54. package/src/internal/meta/meta-state.ts +115 -115
  55. package/src/internal/operation.ts +93 -93
  56. package/src/internal/selector/create-read-write-selector.ts +46 -46
  57. package/src/internal/selector/create-readonly-selector.ts +37 -37
  58. package/src/internal/selector/lookup-selector-sources.ts +9 -9
  59. package/src/internal/selector/register-selector.ts +44 -44
  60. package/src/internal/selector/trace-selector-atoms.ts +30 -30
  61. package/src/internal/selector/update-selector-atoms.ts +25 -25
  62. package/src/internal/selector-internal.ts +37 -37
  63. package/src/internal/set.ts +78 -78
  64. package/src/internal/store.ts +118 -118
  65. package/src/internal/subscribe-internal.ts +62 -62
  66. package/src/internal/time-travel-internal.ts +76 -76
  67. package/src/internal/timeline/add-atom-to-timeline.ts +158 -153
  68. package/src/internal/timeline-internal.ts +80 -80
  69. package/src/internal/transaction/abort-transaction.ts +8 -8
  70. package/src/internal/transaction/apply-transaction.ts +41 -41
  71. package/src/internal/transaction/build-transaction.ts +28 -28
  72. package/src/internal/transaction/index.ts +7 -7
  73. package/src/internal/transaction/redo-transaction.ts +13 -13
  74. package/src/internal/transaction/undo-transaction.ts +13 -13
  75. package/src/internal/transaction-internal.ts +48 -48
  76. package/src/json/select-json.ts +12 -12
  77. package/src/logger.ts +30 -30
  78. package/src/react/store-context.tsx +4 -4
  79. package/src/react/store-hooks.ts +18 -18
  80. package/src/react-devtools/AtomIODevtools.tsx +83 -82
  81. package/src/react-devtools/StateEditor.tsx +53 -53
  82. package/src/react-devtools/TokenList.tsx +47 -42
  83. package/src/react-explorer/AtomIOExplorer.tsx +197 -185
  84. package/src/react-explorer/explorer-effects.ts +11 -11
  85. package/src/react-explorer/explorer-states.ts +186 -193
  86. package/src/react-explorer/index.ts +11 -11
  87. package/src/react-explorer/space-states.ts +48 -50
  88. package/src/react-explorer/view-states.ts +25 -25
  89. package/src/realtime/hook-composition/expose-family.ts +81 -81
  90. package/src/realtime/hook-composition/expose-single.ts +26 -26
  91. package/src/realtime/hook-composition/expose-timeline.ts +60 -0
  92. package/src/realtime/hook-composition/index.ts +2 -2
  93. package/src/realtime/hook-composition/receive-state.ts +18 -18
  94. package/src/realtime/hook-composition/receive-transaction.ts +8 -8
  95. package/src/realtime-react/realtime-context.tsx +17 -17
  96. package/src/realtime-react/realtime-hooks.ts +17 -17
  97. package/src/realtime-react/realtime-state.ts +4 -4
  98. package/src/realtime-react/use-pull-family-member.ts +15 -15
  99. package/src/realtime-react/use-pull-family.ts +13 -13
  100. package/src/realtime-react/use-pull.ts +12 -12
  101. package/src/realtime-react/use-push.ts +15 -15
  102. package/src/realtime-react/use-server-action.ts +21 -21
  103. package/src/realtime-testing/index.ts +1 -0
  104. package/src/realtime-testing/setup-realtime-test.tsx +160 -0
  105. package/src/selector.ts +25 -25
  106. package/src/silo.ts +38 -38
  107. package/src/subscribe.ts +68 -68
  108. package/src/timeline.ts +13 -13
  109. package/src/transaction.ts +28 -28
  110. package/src/web-effects/storage.ts +17 -17
@@ -12,44 +12,44 @@ import { setState, subscribe } from ".."
12
12
  import type { AtomOptions } from "../atom"
13
13
 
14
14
  export type Atom<T> = {
15
- key: string
16
- type: `atom`
17
- family?: FamilyMetadata
18
- subject: Rx.Subject<{ newValue: T; oldValue: T }>
19
- default: T
15
+ key: string
16
+ type: `atom`
17
+ family?: FamilyMetadata
18
+ subject: Rx.Subject<{ newValue: T; oldValue: T }>
19
+ default: T
20
20
  }
21
21
 
22
22
  export function atom__INTERNAL<T>(
23
- options: AtomOptions<T>,
24
- family?: FamilyMetadata,
25
- store: Store = IMPLICIT.STORE
23
+ options: AtomOptions<T>,
24
+ family?: FamilyMetadata,
25
+ store: Store = IMPLICIT.STORE,
26
26
  ): AtomToken<T> {
27
- const core = target(store)
28
- if (hasKeyBeenUsed(options.key, store)) {
29
- store.config.logger?.error?.(
30
- `Key "${options.key}" already exists in the store.`
31
- )
32
- return deposit(core.atoms.get(options.key))
33
- }
34
- const subject = new Rx.Subject<{ newValue: T; oldValue: T }>()
35
- const newAtom = {
36
- ...options,
37
- subject,
38
- type: `atom`,
39
- ...(family && { family }),
40
- } as const
41
- const initialValue =
42
- options.default instanceof Function ? options.default() : options.default
43
- core.atoms = HAMT.set(newAtom.key, newAtom, core.atoms)
44
- markAtomAsDefault(options.key, store)
45
- cacheValue(options.key, initialValue, store)
46
- const token = deposit(newAtom)
47
- options.effects?.forEach((effect) =>
48
- effect({
49
- setSelf: (next) => setState(token, next, store),
50
- onSet: (handle: UpdateHandler<T>) => subscribe(token, handle, store),
51
- })
52
- )
53
- store.subject.atomCreation.next(token)
54
- return token as AtomToken<T>
27
+ const core = target(store)
28
+ if (hasKeyBeenUsed(options.key, store)) {
29
+ store.config.logger?.error?.(
30
+ `Key "${options.key}" already exists in the store.`,
31
+ )
32
+ return deposit(core.atoms.get(options.key))
33
+ }
34
+ const subject = new Rx.Subject<{ newValue: T; oldValue: T }>()
35
+ const newAtom = {
36
+ ...options,
37
+ subject,
38
+ type: `atom`,
39
+ ...(family && { family }),
40
+ } as const
41
+ const initialValue =
42
+ options.default instanceof Function ? options.default() : options.default
43
+ core.atoms = HAMT.set(newAtom.key, newAtom, core.atoms)
44
+ markAtomAsDefault(options.key, store)
45
+ cacheValue(options.key, initialValue, store)
46
+ const token = deposit(newAtom)
47
+ options.effects?.forEach((effect) =>
48
+ effect({
49
+ setSelf: (next) => setState(token, next, store),
50
+ onSet: (handle: UpdateHandler<T>) => subscribe(token, handle, store),
51
+ }),
52
+ )
53
+ store.subject.atomCreation.next(token)
54
+ return token as AtomToken<T>
55
55
  }
@@ -5,138 +5,138 @@ import { stringifyJson } from "~/packages/anvl/src/json"
5
5
 
6
6
  import type { Store } from "."
7
7
  import {
8
- atom__INTERNAL,
9
- withdraw,
10
- selector__INTERNAL,
11
- target,
12
- deposit,
13
- IMPLICIT,
8
+ atom__INTERNAL,
9
+ withdraw,
10
+ selector__INTERNAL,
11
+ target,
12
+ deposit,
13
+ IMPLICIT,
14
14
  } from "."
15
15
  import type {
16
- AtomFamily,
17
- AtomFamilyOptions,
18
- AtomToken,
19
- FamilyMetadata,
20
- ReadonlySelectorFamily,
21
- ReadonlySelectorFamilyOptions,
22
- ReadonlySelectorToken,
23
- SelectorFamily,
24
- SelectorFamilyOptions,
25
- SelectorToken,
16
+ AtomFamily,
17
+ AtomFamilyOptions,
18
+ AtomToken,
19
+ FamilyMetadata,
20
+ ReadonlySelectorFamily,
21
+ ReadonlySelectorFamilyOptions,
22
+ ReadonlySelectorToken,
23
+ SelectorFamily,
24
+ SelectorFamilyOptions,
25
+ SelectorToken,
26
26
  } from ".."
27
27
 
28
28
  export function atomFamily__INTERNAL<T, K extends Serializable>(
29
- options: AtomFamilyOptions<T, K>,
30
- store: Store = IMPLICIT.STORE
29
+ options: AtomFamilyOptions<T, K>,
30
+ store: Store = IMPLICIT.STORE,
31
31
  ): AtomFamily<T, K> {
32
- const subject = new Rx.Subject<AtomToken<T>>()
33
- return Object.assign(
34
- (key: K): AtomToken<T> => {
35
- const subKey = stringifyJson(key)
36
- const family: FamilyMetadata = { key: options.key, subKey }
37
- const fullKey = `${options.key}(${subKey})`
38
- const existing = withdraw({ key: fullKey, type: `atom` }, store)
39
- const token: AtomToken<any> = existing
40
- ? deposit(existing)
41
- : atom__INTERNAL<T>(
42
- {
43
- key: fullKey,
44
- default:
45
- options.default instanceof Function
46
- ? options.default(key)
47
- : options.default,
48
- effects: options.effects?.(key),
49
- },
50
- family,
51
- store
52
- )
53
- subject.next(token)
54
- return token
55
- },
56
- {
57
- key: options.key,
58
- type: `atom_family`,
59
- subject,
60
- } as const
61
- )
32
+ const subject = new Rx.Subject<AtomToken<T>>()
33
+ return Object.assign(
34
+ (key: K): AtomToken<T> => {
35
+ const subKey = stringifyJson(key)
36
+ const family: FamilyMetadata = { key: options.key, subKey }
37
+ const fullKey = `${options.key}(${subKey})`
38
+ const existing = withdraw({ key: fullKey, type: `atom` }, store)
39
+ const token: AtomToken<any> = existing
40
+ ? deposit(existing)
41
+ : atom__INTERNAL<T>(
42
+ {
43
+ key: fullKey,
44
+ default:
45
+ options.default instanceof Function
46
+ ? options.default(key)
47
+ : options.default,
48
+ effects: options.effects?.(key),
49
+ },
50
+ family,
51
+ store,
52
+ )
53
+ subject.next(token)
54
+ return token
55
+ },
56
+ {
57
+ key: options.key,
58
+ type: `atom_family`,
59
+ subject,
60
+ } as const,
61
+ )
62
62
  }
63
63
 
64
64
  export function readonlySelectorFamily__INTERNAL<T, K extends Serializable>(
65
- options: ReadonlySelectorFamilyOptions<T, K>,
66
- store?: Store
65
+ options: ReadonlySelectorFamilyOptions<T, K>,
66
+ store?: Store,
67
67
  ): ReadonlySelectorFamily<T, K> {
68
- const core = target(store)
69
- const subject = new Rx.Subject<ReadonlySelectorToken<T>>()
70
- return Object.assign(
71
- (key: K): ReadonlySelectorToken<T> => {
72
- const subKey = stringifyJson(key)
73
- const family: FamilyMetadata = { key: options.key, subKey }
74
- const fullKey = `${options.key}(${subKey})`
75
- const existing = core.readonlySelectors.get(fullKey)
76
- if (existing) {
77
- return deposit(existing)
78
- }
79
- return selector__INTERNAL<T>(
80
- {
81
- key: fullKey,
82
- get: options.get(key),
83
- },
84
- family,
85
- store
86
- ) as ReadonlySelectorToken<T>
87
- },
88
- {
89
- key: options.key,
90
- type: `readonly_selector_family`,
91
- subject,
92
- } as const
93
- ) as ReadonlySelectorFamily<T, K>
68
+ const core = target(store)
69
+ const subject = new Rx.Subject<ReadonlySelectorToken<T>>()
70
+ return Object.assign(
71
+ (key: K): ReadonlySelectorToken<T> => {
72
+ const subKey = stringifyJson(key)
73
+ const family: FamilyMetadata = { key: options.key, subKey }
74
+ const fullKey = `${options.key}(${subKey})`
75
+ const existing = core.readonlySelectors.get(fullKey)
76
+ if (existing) {
77
+ return deposit(existing)
78
+ }
79
+ return selector__INTERNAL<T>(
80
+ {
81
+ key: fullKey,
82
+ get: options.get(key),
83
+ },
84
+ family,
85
+ store,
86
+ ) as ReadonlySelectorToken<T>
87
+ },
88
+ {
89
+ key: options.key,
90
+ type: `readonly_selector_family`,
91
+ subject,
92
+ } as const,
93
+ ) as ReadonlySelectorFamily<T, K>
94
94
  }
95
95
 
96
96
  export function selectorFamily__INTERNAL<T, K extends Serializable>(
97
- options: SelectorFamilyOptions<T, K>,
98
- store?: Store
97
+ options: SelectorFamilyOptions<T, K>,
98
+ store?: Store,
99
99
  ): SelectorFamily<T, K>
100
100
  export function selectorFamily__INTERNAL<T, K extends Serializable>(
101
- options: ReadonlySelectorFamilyOptions<T, K>,
102
- store?: Store
101
+ options: ReadonlySelectorFamilyOptions<T, K>,
102
+ store?: Store,
103
103
  ): ReadonlySelectorFamily<T, K>
104
104
  export function selectorFamily__INTERNAL<T, K extends Serializable>(
105
- options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,
106
- store: Store = IMPLICIT.STORE
105
+ options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,
106
+ store: Store = IMPLICIT.STORE,
107
107
  ): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {
108
- const isReadonly = !(`set` in options)
108
+ const isReadonly = !(`set` in options)
109
109
 
110
- if (isReadonly) {
111
- return readonlySelectorFamily__INTERNAL(options, store)
112
- }
113
- const core = target(store)
114
- const subject = new Rx.Subject<SelectorToken<T>>()
110
+ if (isReadonly) {
111
+ return readonlySelectorFamily__INTERNAL(options, store)
112
+ }
113
+ const core = target(store)
114
+ const subject = new Rx.Subject<SelectorToken<T>>()
115
115
 
116
- return Object.assign(
117
- (key: K): SelectorToken<T> => {
118
- const subKey = stringifyJson(key)
119
- const family: FamilyMetadata = { key: options.key, subKey }
120
- const fullKey = `${options.key}(${subKey})`
121
- const existing = core.selectors.get(fullKey)
122
- if (existing) {
123
- return deposit(existing)
124
- }
125
- const token = selector__INTERNAL<T>(
126
- {
127
- key: fullKey,
128
- get: options.get(key),
129
- set: options.set(key),
130
- },
131
- family,
132
- store
133
- )
134
- subject.next(token)
135
- return token
136
- },
137
- {
138
- key: options.key,
139
- type: `selector_family`,
140
- } as const
141
- ) as SelectorFamily<T, K>
116
+ return Object.assign(
117
+ (key: K): SelectorToken<T> => {
118
+ const subKey = stringifyJson(key)
119
+ const family: FamilyMetadata = { key: options.key, subKey }
120
+ const fullKey = `${options.key}(${subKey})`
121
+ const existing = core.selectors.get(fullKey)
122
+ if (existing) {
123
+ return deposit(existing)
124
+ }
125
+ const token = selector__INTERNAL<T>(
126
+ {
127
+ key: fullKey,
128
+ get: options.get(key),
129
+ set: options.set(key),
130
+ },
131
+ family,
132
+ store,
133
+ )
134
+ subject.next(token)
135
+ return token
136
+ },
137
+ {
138
+ key: options.key,
139
+ type: `selector_family`,
140
+ } as const,
141
+ ) as SelectorFamily<T, K>
142
142
  }
@@ -3,85 +3,85 @@ import HAMT from "hamt_plus"
3
3
  import type { ƒn } from "~/packages/anvl/src/function"
4
4
 
5
5
  import type {
6
- Atom,
7
- ReadonlySelector,
8
- Selector,
9
- Store,
10
- Timeline,
11
- Transaction,
6
+ Atom,
7
+ ReadonlySelector,
8
+ Selector,
9
+ Store,
10
+ Timeline,
11
+ Transaction,
12
12
  } from "."
13
13
  import { target, isValueCached, readCachedValue, IMPLICIT } from "."
14
14
  import type {
15
- AtomToken,
16
- ReadonlySelectorToken,
17
- SelectorToken,
18
- StateToken,
19
- TimelineToken,
20
- TransactionToken,
15
+ AtomToken,
16
+ ReadonlySelectorToken,
17
+ SelectorToken,
18
+ StateToken,
19
+ TimelineToken,
20
+ TransactionToken,
21
21
  } from ".."
22
22
 
23
23
  export const computeSelectorState = <T>(
24
- selector: ReadonlySelector<T> | Selector<T>
24
+ selector: ReadonlySelector<T> | Selector<T>,
25
25
  ): T => selector.get()
26
26
 
27
27
  export function lookup(
28
- key: string,
29
- store: Store
28
+ key: string,
29
+ store: Store,
30
30
  ): AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown> {
31
- const core = target(store)
32
- const type = HAMT.has(key, core.atoms)
33
- ? `atom`
34
- : HAMT.has(key, core.selectors)
35
- ? `selector`
36
- : `readonly_selector`
37
- return { key, type } as any
31
+ const core = target(store)
32
+ const type = HAMT.has(key, core.atoms)
33
+ ? `atom`
34
+ : HAMT.has(key, core.selectors)
35
+ ? `selector`
36
+ : `readonly_selector`
37
+ return { key, type } as any
38
38
  }
39
39
 
40
40
  export function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | null
41
41
  export function withdraw<T>(
42
- token: SelectorToken<T>,
43
- store: Store
42
+ token: SelectorToken<T>,
43
+ store: Store,
44
44
  ): Selector<T> | null
45
45
  export function withdraw<T>(
46
- token: StateToken<T>,
47
- store: Store
46
+ token: StateToken<T>,
47
+ store: Store,
48
48
  ): Atom<T> | Selector<T> | null
49
49
  export function withdraw<T>(
50
- token: ReadonlySelectorToken<T>,
51
- store: Store
50
+ token: ReadonlySelectorToken<T>,
51
+ store: Store,
52
52
  ): ReadonlySelector<T> | null
53
53
  export function withdraw<T>(
54
- token: TransactionToken<T>,
55
- store: Store
54
+ token: TransactionToken<T>,
55
+ store: Store,
56
56
  ): Transaction<T extends ƒn ? T : never> | null
57
57
  export function withdraw<T>(
58
- token: ReadonlySelectorToken<T> | StateToken<T>,
59
- store: Store
58
+ token: ReadonlySelectorToken<T> | StateToken<T>,
59
+ store: Store,
60
60
  ): Atom<T> | ReadonlySelector<T> | Selector<T> | null
61
61
  export function withdraw<T>(token: TimelineToken, store: Store): Timeline | null
62
62
  export function withdraw<T>(
63
- token:
64
- | ReadonlySelectorToken<T>
65
- | StateToken<T>
66
- | TimelineToken
67
- | TransactionToken<T>,
68
- store: Store
63
+ token:
64
+ | ReadonlySelectorToken<T>
65
+ | StateToken<T>
66
+ | TimelineToken
67
+ | TransactionToken<T>,
68
+ store: Store,
69
69
  ):
70
- | Atom<T>
71
- | ReadonlySelector<T>
72
- | Selector<T>
73
- | Timeline
74
- | Transaction<T extends ƒn ? T : never>
75
- | null {
76
- const core = target(store)
77
- return (
78
- HAMT.get(token.key, core.atoms) ??
79
- HAMT.get(token.key, core.selectors) ??
80
- HAMT.get(token.key, core.readonlySelectors) ??
81
- HAMT.get(token.key, core.transactions) ??
82
- HAMT.get(token.key, core.timelines) ??
83
- null
84
- )
70
+ | Atom<T>
71
+ | ReadonlySelector<T>
72
+ | Selector<T>
73
+ | Timeline
74
+ | Transaction<T extends ƒn ? T : never>
75
+ | null {
76
+ const core = target(store)
77
+ return (
78
+ HAMT.get(token.key, core.atoms) ??
79
+ HAMT.get(token.key, core.selectors) ??
80
+ HAMT.get(token.key, core.readonlySelectors) ??
81
+ HAMT.get(token.key, core.transactions) ??
82
+ HAMT.get(token.key, core.timelines) ??
83
+ null
84
+ )
85
85
  }
86
86
 
87
87
  export function deposit<T>(state: Atom<T>): AtomToken<T>
@@ -89,43 +89,43 @@ export function deposit<T>(state: Selector<T>): SelectorToken<T>
89
89
  export function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>
90
90
  export function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>
91
91
  export function deposit<T>(
92
- state: Transaction<T extends ƒn ? T : never>
92
+ state: Transaction<T extends ƒn ? T : never>,
93
93
  ): TransactionToken<T>
94
94
  export function deposit<T>(
95
- state: Atom<T> | ReadonlySelector<T> | Selector<T>
95
+ state: Atom<T> | ReadonlySelector<T> | Selector<T>,
96
96
  ): ReadonlySelectorToken<T> | StateToken<T>
97
97
  export function deposit<T>(
98
- state:
99
- | Atom<T>
100
- | ReadonlySelector<T>
101
- | Selector<T>
102
- | Transaction<T extends ƒn ? T : never>
98
+ state:
99
+ | Atom<T>
100
+ | ReadonlySelector<T>
101
+ | Selector<T>
102
+ | Transaction<T extends ƒn ? T : never>,
103
103
  ):
104
- | AtomToken<T>
105
- | ReadonlySelectorToken<T>
106
- | SelectorToken<T>
107
- | TransactionToken<T> {
108
- return {
109
- key: state.key,
110
- type: state.type,
111
- ...(`family` in state && { family: state.family }),
112
- } as any
104
+ | AtomToken<T>
105
+ | ReadonlySelectorToken<T>
106
+ | SelectorToken<T>
107
+ | TransactionToken<T> {
108
+ return {
109
+ key: state.key,
110
+ type: state.type,
111
+ ...(`family` in state && { family: state.family }),
112
+ } as any
113
113
  }
114
114
 
115
115
  export const getState__INTERNAL = <T>(
116
- state: Atom<T> | ReadonlySelector<T> | Selector<T>,
117
- store: Store = IMPLICIT.STORE
116
+ state: Atom<T> | ReadonlySelector<T> | Selector<T>,
117
+ store: Store = IMPLICIT.STORE,
118
118
  ): T => {
119
- if (isValueCached(state.key, store)) {
120
- store.config.logger?.info(`>> read "${state.key}"`)
121
- return readCachedValue(state.key, store)
122
- }
123
- if (state.type !== `atom`) {
124
- store.config.logger?.info(`-> calc "${state.key}"`)
125
- return computeSelectorState(state)
126
- }
127
- store.config.logger?.error(
128
- `Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
129
- )
130
- return state.default
119
+ if (isValueCached(state.key, store)) {
120
+ store.config.logger?.info(`>> read "${state.key}"`)
121
+ return readCachedValue(state.key, store)
122
+ }
123
+ if (state.type !== `atom`) {
124
+ store.config.logger?.info(`-> calc "${state.key}"`)
125
+ return computeSelectorState(state)
126
+ }
127
+ store.config.logger?.error(
128
+ `Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`,
129
+ )
130
+ return state.default
131
131
  }
@@ -2,34 +2,34 @@ import type { Store } from "."
2
2
  import { target, IMPLICIT, traceAllSelectorAtoms } from "."
3
3
 
4
4
  export const isAtomDefault = (
5
- key: string,
6
- store: Store = IMPLICIT.STORE
5
+ key: string,
6
+ store: Store = IMPLICIT.STORE,
7
7
  ): boolean => {
8
- const core = target(store)
9
- return core.atomsThatAreDefault.has(key)
8
+ const core = target(store)
9
+ return core.atomsThatAreDefault.has(key)
10
10
  }
11
11
 
12
12
  export const markAtomAsDefault = (
13
- key: string,
14
- store: Store = IMPLICIT.STORE
13
+ key: string,
14
+ store: Store = IMPLICIT.STORE,
15
15
  ): void => {
16
- const core = target(store)
17
- core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)
16
+ const core = target(store)
17
+ core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)
18
18
  }
19
19
 
20
20
  export const markAtomAsNotDefault = (
21
- key: string,
22
- store: Store = IMPLICIT.STORE
21
+ key: string,
22
+ store: Store = IMPLICIT.STORE,
23
23
  ): void => {
24
- const core = target(store)
25
- core.atomsThatAreDefault = new Set(target(store).atomsThatAreDefault)
26
- core.atomsThatAreDefault.delete(key)
24
+ const core = target(store)
25
+ core.atomsThatAreDefault = new Set(target(store).atomsThatAreDefault)
26
+ core.atomsThatAreDefault.delete(key)
27
27
  }
28
28
 
29
29
  export const isSelectorDefault = (
30
- key: string,
31
- store: Store = IMPLICIT.STORE
30
+ key: string,
31
+ store: Store = IMPLICIT.STORE,
32
32
  ): boolean => {
33
- const roots = traceAllSelectorAtoms(key, store)
34
- return roots.every((root) => isAtomDefault(root.key, store))
33
+ const roots = traceAllSelectorAtoms(key, store)
34
+ return roots.every((root) => isAtomDefault(root.key, store))
35
35
  }
@@ -5,13 +5,13 @@ import type { Store } from "../store"
5
5
  import { IMPLICIT } from "../store"
6
6
 
7
7
  export const attachMetaState = (
8
- store: Store = IMPLICIT.STORE
8
+ store: Store = IMPLICIT.STORE,
9
9
  ): {
10
- atomTokenIndexState: ReadonlySelectorToken<AtomTokenIndex>
11
- selectorTokenIndexState: ReadonlySelectorToken<SelectorTokenIndex>
10
+ atomTokenIndexState: ReadonlySelectorToken<AtomTokenIndex>
11
+ selectorTokenIndexState: ReadonlySelectorToken<SelectorTokenIndex>
12
12
  } => {
13
- return {
14
- atomTokenIndexState: attachMetaAtoms(store),
15
- selectorTokenIndexState: attachMetaSelectors(store),
16
- }
13
+ return {
14
+ atomTokenIndexState: attachMetaAtoms(store),
15
+ selectorTokenIndexState: attachMetaSelectors(store),
16
+ }
17
17
  }