atom.io 0.31.0 → 0.32.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 (171) hide show
  1. package/data/dist/index.d.ts +867 -101
  2. package/data/dist/index.js +10 -558
  3. package/data/src/index.ts +0 -2
  4. package/data/src/struct-family.ts +1 -1
  5. package/data/src/struct.ts +1 -2
  6. package/dist/chunk-354XQWHH.js +153 -0
  7. package/dist/chunk-4LWKCEW3.js +14 -0
  8. package/dist/chunk-5F2V7S3B.js +83 -0
  9. package/dist/chunk-ECOMOMUN.js +631 -0
  10. package/dist/{chunk-42UH5F5Q.js → chunk-GY2XQYZY.js} +2051 -755
  11. package/dist/chunk-NF7FJKJD.js +107 -0
  12. package/dist/chunk-R3ZUK5EH.js +1024 -0
  13. package/dist/chunk-Z2UJW4NQ.js +523 -0
  14. package/dist/index.d.ts +855 -127
  15. package/dist/index.js +1 -143
  16. package/eslint-plugin/dist/index.d.ts +1 -30
  17. package/eslint-plugin/dist/index.js +0 -146
  18. package/eslint-plugin/src/index.ts +0 -1
  19. package/eslint-plugin/src/rules/index.ts +0 -1
  20. package/internal/dist/index.d.ts +794 -70
  21. package/internal/dist/index.js +1 -2
  22. package/internal/src/atom/create-regular-atom.ts +3 -3
  23. package/internal/src/atom/dispose-atom.ts +4 -13
  24. package/internal/src/atom/is-default.ts +3 -3
  25. package/internal/src/caching.ts +5 -5
  26. package/internal/src/capitalize.ts +3 -0
  27. package/internal/src/families/create-readonly-selector-family.ts +5 -6
  28. package/internal/src/families/create-writable-selector-family.ts +1 -4
  29. package/internal/src/families/dispose-from-store.ts +3 -13
  30. package/internal/src/families/find-in-store.ts +1 -6
  31. package/internal/src/get-state/get-from-store.ts +2 -2
  32. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  33. package/internal/src/index.ts +19 -9
  34. package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
  35. package/internal/src/install-into-store.ts +48 -0
  36. package/internal/src/join/edit-relations-in-store.ts +32 -0
  37. package/internal/src/join/find-relations-in-store.ts +124 -0
  38. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  39. package/internal/src/join/get-join.ts +31 -0
  40. package/internal/src/join/index.ts +5 -0
  41. package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
  42. package/internal/src/keys.ts +7 -7
  43. package/internal/src/molecule.ts +299 -0
  44. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  45. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  46. package/internal/src/mutable/get-json-token.ts +1 -1
  47. package/internal/src/mutable/tracker-family.ts +19 -17
  48. package/internal/src/mutable/tracker.ts +8 -8
  49. package/internal/src/not-found-error.ts +8 -30
  50. package/internal/src/pretty-print.ts +2 -13
  51. package/internal/src/selector/create-readonly-selector.ts +3 -7
  52. package/internal/src/selector/create-writable-selector.ts +4 -4
  53. package/internal/src/selector/dispose-selector.ts +20 -11
  54. package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
  55. package/internal/src/selector/register-selector.ts +7 -17
  56. package/internal/src/selector/trace-selector-atoms.ts +2 -2
  57. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  58. package/internal/src/set-state/emit-update.ts +1 -1
  59. package/internal/src/set-state/evict-downstream.ts +1 -1
  60. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  61. package/internal/src/set-state/set-atom.ts +10 -10
  62. package/internal/src/set-state/set-into-store.ts +2 -2
  63. package/internal/src/set-state/stow-update.ts +1 -1
  64. package/internal/src/store/deposit.ts +10 -8
  65. package/internal/src/store/store.ts +1 -1
  66. package/internal/src/store/withdraw.ts +34 -53
  67. package/internal/src/subscribe/recall-state.ts +1 -1
  68. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  69. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  70. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  71. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  72. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  73. package/internal/src/timeline/create-timeline.ts +17 -37
  74. package/internal/src/transaction/act-upon-store.ts +2 -2
  75. package/internal/src/transaction/apply-transaction.ts +5 -5
  76. package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
  77. package/internal/src/transaction/build-transaction.ts +5 -8
  78. package/internal/src/transaction/create-transaction.ts +3 -3
  79. package/internal/src/transaction/get-epoch-number.ts +3 -3
  80. package/internal/src/transaction/set-epoch-number.ts +2 -2
  81. package/introspection/dist/index.d.ts +922 -6
  82. package/introspection/dist/index.js +2 -620
  83. package/json/dist/index.d.ts +899 -5
  84. package/json/dist/index.js +1 -81
  85. package/json/src/select-json-family.ts +3 -14
  86. package/package.json +27 -45
  87. package/react/dist/index.d.ts +921 -3
  88. package/react/dist/index.js +2 -82
  89. package/react/src/use-o.ts +1 -1
  90. package/react/src/use-tl.ts +2 -2
  91. package/react-devtools/dist/index.css +16 -14
  92. package/react-devtools/dist/index.d.ts +26 -1
  93. package/react-devtools/dist/index.js +6 -6
  94. package/react-devtools/src/devtools.scss +16 -14
  95. package/realtime/dist/index.d.ts +202 -8
  96. package/realtime/dist/index.js +2 -107
  97. package/realtime/src/realtime-continuity.ts +2 -2
  98. package/realtime/src/shared-room-store.ts +1 -2
  99. package/realtime-client/dist/index.d.ts +960 -22
  100. package/realtime-client/dist/index.js +3 -509
  101. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  102. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  103. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  104. package/realtime-client/src/pull-atom.ts +2 -2
  105. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  106. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  107. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  108. package/realtime-client/src/pull-selector.ts +4 -4
  109. package/realtime-client/src/push-state.ts +5 -10
  110. package/realtime-client/src/server-action.ts +4 -4
  111. package/realtime-client/src/sync-continuity.ts +6 -6
  112. package/realtime-react/dist/index.d.ts +166 -12
  113. package/realtime-react/dist/index.js +5 -154
  114. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  115. package/realtime-react/src/use-pull-atom.ts +1 -1
  116. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  117. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  118. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  119. package/realtime-react/src/use-pull-selector.ts +1 -1
  120. package/realtime-react/src/use-push.ts +1 -1
  121. package/realtime-react/src/use-server-action.ts +2 -2
  122. package/realtime-react/src/use-sync-continuity.ts +1 -1
  123. package/realtime-server/dist/index.d.ts +971 -28
  124. package/realtime-server/dist/index.js +3 -1001
  125. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  126. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  127. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  128. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  129. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  130. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  131. package/realtime-server/src/realtime-family-provider.ts +2 -2
  132. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  133. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  134. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  135. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  136. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  137. package/realtime-server/src/realtime-state-provider.ts +2 -2
  138. package/realtime-testing/dist/index.d.ts +1091 -3
  139. package/realtime-testing/dist/index.js +23 -26
  140. package/realtime-testing/src/setup-realtime-test.tsx +6 -5
  141. package/src/atom.ts +53 -29
  142. package/src/dispose-state.ts +12 -2
  143. package/{ephemeral/src → src}/find-state.ts +35 -25
  144. package/src/get-state.ts +16 -0
  145. package/src/index.ts +77 -3
  146. package/src/join.ts +218 -0
  147. package/src/realm.ts +169 -0
  148. package/src/selector.ts +20 -0
  149. package/src/set-state.ts +16 -8
  150. package/src/silo.ts +13 -7
  151. package/src/timeline.ts +1 -1
  152. package/src/transaction.ts +4 -8
  153. package/transceivers/set-rtx/dist/index.d.ts +37 -2
  154. package/transceivers/set-rtx/dist/index.js +1 -212
  155. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  156. package/web/dist/index.d.ts +30 -1
  157. package/web/dist/index.js +1 -15
  158. package/data/src/until.ts +0 -15
  159. package/dist/chunk-ICGFFQ3H.js +0 -272
  160. package/ephemeral/dist/index.d.ts +0 -57
  161. package/ephemeral/dist/index.js +0 -9
  162. package/ephemeral/package.json +0 -13
  163. package/ephemeral/src/index.ts +0 -1
  164. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  165. package/immortal/dist/index.d.ts +0 -12
  166. package/immortal/dist/index.js +0 -9
  167. package/immortal/package.json +0 -13
  168. package/immortal/src/index.ts +0 -1
  169. package/immortal/src/seek-state.ts +0 -60
  170. package/src/allocate.ts +0 -443
  171. package/src/molecule.ts +0 -16
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ findState,
2
3
  ReadableFamilyToken,
3
4
  ReadableToken,
4
5
  setState,
@@ -6,15 +7,12 @@ import type {
6
7
  WritableFamilyToken,
7
8
  WritableToken,
8
9
  } from "atom.io"
9
- import type { findState } from "atom.io/ephemeral"
10
- import type { seekState } from "atom.io/immortal"
11
10
  import type { Json } from "atom.io/json"
12
11
 
13
- import { findInStore, seekInStore } from "../families"
12
+ import { findInStore } from "../families"
14
13
  import { readOrComputeValue } from "../get-state/read-or-compute-value"
15
14
  import { newest } from "../lineage"
16
15
  import { getJsonToken } from "../mutable"
17
- import { NotFoundError } from "../not-found-error"
18
16
  import { setAtomOrSelector } from "../set-state"
19
17
  import type { Store } from "../store"
20
18
  import { withdraw } from "../store"
@@ -40,8 +38,8 @@ export const registerSelector = (
40
38
  ;[dependency] = params
41
39
  }
42
40
 
43
- const dependencyState = withdraw(dependency, store)
44
- const dependencyValue = readOrComputeValue(dependencyState, store)
41
+ const dependencyState = withdraw(store, dependency)
42
+ const dependencyValue = readOrComputeValue(store, dependencyState)
45
43
 
46
44
  store.logger.info(
47
45
  `🔌`,
@@ -82,20 +80,12 @@ export const registerSelector = (
82
80
  const family = params[0]
83
81
  const key = params[1]
84
82
  value = params[2]
85
- const maybeToken =
86
- store.config.lifespan === `ephemeral`
87
- ? findInStore(store, family, key)
88
- : seekInStore(store, family, key)
89
- if (!maybeToken) {
90
- throw new NotFoundError(family, key, store)
91
- }
92
- token = maybeToken
83
+ token = findInStore(store, family, key)
93
84
  }
94
85
  const target = newest(store)
95
- const state = withdraw(token, target)
96
- setAtomOrSelector(state, value, target)
86
+ const state = withdraw(target, token)
87
+ setAtomOrSelector(target, state, value)
97
88
  }) as typeof setState,
98
89
  find: ((token, key) => findInStore(store, token, key)) as typeof findState,
99
- seek: ((token, key) => seekInStore(store, token, key)) as typeof seekState,
100
90
  json: (token) => getJsonToken(store, token),
101
91
  })
@@ -22,7 +22,7 @@ export const traceSelectorAtoms = (
22
22
  }
23
23
  covered.add(indirectDependencyKey)
24
24
 
25
- if (!isAtomKey(indirectDependencyKey, store)) {
25
+ if (!isAtomKey(store, indirectDependencyKey)) {
26
26
  indirectDependencyKeys.push(
27
27
  ...getSelectorDependencyKeys(indirectDependencyKey, store),
28
28
  )
@@ -42,7 +42,7 @@ export const traceAllSelectorAtoms = (
42
42
  const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store)
43
43
  const covered = new Set<string>()
44
44
  return directDependencyKeys.flatMap((depKey) =>
45
- isAtomKey(depKey, store)
45
+ isAtomKey(store, depKey)
46
46
  ? depKey
47
47
  : traceSelectorAtoms(depKey, covered, store),
48
48
  )
@@ -3,9 +3,9 @@ import { Tracker } from "../mutable"
3
3
  import type { Store } from "../store"
4
4
 
5
5
  export function copyMutableIfNeeded<T extends Transceiver<any>>(
6
+ target: Store,
6
7
  atom: MutableAtom<T, any>,
7
8
  origin: Store,
8
- target: Store,
9
9
  ): T {
10
10
  const originValue = origin.valueMap.get(atom.key)
11
11
  const targetValue = target.valueMap.get(atom.key)
@@ -3,9 +3,9 @@ import type { StateUpdate } from "atom.io"
3
3
  import type { Atom, Selector, Store } from ".."
4
4
 
5
5
  export const emitUpdate = <T>(
6
+ store: Store,
6
7
  state: Atom<T> | Selector<T>,
7
8
  update: StateUpdate<T>,
8
- store: Store,
9
9
  ): void => {
10
10
  switch (state.type) {
11
11
  case `mutable_atom`:
@@ -4,7 +4,7 @@ import { newest } from "../lineage"
4
4
  import { isDone, markDone } from "../operation"
5
5
  import type { Store } from "../store"
6
6
 
7
- export const evictDownStream = <T>(atom: Atom<T>, store: Store): void => {
7
+ export const evictDownStream = <T>(store: Store, atom: Atom<T>): void => {
8
8
  const target = newest(store)
9
9
  const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key)
10
10
  target.logger.info(
@@ -3,9 +3,9 @@ import type { Store } from "../store"
3
3
  import { setAtom } from "./set-atom"
4
4
 
5
5
  export const setAtomOrSelector = <T>(
6
+ store: Store,
6
7
  state: WritableState<T>,
7
8
  value: T | ((oldValue: T) => T),
8
- store: Store,
9
9
  ): void => {
10
10
  switch (state.type) {
11
11
  case `atom`:
@@ -17,38 +17,38 @@ export const setAtom = <T>(
17
17
  next: T | ((oldValue: T) => T),
18
18
  target: Store,
19
19
  ): void => {
20
- const oldValue = readOrComputeValue(atom, target)
20
+ const oldValue = readOrComputeValue(target, atom)
21
21
  let newValue = oldValue
22
22
  if (atom.type === `mutable_atom` && isChildStore(target)) {
23
23
  const { parent } = target
24
- const copiedValue = copyMutableIfNeeded(atom, parent, target)
24
+ const copiedValue = copyMutableIfNeeded(target, atom, parent)
25
25
  newValue = copiedValue
26
26
  }
27
27
  newValue = become(next)(newValue)
28
28
  target.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)
29
- newValue = cacheValue(atom.key, newValue, atom.subject, target)
30
- if (isAtomDefault(atom.key, target)) {
31
- markAtomAsNotDefault(atom.key, target)
29
+ newValue = cacheValue(target, atom.key, newValue, atom.subject)
30
+ if (isAtomDefault(target, atom.key)) {
31
+ markAtomAsNotDefault(target, atom.key)
32
32
  }
33
33
  markDone(target, atom.key)
34
- evictDownStream(atom, target)
34
+ evictDownStream(target, atom)
35
35
  const update = { oldValue, newValue }
36
36
  if (isRootStore(target)) {
37
- emitUpdate(atom, update, target)
37
+ emitUpdate(target, atom, update)
38
38
  } else if (target.parent) {
39
39
  if (target.on.transactionApplying.state === null) {
40
- stowUpdate(atom, update, target)
40
+ stowUpdate(target, atom, update)
41
41
  } else if (atom.key.startsWith(`*`)) {
42
42
  const mutableKey = atom.key.slice(1)
43
43
  const mutableAtom = target.atoms.get(mutableKey) as Atom<any>
44
44
  let transceiver: Transceiver<any> = target.valueMap.get(mutableKey)
45
45
  if (mutableAtom.type === `mutable_atom` && isChildStore(target)) {
46
46
  const { parent } = target
47
- const copiedValue = copyMutableIfNeeded(mutableAtom, parent, target)
47
+ const copiedValue = copyMutableIfNeeded(target, mutableAtom, parent)
48
48
  transceiver = copiedValue
49
49
  }
50
50
  const accepted = transceiver.do(update.newValue) === null
51
- if (accepted) evictDownStream(mutableAtom, target)
51
+ if (accepted) evictDownStream(target, mutableAtom)
52
52
  }
53
53
  }
54
54
  }
@@ -84,7 +84,7 @@ export function setIntoStore<T, New extends T>(
84
84
  )
85
85
  return
86
86
  }
87
- const state = withdraw(token, store)
88
- setAtomOrSelector(state, value, store)
87
+ const state = withdraw(store, token)
88
+ setAtomOrSelector(store, state, value)
89
89
  closeOperation(store)
90
90
  }
@@ -19,9 +19,9 @@ function shouldUpdateBeStowed(key: string, update: StateUpdate<any>): boolean {
19
19
  }
20
20
 
21
21
  export const stowUpdate = <T>(
22
+ store: Store,
22
23
  state: Atom<T>,
23
24
  update: StateUpdate<T>,
24
- store: Store,
25
25
  ): void => {
26
26
  const { key } = state
27
27
  const target = newest(store)
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  AtomFamilyToken,
3
+ AtomIOToken,
3
4
  AtomToken,
4
5
  MutableAtomFamilyToken,
5
6
  MutableAtomToken,
@@ -11,6 +12,8 @@ import type {
11
12
  RegularAtomToken,
12
13
  SelectorFamilyToken,
13
14
  SelectorToken,
15
+ TimelineManageable,
16
+ TimelineToken,
14
17
  TransactionToken,
15
18
  WritableFamilyToken,
16
19
  WritableSelectorFamilyToken,
@@ -22,6 +25,7 @@ import type { Canonical, Json } from "atom.io/json"
22
25
  import type {
23
26
  Atom,
24
27
  AtomFamily,
28
+ AtomIOInternalResource,
25
29
  Func,
26
30
  MutableAtom,
27
31
  MutableAtomFamily,
@@ -33,6 +37,7 @@ import type {
33
37
  RegularAtomFamily,
34
38
  Selector,
35
39
  SelectorFamily,
40
+ Timeline,
36
41
  Transceiver,
37
42
  WritableFamily,
38
43
  WritableSelector,
@@ -80,16 +85,13 @@ export function deposit<T>(
80
85
  export function deposit<T extends Func>(
81
86
  state: Transaction<T>,
82
87
  ): TransactionToken<T>
88
+ export function deposit<M extends TimelineManageable>(
89
+ state: Timeline<M>,
90
+ ): TimelineToken<M>
83
91
 
84
- export function deposit(state: ReadableState<any>): ReadableToken<any>
92
+ export function deposit(resource: AtomIOInternalResource): AtomIOToken
85
93
 
86
- export function deposit(
87
- state: ReadableFamily<any, any> | ReadableState<any> | Transaction<Func>,
88
- ): ReadableFamilyToken<any, any> | ReadableToken<any> | TransactionToken<Func>
89
-
90
- export function deposit(
91
- state: ReadableFamily<any, any> | ReadableState<any> | Transaction<Func>,
92
- ): ReadableFamilyToken<any, any> | ReadableToken<any> | TransactionToken<Func> {
94
+ export function deposit(state: AtomIOInternalResource): AtomIOToken {
93
95
  const token = {
94
96
  key: state.key,
95
97
  type: state.type,
@@ -9,7 +9,6 @@ import type {
9
9
  WritableSelectorToken,
10
10
  } from "atom.io"
11
11
  import { AtomIOLogger } from "atom.io"
12
- import type { Join } from "atom.io/data"
13
12
  import type { Canonical, stringified } from "atom.io/json"
14
13
 
15
14
  import type {
@@ -21,6 +20,7 @@ import type {
21
20
  WritableSelector,
22
21
  WritableSelectorFamily,
23
22
  } from ".."
23
+ import type { Join } from "../join"
24
24
  import { Junction } from "../junction"
25
25
  import type { Lineage } from "../lineage"
26
26
  import type { Molecule } from "../molecule"
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  AtomFamilyToken,
3
+ AtomIOToken,
3
4
  AtomToken,
4
5
  MutableAtomFamilyToken,
5
6
  MutableAtomToken,
@@ -24,8 +25,8 @@ import type { Canonical, Json } from "atom.io/json"
24
25
  import type {
25
26
  Atom,
26
27
  AtomFamily,
28
+ AtomIOInternalResource,
27
29
  Func,
28
- Molecule,
29
30
  MutableAtom,
30
31
  MutableAtomFamily,
31
32
  ReadableFamily,
@@ -47,118 +48,98 @@ import type { Timeline } from "../timeline"
47
48
  import type { Transaction } from "../transaction"
48
49
  import type { Store } from "./store"
49
50
 
50
- export type Withdrawable =
51
- | Atom<any>
52
- | AtomFamily<any, any>
53
- | Molecule<any>
54
- | MutableAtom<any, any>
55
- | MutableAtomFamily<any, any, any>
56
- | ReadableFamily<any, any>
57
- | ReadableState<any>
58
- | ReadonlySelector<any>
59
- | ReadonlySelectorFamily<any, any>
60
- | RegularAtom<any>
61
- | RegularAtomFamily<any, any>
62
- | Selector<any>
63
- | SelectorFamily<any, any>
64
- | Timeline<any>
65
- | Transaction<any>
66
- | WritableFamily<any, any>
67
- | WritableSelector<any>
68
- | WritableSelectorFamily<any, any>
69
- | WritableState<any>
70
-
71
51
  export function withdraw<T>(
72
- token: RegularAtomToken<T>,
73
52
  store: Store,
53
+ token: RegularAtomToken<T>,
74
54
  ): RegularAtom<T>
75
55
  export function withdraw<T extends Transceiver<any>>(
76
- token: MutableAtomToken<T, any>,
77
56
  store: Store,
57
+ token: MutableAtomToken<T, any>,
78
58
  ): MutableAtom<T, any>
79
- export function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>
59
+ export function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>
80
60
  export function withdraw<T>(
81
- token: WritableSelectorToken<T>,
82
61
  store: Store,
62
+ token: WritableSelectorToken<T>,
83
63
  ): WritableSelector<T>
84
64
  export function withdraw<T>(
85
- token: ReadonlySelectorToken<T>,
86
65
  store: Store,
66
+ token: ReadonlySelectorToken<T>,
87
67
  ): ReadonlySelector<T>
88
- export function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>
68
+ export function withdraw<T>(store: Store, token: SelectorToken<T>): Selector<T>
89
69
  export function withdraw<T>(
90
- token: WritableToken<T>,
91
70
  store: Store,
71
+ token: WritableToken<T>,
92
72
  ): WritableState<T>
93
73
  export function withdraw<T>(
94
- token: ReadableToken<T>,
95
74
  store: Store,
75
+ token: ReadableToken<T>,
96
76
  ): ReadableState<T>
97
77
 
98
78
  export function withdraw<T, K extends Canonical>(
99
- token: RegularAtomFamilyToken<T, K>,
100
79
  store: Store,
80
+ token: RegularAtomFamilyToken<T, K>,
101
81
  ): RegularAtomFamily<T, K>
102
82
  export function withdraw<
103
83
  T extends Transceiver<any>,
104
84
  J extends Json.Serializable,
105
85
  K extends Canonical,
106
86
  >(
107
- token: MutableAtomFamilyToken<T, J, K>,
108
87
  store: Store,
88
+ token: MutableAtomFamilyToken<T, J, K>,
109
89
  ): MutableAtomFamily<T, J, K>
110
90
  export function withdraw<T, K extends Canonical>(
111
- token: AtomFamilyToken<T>,
112
91
  store: Store,
92
+ token: AtomFamilyToken<T>,
113
93
  ): AtomFamily<T, any>
114
94
  export function withdraw<T, K extends Canonical>(
115
- token: ReadonlySelectorFamilyToken<T, K>,
116
95
  store: Store,
96
+ token: ReadonlySelectorFamilyToken<T, K>,
117
97
  ): ReadonlySelectorFamily<T, any>
118
98
  export function withdraw<T, K extends Canonical>(
119
- token: WritableSelectorFamilyToken<T, K>,
120
99
  store: Store,
100
+ token: WritableSelectorFamilyToken<T, K>,
121
101
  ): WritableSelectorFamily<T, any>
122
102
  export function withdraw<T, K extends Canonical>(
123
- token: SelectorFamilyToken<T, K>,
124
103
  store: Store,
104
+ token: SelectorFamilyToken<T, K>,
125
105
  ): SelectorFamily<T, any>
126
106
  export function withdraw<T, K extends Canonical>(
127
- token: ReadableFamilyToken<T, K>,
128
107
  store: Store,
108
+ token: ReadableFamilyToken<T, K>,
129
109
  ): ReadableFamily<T, any>
130
110
  export function withdraw<T, K extends Canonical>(
131
- token: WritableFamilyToken<T, K>,
132
111
  store: Store,
112
+ token: WritableFamilyToken<T, K>,
133
113
  ): WritableFamily<T, any>
134
114
 
135
115
  export function withdraw<T extends Func>(
136
- token: TransactionToken<T>,
137
116
  store: Store,
117
+ token: TransactionToken<T>,
138
118
  ): Transaction<T extends Func ? T : never>
139
119
  export function withdraw<T>(
140
- token: TimelineToken<T>,
141
120
  store: Store,
121
+ token: TimelineToken<T>,
142
122
  ): Timeline<T extends TimelineManageable ? T : never>
143
123
 
144
124
  export function withdraw<T>(
145
- token: ReadableToken<T>,
146
125
  store: Store,
126
+ token: WritableToken<T>,
127
+ ): WritableState<T>
128
+ export function withdraw<T>(
129
+ store: Store,
130
+ token: ReadableToken<T>,
147
131
  ): ReadableState<T>
148
132
 
149
133
  export function withdraw(
150
- token:
151
- | MutableAtomFamilyToken<any, any, any>
152
- | MutableAtomToken<any, any>
153
- | RegularAtomFamilyToken<any, any>
154
- | RegularAtomToken<any>
155
- | SelectorFamilyToken<any, any>
156
- | SelectorToken<any>
157
- | TimelineToken<any>
158
- | TransactionToken<any>,
159
- store: Store,
160
- ): Withdrawable {
161
- let withdrawn: Withdrawable | undefined
134
+ store: Store,
135
+ token: AtomIOToken,
136
+ ): AtomIOInternalResource
137
+
138
+ export function withdraw(
139
+ store: Store,
140
+ token: AtomIOToken,
141
+ ): AtomIOInternalResource {
142
+ let withdrawn: AtomIOInternalResource | undefined
162
143
  let target: Store | null = store
163
144
  while (target !== null) {
164
145
  switch (token.type) {
@@ -2,7 +2,7 @@ import type { ReadableState } from ".."
2
2
  import { newest } from "../lineage"
3
3
  import type { Store } from "../store"
4
4
 
5
- export const recallState = <T>(state: ReadableState<T>, store: Store): T => {
5
+ export const recallState = <T>(store: Store, state: ReadableState<T>): T => {
6
6
  const target = newest(store)
7
7
  if (target.operation.open) {
8
8
  return target.operation.prev.get(state.key)
@@ -53,10 +53,10 @@ export function subscribeInStore(
53
53
  case `mutable_atom`:
54
54
  case `readonly_selector`:
55
55
  case `selector`:
56
- return subscribeToState(token, handleUpdate, key, store)
56
+ return subscribeToState(store, token, key, handleUpdate)
57
57
  case `transaction`:
58
- return subscribeToTransaction(token, handleUpdate, key, store)
58
+ return subscribeToTransaction(store, token, key, handleUpdate)
59
59
  case `timeline`:
60
- return subscribeToTimeline(token, handleUpdate, key, store)
60
+ return subscribeToTimeline(store, token, key, handleUpdate)
61
61
  }
62
62
  }
@@ -6,8 +6,8 @@ import type { Store } from "../store"
6
6
  import { recallState } from "./recall-state"
7
7
 
8
8
  export const subscribeToRootAtoms = <T>(
9
- selector: Selector<T>,
10
9
  store: Store,
10
+ selector: Selector<T>,
11
11
  ): (() => void)[] => {
12
12
  const target = newest(store)
13
13
  const dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(
@@ -32,8 +32,8 @@ export const subscribeToRootAtoms = <T>(
32
32
  `->`,
33
33
  atomChange.newValue,
34
34
  )
35
- const oldValue = recallState(selector, target)
36
- const newValue = readOrComputeValue(selector, target)
35
+ const oldValue = recallState(target, selector)
36
+ const newValue = readOrComputeValue(target, selector)
37
37
  store.logger.info(
38
38
  `✨`,
39
39
  selector.type,
@@ -5,10 +5,10 @@ import { withdraw } from "../store"
5
5
  import { subscribeToRootAtoms } from "./subscribe-to-root-atoms"
6
6
 
7
7
  export function subscribeToState<T>(
8
+ store: Store,
8
9
  token: ReadableToken<T>,
9
- handleUpdate: UpdateHandler<T>,
10
10
  key: string,
11
- store: Store,
11
+ handleUpdate: UpdateHandler<T>,
12
12
  ): () => void {
13
13
  function safelyHandleUpdate(update: StateUpdate<any>): void {
14
14
  if (store.operation.open) {
@@ -23,18 +23,18 @@ export function subscribeToState<T>(
23
23
  handleUpdate(update)
24
24
  }
25
25
  }
26
- const state = withdraw(token, store)
26
+ const state = withdraw(store, token)
27
27
  store.logger.info(`👀`, state.type, state.key, `Adding subscription "${key}"`)
28
28
  const isSelector =
29
29
  state.type === `selector` || state.type === `readonly_selector`
30
30
  let dependencyUnsubFunctions: (() => void)[] | null = null
31
31
  let updateHandler: UpdateHandler<T> = safelyHandleUpdate
32
32
  if (isSelector) {
33
- dependencyUnsubFunctions = subscribeToRootAtoms(state, store)
33
+ dependencyUnsubFunctions = subscribeToRootAtoms(store, state)
34
34
  updateHandler = (update) => {
35
35
  if (dependencyUnsubFunctions) {
36
36
  dependencyUnsubFunctions.length = 0
37
- dependencyUnsubFunctions.push(...subscribeToRootAtoms(state, store))
37
+ dependencyUnsubFunctions.push(...subscribeToRootAtoms(store, state))
38
38
  }
39
39
  safelyHandleUpdate(update)
40
40
  }
@@ -4,12 +4,12 @@ import type { Store } from ".."
4
4
  import { withdraw } from ".."
5
5
 
6
6
  export const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(
7
+ store: Store,
7
8
  token: TimelineToken<ManagedAtom>,
8
- handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,
9
9
  key: string,
10
- store: Store,
10
+ handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,
11
11
  ): (() => void) => {
12
- const tl = withdraw(token, store)
12
+ const tl = withdraw(store, token)
13
13
  store.logger.info(`👀`, `timeline`, token.key, `Adding subscription "${key}"`)
14
14
  const unsubscribe = tl.subject.subscribe(key, handleUpdate)
15
15
  return () => {
@@ -4,12 +4,12 @@ import type { Func, Store } from ".."
4
4
  import { withdraw } from ".."
5
5
 
6
6
  export const subscribeToTransaction = <F extends Func>(
7
+ store: Store,
7
8
  token: TransactionToken<F>,
8
- handleUpdate: TransactionUpdateHandler<F>,
9
9
  key: string,
10
- store: Store,
10
+ handleUpdate: TransactionUpdateHandler<F>,
11
11
  ): (() => void) => {
12
- const tx = withdraw(token, store)
12
+ const tx = withdraw(store, token)
13
13
  store.logger.info(
14
14
  `👀`,
15
15
  `transaction`,