atom.io 0.15.6 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/data/dist/index.cjs +20 -22
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.ts +6 -6
  4. package/data/dist/index.js +21 -23
  5. package/data/dist/index.js.map +1 -1
  6. package/data/src/dict.ts +6 -7
  7. package/data/src/join.ts +23 -23
  8. package/data/src/struct-family.ts +2 -2
  9. package/data/src/struct.ts +4 -5
  10. package/dist/index.cjs +12 -5
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +67 -60
  13. package/dist/index.js +13 -6
  14. package/dist/index.js.map +1 -1
  15. package/internal/dist/index.cjs +910 -887
  16. package/internal/dist/index.cjs.map +1 -1
  17. package/internal/dist/index.d.ts +157 -162
  18. package/internal/dist/index.js +482 -458
  19. package/internal/dist/index.js.map +1 -1
  20. package/internal/src/atom/create-regular-atom.ts +9 -12
  21. package/internal/src/atom/create-standalone-atom.ts +33 -0
  22. package/internal/src/atom/delete-atom.ts +5 -2
  23. package/internal/src/atom/index.ts +1 -16
  24. package/internal/src/atom/is-default.ts +0 -1
  25. package/internal/src/caching.ts +6 -3
  26. package/internal/src/families/create-atom-family.ts +11 -7
  27. package/internal/src/families/create-readonly-selector-family.ts +4 -3
  28. package/internal/src/families/create-regular-atom-family.ts +12 -27
  29. package/internal/src/families/create-selector-family.ts +13 -49
  30. package/internal/src/families/create-writable-selector-family.ts +51 -0
  31. package/internal/src/index.ts +44 -3
  32. package/internal/src/lineage.ts +0 -7
  33. package/internal/src/mutable/create-mutable-atom-family.ts +61 -15
  34. package/internal/src/mutable/create-mutable-atom.ts +70 -25
  35. package/internal/src/mutable/get-json-family.ts +4 -5
  36. package/internal/src/mutable/get-json-token.ts +6 -3
  37. package/internal/src/mutable/get-update-token.ts +3 -3
  38. package/internal/src/mutable/index.ts +1 -7
  39. package/internal/src/mutable/is-mutable.ts +6 -7
  40. package/internal/src/mutable/tracker-family.ts +4 -4
  41. package/internal/src/mutable/tracker.ts +6 -6
  42. package/internal/src/read-or-compute-value.ts +6 -3
  43. package/internal/src/selector/create-readonly-selector.ts +2 -3
  44. package/internal/src/selector/create-standalone-selector.ts +32 -0
  45. package/internal/src/selector/{create-read-write-selector.ts → create-writable-selector.ts} +12 -9
  46. package/internal/src/selector/delete-selector.ts +2 -2
  47. package/internal/src/selector/index.ts +3 -1
  48. package/internal/src/selector/trace-selector-atoms.ts +3 -2
  49. package/internal/src/selector/update-selector-atoms.ts +1 -1
  50. package/internal/src/set-state/copy-mutable-if-needed.ts +5 -6
  51. package/internal/src/set-state/copy-mutable-in-transaction.ts +4 -36
  52. package/internal/src/set-state/emit-update.ts +2 -3
  53. package/internal/src/set-state/evict-downstream.ts +1 -1
  54. package/internal/src/set-state/set-atom-or-selector.ts +3 -3
  55. package/internal/src/set-state/set-atom.ts +1 -2
  56. package/internal/src/set-state/stow-update.ts +1 -1
  57. package/internal/src/store/deposit.ts +25 -13
  58. package/internal/src/store/store.ts +21 -21
  59. package/internal/src/store/withdraw-new-family-member.ts +16 -9
  60. package/internal/src/store/withdraw.ts +43 -19
  61. package/internal/src/subscribe/recall-state.ts +2 -6
  62. package/internal/src/subscribe/subscribe-to-root-atoms.ts +39 -41
  63. package/internal/src/subscribe/subscribe-to-state.ts +3 -1
  64. package/internal/src/timeline/add-atom-to-timeline.ts +5 -5
  65. package/internal/src/timeline/create-timeline.ts +19 -22
  66. package/introspection/dist/index.cjs +4 -8
  67. package/introspection/dist/index.cjs.map +1 -1
  68. package/introspection/dist/index.d.ts +5 -5
  69. package/introspection/dist/index.js +5 -9
  70. package/introspection/dist/index.js.map +1 -1
  71. package/introspection/src/attach-atom-index.ts +4 -5
  72. package/introspection/src/attach-selector-index.ts +4 -5
  73. package/introspection/src/attach-timeline-index.ts +6 -3
  74. package/introspection/src/attach-transaction-index.ts +6 -3
  75. package/introspection/src/index.ts +9 -5
  76. package/json/dist/index.cjs +3 -4
  77. package/json/dist/index.cjs.map +1 -1
  78. package/json/dist/index.d.ts +4 -3
  79. package/json/dist/index.js +4 -5
  80. package/json/dist/index.js.map +1 -1
  81. package/json/src/select-json-family.ts +24 -4
  82. package/json/src/select-json.ts +3 -4
  83. package/package.json +2 -2
  84. package/react-devtools/dist/index.cjs.map +1 -1
  85. package/react-devtools/dist/index.d.ts +9 -9
  86. package/react-devtools/dist/index.js.map +1 -1
  87. package/react-devtools/src/StateIndex.tsx +18 -10
  88. package/react-devtools/src/TimelineIndex.tsx +6 -2
  89. package/react-devtools/src/TransactionIndex.tsx +2 -2
  90. package/realtime-client/dist/index.cjs +27 -13
  91. package/realtime-client/dist/index.cjs.map +1 -1
  92. package/realtime-client/dist/index.d.ts +6 -4
  93. package/realtime-client/dist/index.js +20 -7
  94. package/realtime-client/dist/index.js.map +1 -1
  95. package/realtime-client/src/index.ts +4 -3
  96. package/realtime-client/src/server-action.ts +2 -55
  97. package/realtime-client/src/sync-server-action.ts +75 -0
  98. package/realtime-react/dist/index.cjs +22 -13
  99. package/realtime-react/dist/index.cjs.map +1 -1
  100. package/realtime-react/dist/index.d.ts +3 -1
  101. package/realtime-react/dist/index.js +20 -12
  102. package/realtime-react/dist/index.js.map +1 -1
  103. package/realtime-react/src/index.ts +1 -0
  104. package/realtime-react/src/use-server-action.ts +2 -4
  105. package/realtime-react/src/use-sync-server-action.ts +19 -0
  106. package/realtime-server/dist/index.cjs +83 -81
  107. package/realtime-server/dist/index.cjs.map +1 -1
  108. package/realtime-server/dist/index.d.ts +8 -8
  109. package/realtime-server/dist/index.js +58 -56
  110. package/realtime-server/dist/index.js.map +1 -1
  111. package/realtime-server/src/index.ts +15 -1
  112. package/realtime-server/src/{hook-composition/receive-transaction.ts → realtime-action-receiver.ts} +6 -2
  113. package/realtime-server/src/{hook-composition/sync-transaction.ts → realtime-action-synchronizer.ts} +10 -43
  114. package/realtime-server/src/{hook-composition/expose-family.ts → realtime-family-provider.ts} +9 -23
  115. package/realtime-server/src/{hook-composition/expose-mutable-family.ts → realtime-mutable-family-provider.ts} +4 -4
  116. package/realtime-server/src/{hook-composition/expose-mutable.ts → realtime-mutable-provider.ts} +4 -5
  117. package/realtime-server/src/realtime-server-store.ts +39 -0
  118. package/realtime-server/src/{hook-composition/expose-single.ts → realtime-state-provider.ts} +7 -8
  119. package/realtime-server/src/{hook-composition/receive-state.ts → realtime-state-receiver.ts} +7 -4
  120. package/src/atom.ts +39 -24
  121. package/src/find-state.ts +20 -19
  122. package/src/index.ts +41 -28
  123. package/src/logger.ts +1 -0
  124. package/src/selector.ts +31 -16
  125. package/src/silo.ts +45 -6
  126. package/src/subscribe.ts +1 -0
  127. package/src/validators.ts +35 -25
  128. package/internal/src/atom/create-atom.ts +0 -21
  129. package/internal/src/mutable/get-update-family.ts +0 -23
  130. package/internal/src/selector/create-selector.ts +0 -65
  131. package/realtime-server/src/hook-composition/index.ts +0 -15
  132. /package/realtime-client/src/{pull.ts → pull-state.ts} +0 -0
  133. /package/realtime-client/src/{push.ts → push-state.ts} +0 -0
  134. /package/realtime-client/src/{realtime-state.ts → realtime-client-store.ts} +0 -0
@@ -1,35 +1,47 @@
1
1
  import type {
2
- AtomToken,
2
+ MutableAtomToken,
3
3
  ReadableToken,
4
4
  ReadonlySelectorToken,
5
+ RegularAtomToken,
5
6
  SelectorToken,
6
7
  TransactionToken,
8
+ WritableSelectorToken,
7
9
  WritableToken,
8
10
  ƒn,
9
11
  } from "atom.io"
10
12
 
11
- import type { StateNode } from ".."
12
- import type { Atom } from "../atom"
13
- import type { ReadonlySelector, Selector } from "../selector"
13
+ import type {
14
+ MutableAtom,
15
+ ReadableState,
16
+ ReadonlySelector,
17
+ RegularAtom,
18
+ Transceiver,
19
+ WritableSelector,
20
+ WritableState,
21
+ } from ".."
14
22
  import type { Transaction } from "../transaction"
15
23
 
16
- export function deposit<T>(state: Atom<T>): AtomToken<T>
17
- export function deposit<T>(state: Selector<T>): SelectorToken<T>
18
- export function deposit<T>(state: Atom<T> | Selector<T>): WritableToken<T>
24
+ export function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>
25
+ export function deposit<T extends Transceiver<any>>(
26
+ state: MutableAtom<T, any>,
27
+ ): MutableAtomToken<T, any>
28
+ export function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>
19
29
  export function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>
30
+ export function deposit<T>(state: WritableState<T>): WritableToken<T>
20
31
  export function deposit<T>(
21
32
  state: Transaction<T extends ƒn ? T : never>,
22
33
  ): TransactionToken<T>
23
- export function deposit<T>(state: StateNode<T>): ReadableToken<T>
34
+ export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
24
35
  export function deposit<T>(
25
36
  state:
26
- | Atom<T>
27
37
  | ReadonlySelector<T>
28
- | Selector<T>
29
- | Transaction<T extends ƒn ? T : never>,
38
+ | RegularAtom<T>
39
+ | Transaction<T extends ƒn ? T : never>
40
+ | WritableSelector<T>
41
+ | (T extends Transceiver<any> ? MutableAtom<T, any> : never),
30
42
  ):
31
- | AtomToken<T>
32
- | ReadonlySelectorToken<T>
43
+ | MutableAtomToken<T extends Transceiver<any> ? T : never, any>
44
+ | RegularAtomToken<T>
33
45
  | SelectorToken<T>
34
46
  | TransactionToken<T> {
35
47
  const token = {
@@ -1,30 +1,31 @@
1
1
  import { AtomIOLogger } from "atom.io"
2
2
  import type {
3
- AtomFamily,
4
3
  AtomToken,
5
4
  Logger,
5
+ MutableAtomFamily,
6
6
  ReadonlySelectorFamily,
7
7
  ReadonlySelectorToken,
8
- SelectorFamily,
9
- SelectorToken,
8
+ RegularAtomFamily,
9
+ RegularAtomToken,
10
10
  TimelineToken,
11
11
  TransactionToken,
12
+ WritableSelectorFamily,
13
+ WritableSelectorToken,
12
14
  ƒn,
13
15
  } from "atom.io"
14
16
 
15
17
  import { Junction } from "~/packages/rel8/junction/src"
16
18
 
17
- import type { Atom } from "../atom"
19
+ import type {
20
+ Atom,
21
+ ReadonlySelector,
22
+ Tracker,
23
+ Transceiver,
24
+ WritableSelector,
25
+ } from ".."
18
26
  import type { Lineage } from "../lineage"
19
- import {
20
- type MutableAtom,
21
- type Tracker,
22
- type Transceiver,
23
- getJsonToken,
24
- getUpdateToken,
25
- } from "../mutable"
27
+ import { getJsonToken, getUpdateToken } from "../mutable"
26
28
  import type { OperationProgress } from "../operation"
27
- import type { ReadonlySelector, Selector } from "../selector"
28
29
  import { StatefulSubject, Subject } from "../subject"
29
30
  import type { Timeline } from "../timeline"
30
31
  import type { Transaction, TransactionMeta } from "../transaction"
@@ -35,16 +36,17 @@ export class Store implements Lineage {
35
36
 
36
37
  public valueMap = new Map<string, any>()
37
38
 
38
- public atoms = new Map<string, Atom<any> | MutableAtom<any>>()
39
- public selectors = new Map<string, Selector<any>>()
39
+ public atoms = new Map<string, Atom<any>>()
40
+ public selectors = new Map<string, WritableSelector<any>>()
40
41
  public readonlySelectors = new Map<string, ReadonlySelector<any>>()
41
42
 
42
43
  public trackers = new Map<string, Tracker<Transceiver<any>>>()
43
44
  public families = new Map<
44
45
  string,
45
- | AtomFamily<any, any>
46
+ | MutableAtomFamily<any, any, any>
46
47
  | ReadonlySelectorFamily<any, any>
47
- | SelectorFamily<any, any>
48
+ | RegularAtomFamily<any, any>
49
+ | WritableSelectorFamily<any, any>
48
50
  >()
49
51
 
50
52
  public timelines = new Map<string, Timeline<any>>()
@@ -77,7 +79,7 @@ export class Store implements Lineage {
77
79
  public on = {
78
80
  atomCreation: new Subject<AtomToken<unknown>>(),
79
81
  selectorCreation: new Subject<
80
- ReadonlySelectorToken<unknown> | SelectorToken<unknown>
82
+ ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>
81
83
  >(),
82
84
  transactionCreation: new Subject<TransactionToken<ƒn>>(),
83
85
  timelineCreation: new Subject<TimelineToken<unknown>>(),
@@ -112,9 +114,7 @@ export class Store implements Lineage {
112
114
  if (store !== null) {
113
115
  this.valueMap = new Map(store?.valueMap)
114
116
  this.operation = { ...store?.operation }
115
- this.transactionMeta = store?.transactionMeta
116
- ? { ...store?.transactionMeta }
117
- : null
117
+ this.transactionMeta = null
118
118
  this.config = {
119
119
  ...store?.config,
120
120
  name,
@@ -128,7 +128,7 @@ export class Store implements Lineage {
128
128
  continue
129
129
  }
130
130
  atom.install(this)
131
- if (`mutable` in atom) {
131
+ if (atom.type === `mutable_atom`) {
132
132
  const originalJsonToken = getJsonToken(atom)
133
133
  const originalUpdateToken = getUpdateToken(atom)
134
134
  mutableHelpers.add(originalJsonToken.key)
@@ -1,21 +1,28 @@
1
1
  import type {
2
- AtomToken,
3
2
  ReadableToken,
4
3
  ReadonlySelectorToken,
5
- SelectorToken,
4
+ RegularAtomToken,
5
+ WritableSelectorToken,
6
6
  WritableToken,
7
7
  } from "atom.io"
8
- import type { Atom, ReadonlySelector, Selector, StateNode, Store } from ".."
8
+ import type {
9
+ Atom,
10
+ ReadableState,
11
+ ReadonlySelector,
12
+ Store,
13
+ WritableSelector,
14
+ WritableState,
15
+ } from ".."
9
16
  import { newest, withdraw } from ".."
10
17
 
11
18
  export function withdrawNewFamilyMember<T>(
12
- token: AtomToken<T>,
19
+ token: RegularAtomToken<T>,
13
20
  store: Store,
14
21
  ): Atom<T> | undefined
15
22
  export function withdrawNewFamilyMember<T>(
16
- token: SelectorToken<T>,
23
+ token: WritableSelectorToken<T>,
17
24
  store: Store,
18
- ): Selector<T> | undefined
25
+ ): WritableSelector<T> | undefined
19
26
  export function withdrawNewFamilyMember<T>(
20
27
  token: ReadonlySelectorToken<T>,
21
28
  store: Store,
@@ -23,15 +30,15 @@ export function withdrawNewFamilyMember<T>(
23
30
  export function withdrawNewFamilyMember<T>(
24
31
  token: WritableToken<T>,
25
32
  store: Store,
26
- ): Atom<T> | Selector<T> | undefined
33
+ ): WritableState<T> | undefined
27
34
  export function withdrawNewFamilyMember<T>(
28
35
  token: ReadableToken<T>,
29
36
  store: Store,
30
- ): StateNode<T> | undefined
37
+ ): ReadableState<T> | undefined
31
38
  export function withdrawNewFamilyMember<T>(
32
39
  token: ReadableToken<T>,
33
40
  store: Store,
34
- ): StateNode<T> | undefined {
41
+ ): ReadableState<T> | undefined {
35
42
  if (token.family) {
36
43
  store.logger.info(
37
44
  `👪`,
@@ -1,33 +1,55 @@
1
1
  import type {
2
2
  AtomToken,
3
+ MutableAtomToken,
3
4
  ReadableToken,
4
5
  ReadonlySelectorToken,
6
+ RegularAtomToken,
5
7
  SelectorToken,
6
8
  TimelineManageable,
7
9
  TimelineToken,
8
10
  TransactionToken,
11
+ WritableSelectorToken,
9
12
  WritableToken,
10
13
  ƒn,
11
14
  } from "atom.io"
12
15
 
13
- import type { StateNode } from ".."
14
- import type { Atom } from "../atom"
15
- import type { ReadonlySelector, Selector } from "../selector"
16
+ import type {
17
+ Atom,
18
+ MutableAtom,
19
+ ReadableState,
20
+ ReadonlySelector,
21
+ RegularAtom,
22
+ Selector,
23
+ Transceiver,
24
+ WritableSelector,
25
+ WritableState,
26
+ } from ".."
16
27
  import type { Timeline } from "../timeline"
17
28
  import type { Transaction } from "../transaction"
18
29
  import type { Store } from "./store"
19
30
 
20
- type Withdrawable<T> =
21
- | Atom<T>
22
- | ReadonlySelector<T>
23
- | Selector<T>
24
- | Timeline<T extends TimelineManageable ? T : never>
25
- | Transaction<T extends ƒn ? T : never>
31
+ export type Withdrawable = ReadableState<any> | Timeline<any> | Transaction<any>
26
32
 
33
+ export function withdraw<T>(
34
+ token: RegularAtomToken<T>,
35
+ store: Store,
36
+ ): RegularAtom<T> | undefined
37
+ export function withdraw<T extends Transceiver<any>>(
38
+ token: MutableAtomToken<T, any>,
39
+ store: Store,
40
+ ): MutableAtom<T, any> | undefined
27
41
  export function withdraw<T>(
28
42
  token: AtomToken<T>,
29
43
  store: Store,
30
44
  ): Atom<T> | undefined
45
+ export function withdraw<T>(
46
+ token: WritableSelectorToken<T>,
47
+ store: Store,
48
+ ): WritableSelector<T> | undefined
49
+ export function withdraw<T>(
50
+ token: ReadonlySelectorToken<T>,
51
+ store: Store,
52
+ ): ReadonlySelector<T> | undefined
31
53
  export function withdraw<T>(
32
54
  token: SelectorToken<T>,
33
55
  store: Store,
@@ -35,32 +57,34 @@ export function withdraw<T>(
35
57
  export function withdraw<T>(
36
58
  token: WritableToken<T>,
37
59
  store: Store,
38
- ): Atom<T> | Selector<T> | undefined
60
+ ): WritableState<T> | undefined
39
61
  export function withdraw<T>(
40
- token: ReadonlySelectorToken<T>,
62
+ token: ReadableToken<T>,
41
63
  store: Store,
42
- ): ReadonlySelector<T> | undefined
64
+ ): ReadableState<T> | undefined
43
65
  export function withdraw<T>(
44
66
  token: TransactionToken<T>,
45
67
  store: Store,
46
68
  ): Transaction<T extends ƒn ? T : never> | undefined
47
- export function withdraw<T>(
48
- token: ReadableToken<T>,
49
- store: Store,
50
- ): StateNode<T> | undefined
51
69
  export function withdraw<T>(
52
70
  token: TimelineToken<T>,
53
71
  store: Store,
54
72
  ): Timeline<T extends TimelineManageable ? T : never> | undefined
55
73
  export function withdraw<T>(
56
- token: ReadableToken<T> | TimelineToken<T> | TransactionToken<T>,
74
+ token:
75
+ | RegularAtomToken<T>
76
+ | SelectorToken<T>
77
+ | TimelineToken<T>
78
+ | TransactionToken<T>
79
+ | (T extends Transceiver<any> ? MutableAtomToken<T, any> : never),
57
80
  store: Store,
58
- ): Withdrawable<T> | undefined {
59
- let withdrawn: Withdrawable<T> | undefined
81
+ ): Withdrawable | undefined {
82
+ let withdrawn: Withdrawable | undefined
60
83
  let target: Store | null = store
61
84
  while (target !== null) {
62
85
  switch (token.type) {
63
86
  case `atom`:
87
+ case `mutable_atom`:
64
88
  withdrawn = target.atoms.get(token.key)
65
89
  break
66
90
  case `selector`:
@@ -1,12 +1,8 @@
1
- import type { Atom } from "../atom"
1
+ import type { ReadableState } from ".."
2
2
  import { newest } from "../lineage"
3
- import type { ReadonlySelector, Selector } from "../selector"
4
3
  import type { Store } from "../store"
5
4
 
6
- export const recallState = <T>(
7
- state: Atom<T> | ReadonlySelector<T> | Selector<T>,
8
- store: Store,
9
- ): T => {
5
+ export const recallState = <T>(state: ReadableState<T>, store: Store): T => {
10
6
  const target = newest(store)
11
7
  if (!target.operation.open) {
12
8
  return target.valueMap.get(state.key)
@@ -1,54 +1,52 @@
1
+ import type { Selector } from ".."
1
2
  import { newest } from "../lineage"
2
3
  import { readOrComputeValue } from "../read-or-compute-value"
3
- import type { ReadonlySelector, Selector } from "../selector"
4
4
  import { traceAllSelectorAtoms } from "../selector"
5
5
  import type { Store } from "../store"
6
6
  import { recallState } from "./recall-state"
7
7
 
8
8
  export const subscribeToRootAtoms = <T>(
9
- state: ReadonlySelector<T> | Selector<T>,
9
+ selector: Selector<T>,
10
10
  store: Store,
11
11
  ): (() => void)[] | null => {
12
12
  const target = newest(store)
13
- const dependencySubscriptions =
14
- `default` in state
15
- ? null
16
- : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
17
- const atom = target.atoms.get(atomKey)
18
- if (atom === undefined) {
19
- throw new Error(
20
- `Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`,
21
- )
22
- }
23
- return atom.subject.subscribe(
24
- `${state.type}:${state.key}`,
25
- (atomChange) => {
26
- store.logger.info(
27
- `📢`,
28
- state.type,
29
- state.key,
30
- `root`,
31
- atomKey,
32
- `went`,
33
- atomChange.oldValue,
34
- `->`,
35
- atomChange.newValue,
36
- )
37
- const oldValue = recallState(state, target)
38
- // ❌ this retrieves a stale cached value when applying a transaction on the server
39
- const newValue = readOrComputeValue(state, target)
40
- store.logger.info(
41
- `✨`,
42
- state.type,
43
- state.key,
44
- `went`,
45
- oldValue,
46
- `->`,
47
- newValue,
48
- )
49
- state.subject.next({ newValue, oldValue })
50
- },
13
+ const dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(
14
+ (atomKey) => {
15
+ const atom = target.atoms.get(atomKey)
16
+ if (atom === undefined) {
17
+ throw new Error(
18
+ `Atom "${atomKey}", a dependency of selector "${selector.key}", not found in store "${store.config.name}".`,
19
+ )
20
+ }
21
+ return atom.subject.subscribe(
22
+ `${selector.type}:${selector.key}`,
23
+ (atomChange) => {
24
+ store.logger.info(
25
+ `📢`,
26
+ selector.type,
27
+ selector.key,
28
+ `root`,
29
+ atomKey,
30
+ `went`,
31
+ atomChange.oldValue,
32
+ `->`,
33
+ atomChange.newValue,
51
34
  )
52
- })
35
+ const oldValue = recallState(selector, target)
36
+ const newValue = readOrComputeValue(selector, target)
37
+ store.logger.info(
38
+ `✨`,
39
+ selector.type,
40
+ selector.key,
41
+ `went`,
42
+ oldValue,
43
+ `->`,
44
+ newValue,
45
+ )
46
+ selector.subject.next({ newValue, oldValue })
47
+ },
48
+ )
49
+ },
50
+ )
53
51
  return dependencySubscriptions
54
52
  }
@@ -19,7 +19,9 @@ export function subscribeToState<T>(
19
19
  const unsubFunction = state.subject.subscribe(key, handleUpdate)
20
20
  store.logger.info(`👀`, state.type, state.key, `Adding subscription "${key}"`)
21
21
  const dependencyUnsubFunctions =
22
- state.type !== `atom` ? subscribeToRootAtoms(state, store) : null
22
+ state.type !== `atom` && state.type !== `mutable_atom`
23
+ ? subscribeToRootAtoms(state, store)
24
+ : null
23
25
 
24
26
  const unsubscribe =
25
27
  dependencyUnsubFunctions === null
@@ -1,5 +1,5 @@
1
- import type { TransactionUpdate, ƒn } from "atom.io"
2
- import type { AtomToken, TimelineUpdate } from "atom.io"
1
+ import type { AtomToken, TransactionUpdate, ƒn } from "atom.io"
2
+ import type { TimelineUpdate } from "atom.io"
3
3
 
4
4
  import { newest } from "../lineage"
5
5
  import { getUpdateToken } from "../mutable"
@@ -17,9 +17,8 @@ export const addAtomToTimeline = (
17
17
  store: Store,
18
18
  ): void => {
19
19
  let maybeAtom = withdraw(atomToken, store)
20
- if (maybeAtom?.mutable) {
21
- console.log(`adding transceiver to timeline`, atomToken.key)
22
- const updateToken = getUpdateToken(atomToken)
20
+ if (maybeAtom?.type === `mutable_atom`) {
21
+ const updateToken = getUpdateToken(maybeAtom)
23
22
  maybeAtom = withdraw(updateToken, store)
24
23
  }
25
24
  const atom = maybeAtom
@@ -28,6 +27,7 @@ export const addAtomToTimeline = (
28
27
  `Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`,
29
28
  )
30
29
  }
30
+ store.timelineAtoms.set({ atomKey: atom.key, timelineKey: tl.key })
31
31
 
32
32
  atom.subject.subscribe(`timeline`, (update) => {
33
33
  // debugger
@@ -1,6 +1,5 @@
1
1
  import type {
2
2
  AtomFamily,
3
- AtomToken,
4
3
  FamilyMetadata,
5
4
  StateUpdate,
6
5
  TimelineManageable,
@@ -13,9 +12,7 @@ import type {
13
12
  } from "atom.io"
14
13
 
15
14
  import { newest } from "../lineage"
16
- import { getUpdateToken } from "../mutable"
17
- import { getUpdateFamily } from "../mutable/get-update-family"
18
- import { isMutable } from "../mutable/is-mutable"
15
+ import { getUpdateToken, isMutable } from "../mutable"
19
16
  import { type Store, withdraw } from "../store"
20
17
  import { Subject } from "../subject"
21
18
  import { addAtomToTimeline } from "./add-atom-to-timeline"
@@ -85,27 +82,18 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
85
82
  const target = newest(store)
86
83
  for (const tokenOrFamily of options.atoms) {
87
84
  let atomKey = tokenOrFamily.key
88
- const existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey)
89
- if (existingTimelineKey) {
90
- store.logger.error(
91
- `❌`,
92
- `timeline`,
93
- options.key,
94
- `Failed to add atom "${atomKey}" because it already belongs to timeline "${existingTimelineKey}"`,
95
- )
96
- continue
97
- }
98
- if (tokenOrFamily.type === `atom_family`) {
99
- let family: AtomFamily<any> = tokenOrFamily
100
- if (isMutable(family)) {
101
- family = getUpdateFamily(family, store)
102
- atomKey = family.key
103
- }
85
+ if (
86
+ tokenOrFamily.type === `atom_family` ||
87
+ tokenOrFamily.type === `mutable_atom_family`
88
+ ) {
89
+ const family: AtomFamily<any> = tokenOrFamily
90
+ const familyKey = family.key
91
+ target.timelineAtoms.set({ atomKey: familyKey, timelineKey })
104
92
  family.subject.subscribe(`timeline:${options.key}`, (token) => {
105
93
  addAtomToTimeline(token, tl, store)
106
94
  })
107
95
  for (const atom of target.atoms.values()) {
108
- if (atom.family?.key === family.key) {
96
+ if (atom.family?.key === familyKey) {
109
97
  addAtomToTimeline(atom, tl, store)
110
98
  }
111
99
  }
@@ -148,9 +136,18 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
148
136
  continue
149
137
  }
150
138
  }
139
+ const existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey)
140
+ if (existingTimelineKey) {
141
+ store.logger.error(
142
+ `❌`,
143
+ `timeline`,
144
+ options.key,
145
+ `Failed to add atom "${atomKey}" because it already belongs to timeline "${existingTimelineKey}"`,
146
+ )
147
+ continue
148
+ }
151
149
  addAtomToTimeline(atom, tl, store)
152
150
  }
153
- target.timelineAtoms.set({ atomKey, timelineKey })
154
151
  }
155
152
 
156
153
  store.timelines.set(options.key, tl)
@@ -99,12 +99,11 @@ var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
99
99
  void 0,
100
100
  store
101
101
  );
102
- return Internal.createSelector(
102
+ return Internal.createStandaloneSelector(
103
103
  {
104
104
  key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index`,
105
105
  get: ({ get }) => get(atomTokenIndexState__INTERNAL)
106
106
  },
107
- void 0,
108
107
  store
109
108
  );
110
109
  };
@@ -172,12 +171,11 @@ var attachSelectorIndex = (store = Internal.IMPLICIT.STORE) => {
172
171
  void 0,
173
172
  store
174
173
  );
175
- return Internal.createSelector(
174
+ return Internal.createStandaloneSelector(
176
175
  {
177
176
  key: `\u{1F441}\u200D\u{1F5E8} Selector Token Index`,
178
177
  get: ({ get }) => get(readonlySelectorTokenIndexState__INTERNAL)
179
178
  },
180
- void 0,
181
179
  Internal.IMPLICIT.STORE
182
180
  );
183
181
  };
@@ -253,12 +251,11 @@ var attachTimelineIndex = (store = Internal.IMPLICIT.STORE) => {
253
251
  void 0,
254
252
  store
255
253
  );
256
- const timelineTokenIndex = Internal.createSelector(
254
+ const timelineTokenIndex = Internal.createStandaloneSelector(
257
255
  {
258
256
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Token Index`,
259
257
  get: ({ get }) => get(timelineTokenIndexState__INTERNAL)
260
258
  },
261
- void 0,
262
259
  store
263
260
  );
264
261
  return timelineTokenIndex;
@@ -284,12 +281,11 @@ var attachTransactionIndex = (store = Internal.IMPLICIT.STORE) => {
284
281
  void 0,
285
282
  store
286
283
  );
287
- const transactionTokenIndex = Internal.createSelector(
284
+ const transactionTokenIndex = Internal.createStandaloneSelector(
288
285
  {
289
286
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Token Index`,
290
287
  get: ({ get }) => get(transactionTokenIndexState__INTERNAL)
291
288
  },
292
- void 0,
293
289
  store
294
290
  );
295
291
  return transactionTokenIndex;