atom.io 0.31.1 → 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 (155) 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-Y5MBNTVU.js → chunk-GY2XQYZY.js} +1791 -703
  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 +622 -26
  15. package/dist/index.js +1 -228
  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 +783 -64
  21. package/internal/dist/index.js +1 -1
  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/get-state/get-from-store.ts +2 -2
  31. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  32. package/internal/src/index.ts +2 -0
  33. package/internal/src/install-into-store.ts +1 -1
  34. package/internal/src/join/edit-relations-in-store.ts +32 -0
  35. package/internal/src/join/find-relations-in-store.ts +124 -0
  36. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  37. package/internal/src/join/get-join.ts +31 -0
  38. package/internal/src/join/index.ts +5 -0
  39. package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
  40. package/internal/src/keys.ts +7 -7
  41. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  42. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  43. package/internal/src/mutable/get-json-token.ts +1 -1
  44. package/internal/src/mutable/tracker-family.ts +19 -17
  45. package/internal/src/mutable/tracker.ts +8 -8
  46. package/internal/src/pretty-print.ts +1 -1
  47. package/internal/src/selector/create-readonly-selector.ts +3 -7
  48. package/internal/src/selector/create-writable-selector.ts +4 -4
  49. package/internal/src/selector/dispose-selector.ts +20 -11
  50. package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
  51. package/internal/src/selector/register-selector.ts +6 -9
  52. package/internal/src/selector/trace-selector-atoms.ts +2 -2
  53. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  54. package/internal/src/set-state/emit-update.ts +1 -1
  55. package/internal/src/set-state/evict-downstream.ts +1 -1
  56. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  57. package/internal/src/set-state/set-atom.ts +10 -10
  58. package/internal/src/set-state/set-into-store.ts +2 -2
  59. package/internal/src/set-state/stow-update.ts +1 -1
  60. package/internal/src/store/store.ts +1 -1
  61. package/internal/src/store/withdraw.ts +22 -22
  62. package/internal/src/subscribe/recall-state.ts +1 -1
  63. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  64. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  65. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  66. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  67. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  68. package/internal/src/timeline/create-timeline.ts +17 -37
  69. package/internal/src/transaction/act-upon-store.ts +2 -2
  70. package/internal/src/transaction/apply-transaction.ts +5 -5
  71. package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
  72. package/internal/src/transaction/build-transaction.ts +5 -8
  73. package/internal/src/transaction/create-transaction.ts +3 -3
  74. package/internal/src/transaction/get-epoch-number.ts +3 -3
  75. package/internal/src/transaction/set-epoch-number.ts +2 -2
  76. package/introspection/dist/index.d.ts +922 -6
  77. package/introspection/dist/index.js +2 -620
  78. package/json/dist/index.d.ts +899 -5
  79. package/json/dist/index.js +1 -80
  80. package/json/src/select-json-family.ts +3 -14
  81. package/package.json +24 -42
  82. package/react/dist/index.d.ts +921 -3
  83. package/react/dist/index.js +2 -82
  84. package/react/src/use-o.ts +1 -1
  85. package/react/src/use-tl.ts +2 -2
  86. package/react-devtools/dist/index.css +16 -14
  87. package/react-devtools/dist/index.d.ts +26 -1
  88. package/react-devtools/dist/index.js +6 -6
  89. package/react-devtools/src/devtools.scss +16 -14
  90. package/realtime/dist/index.d.ts +202 -8
  91. package/realtime/dist/index.js +2 -107
  92. package/realtime/src/realtime-continuity.ts +2 -2
  93. package/realtime/src/shared-room-store.ts +1 -2
  94. package/realtime-client/dist/index.d.ts +960 -22
  95. package/realtime-client/dist/index.js +3 -509
  96. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  97. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  98. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  99. package/realtime-client/src/pull-atom.ts +2 -2
  100. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  101. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  102. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  103. package/realtime-client/src/pull-selector.ts +4 -4
  104. package/realtime-client/src/push-state.ts +5 -10
  105. package/realtime-client/src/server-action.ts +4 -4
  106. package/realtime-client/src/sync-continuity.ts +6 -6
  107. package/realtime-react/dist/index.d.ts +166 -12
  108. package/realtime-react/dist/index.js +5 -154
  109. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  110. package/realtime-react/src/use-pull-atom.ts +1 -1
  111. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  112. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  113. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  114. package/realtime-react/src/use-pull-selector.ts +1 -1
  115. package/realtime-react/src/use-push.ts +1 -1
  116. package/realtime-react/src/use-server-action.ts +2 -2
  117. package/realtime-react/src/use-sync-continuity.ts +1 -1
  118. package/realtime-server/dist/index.d.ts +971 -28
  119. package/realtime-server/dist/index.js +3 -1001
  120. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  121. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  122. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  123. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  124. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  125. package/realtime-server/src/realtime-family-provider.ts +2 -2
  126. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  127. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  128. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  129. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  130. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  131. package/realtime-server/src/realtime-state-provider.ts +2 -2
  132. package/realtime-testing/dist/index.d.ts +1091 -3
  133. package/realtime-testing/dist/index.js +20 -22
  134. package/realtime-testing/src/setup-realtime-test.tsx +2 -1
  135. package/src/index.ts +4 -0
  136. package/src/join.ts +218 -0
  137. package/src/silo.ts +4 -4
  138. package/src/timeline.ts +1 -1
  139. package/src/transaction.ts +4 -8
  140. package/transceivers/set-rtx/dist/index.d.ts +37 -2
  141. package/transceivers/set-rtx/dist/index.js +1 -215
  142. package/web/dist/index.d.ts +30 -1
  143. package/web/dist/index.js +1 -15
  144. package/data/src/until.ts +0 -15
  145. package/ephemeral/dist/index.d.ts +0 -67
  146. package/ephemeral/dist/index.js +0 -9
  147. package/ephemeral/package.json +0 -13
  148. package/ephemeral/src/index.ts +0 -1
  149. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  150. package/immortal/dist/index.d.ts +0 -12
  151. package/immortal/dist/index.js +0 -9
  152. package/immortal/package.json +0 -13
  153. package/immortal/src/index.ts +0 -1
  154. package/immortal/src/seek-state.ts +0 -60
  155. /package/{ephemeral/src → src}/find-state.ts +0 -0
@@ -19,14 +19,10 @@ export const createReadonlySelector = <T>(
19
19
  const target = newest(store)
20
20
  const subject = new Subject<{ newValue: T; oldValue: T }>()
21
21
  const covered = new Set<string>()
22
- const { get, find, seek, json } = registerSelector(
23
- options.key,
24
- covered,
25
- target,
26
- )
22
+ const { get, find, json } = registerSelector(options.key, covered, target)
27
23
  const getSelf = () => {
28
- const value = options.get({ get, find, seek, json })
29
- cacheValue(options.key, value, subject, newest(store))
24
+ const value = options.get({ get, find, json })
25
+ cacheValue(newest(store), options.key, value, subject)
30
26
  covered.clear()
31
27
  return value
32
28
  }
@@ -23,12 +23,12 @@ export const createWritableSelector = <T>(
23
23
  const subject = new Subject<{ newValue: T; oldValue: T }>()
24
24
  const covered = new Set<string>()
25
25
  const setterToolkit = registerSelector(options.key, covered, target)
26
- const { find, get, seek, json } = setterToolkit
27
- const getterToolkit = { find, get, seek, json }
26
+ const { find, get, json } = setterToolkit
27
+ const getterToolkit = { find, get, json }
28
28
 
29
29
  const getSelf = (getFn = options.get, innerTarget = newest(store)): T => {
30
30
  const value = getFn(getterToolkit)
31
- cacheValue(options.key, value, subject, innerTarget)
31
+ cacheValue(innerTarget, options.key, value, subject)
32
32
  covered.clear()
33
33
  return value
34
34
  }
@@ -47,7 +47,7 @@ export const createWritableSelector = <T>(
47
47
  newValue,
48
48
  `)`,
49
49
  )
50
- cacheValue(options.key, newValue, subject, innerTarget)
50
+ cacheValue(innerTarget, options.key, newValue, subject)
51
51
  markDone(innerTarget, options.key)
52
52
  if (isRootStore(innerTarget)) {
53
53
  subject.next({ newValue, oldValue })
@@ -1,15 +1,15 @@
1
- import type { ReadonlySelectorToken, WritableSelectorToken } from "atom.io"
1
+ import type { SelectorFamilyToken, SelectorToken } from "atom.io"
2
2
 
3
3
  import type { Store } from ".."
4
4
  import { isChildStore, newest, withdraw } from ".."
5
5
 
6
6
  export function disposeSelector(
7
- selectorToken: ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>,
8
7
  store: Store,
8
+ selectorToken: SelectorToken<unknown>,
9
9
  ): void {
10
10
  const target = newest(store)
11
11
  const { key } = selectorToken
12
- const selector = withdraw(selectorToken, target)
12
+ const selector = withdraw(target, selectorToken)
13
13
  if (!selector.family) {
14
14
  store.logger.error(
15
15
  `❌`,
@@ -22,23 +22,31 @@ export function disposeSelector(
22
22
  if (molecule) {
23
23
  target.moleculeData.delete(selector.family.subKey, selector.family.key)
24
24
  }
25
+ let familyToken: SelectorFamilyToken<any, any>
25
26
  switch (selectorToken.type) {
26
27
  case `selector`:
27
28
  {
28
29
  target.selectors.delete(key)
29
- const family = withdraw(
30
- { key: selector.family.key, type: `selector_family` },
31
- store,
32
- )
30
+ familyToken = {
31
+ key: selector.family.key,
32
+ type: `selector_family`,
33
+ }
34
+ const family = withdraw(store, familyToken)
35
+ family.subject.next({
36
+ type: `state_disposal`,
37
+ subType: `selector`,
38
+ token: selectorToken,
39
+ })
33
40
  }
34
41
  break
35
42
  case `readonly_selector`:
36
43
  {
37
44
  target.readonlySelectors.delete(key)
38
- const family = withdraw(
39
- { key: selector.family.key, type: `readonly_selector_family` },
40
- store,
41
- )
45
+ familyToken = {
46
+ key: selector.family.key,
47
+ type: `readonly_selector_family`,
48
+ }
49
+ const family = withdraw(store, familyToken)
42
50
  family.subject.next({
43
51
  type: `state_disposal`,
44
52
  subType: `selector`,
@@ -47,6 +55,7 @@ export function disposeSelector(
47
55
  }
48
56
  break
49
57
  }
58
+
50
59
  target.valueMap.delete(key)
51
60
  target.selectorAtoms.delete(key)
52
61
  target.selectorGraph.delete(key)
@@ -15,6 +15,6 @@ export const getSelectorDependencyKeys = (
15
15
  .selectorGraph.getRelationEntries({ downstreamSelectorKey: key })
16
16
  .filter(([_, { source }]) => source !== key)
17
17
  .map(([_, { source }]) => source)
18
- .filter((source) => isStateKey(source, store))
18
+ .filter((source) => isStateKey(store, source))
19
19
  return sources
20
20
  }
@@ -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
  `🔌`,
@@ -85,10 +83,9 @@ export const registerSelector = (
85
83
  token = findInStore(store, family, key)
86
84
  }
87
85
  const target = newest(store)
88
- const state = withdraw(token, target)
89
- setAtomOrSelector(state, value, target)
86
+ const state = withdraw(target, token)
87
+ setAtomOrSelector(target, state, value)
90
88
  }) as typeof setState,
91
89
  find: ((token, key) => findInStore(store, token, key)) as typeof findState,
92
- seek: ((token, key) => seekInStore(store, token, key)) as typeof seekState,
93
90
  json: (token) => getJsonToken(store, token),
94
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)
@@ -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"
@@ -49,95 +49,95 @@ import type { Transaction } from "../transaction"
49
49
  import type { Store } from "./store"
50
50
 
51
51
  export function withdraw<T>(
52
- token: RegularAtomToken<T>,
53
52
  store: Store,
53
+ token: RegularAtomToken<T>,
54
54
  ): RegularAtom<T>
55
55
  export function withdraw<T extends Transceiver<any>>(
56
- token: MutableAtomToken<T, any>,
57
56
  store: Store,
57
+ token: MutableAtomToken<T, any>,
58
58
  ): MutableAtom<T, any>
59
- export function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>
59
+ export function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>
60
60
  export function withdraw<T>(
61
- token: WritableSelectorToken<T>,
62
61
  store: Store,
62
+ token: WritableSelectorToken<T>,
63
63
  ): WritableSelector<T>
64
64
  export function withdraw<T>(
65
- token: ReadonlySelectorToken<T>,
66
65
  store: Store,
66
+ token: ReadonlySelectorToken<T>,
67
67
  ): ReadonlySelector<T>
68
- export function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>
68
+ export function withdraw<T>(store: Store, token: SelectorToken<T>): Selector<T>
69
69
  export function withdraw<T>(
70
- token: WritableToken<T>,
71
70
  store: Store,
71
+ token: WritableToken<T>,
72
72
  ): WritableState<T>
73
73
  export function withdraw<T>(
74
- token: ReadableToken<T>,
75
74
  store: Store,
75
+ token: ReadableToken<T>,
76
76
  ): ReadableState<T>
77
77
 
78
78
  export function withdraw<T, K extends Canonical>(
79
- token: RegularAtomFamilyToken<T, K>,
80
79
  store: Store,
80
+ token: RegularAtomFamilyToken<T, K>,
81
81
  ): RegularAtomFamily<T, K>
82
82
  export function withdraw<
83
83
  T extends Transceiver<any>,
84
84
  J extends Json.Serializable,
85
85
  K extends Canonical,
86
86
  >(
87
- token: MutableAtomFamilyToken<T, J, K>,
88
87
  store: Store,
88
+ token: MutableAtomFamilyToken<T, J, K>,
89
89
  ): MutableAtomFamily<T, J, K>
90
90
  export function withdraw<T, K extends Canonical>(
91
- token: AtomFamilyToken<T>,
92
91
  store: Store,
92
+ token: AtomFamilyToken<T>,
93
93
  ): AtomFamily<T, any>
94
94
  export function withdraw<T, K extends Canonical>(
95
- token: ReadonlySelectorFamilyToken<T, K>,
96
95
  store: Store,
96
+ token: ReadonlySelectorFamilyToken<T, K>,
97
97
  ): ReadonlySelectorFamily<T, any>
98
98
  export function withdraw<T, K extends Canonical>(
99
- token: WritableSelectorFamilyToken<T, K>,
100
99
  store: Store,
100
+ token: WritableSelectorFamilyToken<T, K>,
101
101
  ): WritableSelectorFamily<T, any>
102
102
  export function withdraw<T, K extends Canonical>(
103
- token: SelectorFamilyToken<T, K>,
104
103
  store: Store,
104
+ token: SelectorFamilyToken<T, K>,
105
105
  ): SelectorFamily<T, any>
106
106
  export function withdraw<T, K extends Canonical>(
107
- token: ReadableFamilyToken<T, K>,
108
107
  store: Store,
108
+ token: ReadableFamilyToken<T, K>,
109
109
  ): ReadableFamily<T, any>
110
110
  export function withdraw<T, K extends Canonical>(
111
- token: WritableFamilyToken<T, K>,
112
111
  store: Store,
112
+ token: WritableFamilyToken<T, K>,
113
113
  ): WritableFamily<T, any>
114
114
 
115
115
  export function withdraw<T extends Func>(
116
- token: TransactionToken<T>,
117
116
  store: Store,
117
+ token: TransactionToken<T>,
118
118
  ): Transaction<T extends Func ? T : never>
119
119
  export function withdraw<T>(
120
- token: TimelineToken<T>,
121
120
  store: Store,
121
+ token: TimelineToken<T>,
122
122
  ): Timeline<T extends TimelineManageable ? T : never>
123
123
 
124
124
  export function withdraw<T>(
125
- token: WritableToken<T>,
126
125
  store: Store,
126
+ token: WritableToken<T>,
127
127
  ): WritableState<T>
128
128
  export function withdraw<T>(
129
- token: ReadableToken<T>,
130
129
  store: Store,
130
+ token: ReadableToken<T>,
131
131
  ): ReadableState<T>
132
132
 
133
133
  export function withdraw(
134
- token: AtomIOToken,
135
134
  store: Store,
135
+ token: AtomIOToken,
136
136
  ): AtomIOInternalResource
137
137
 
138
138
  export function withdraw(
139
- token: AtomIOToken,
140
139
  store: Store,
140
+ token: AtomIOToken,
141
141
  ): AtomIOInternalResource {
142
142
  let withdrawn: AtomIOInternalResource | undefined
143
143
  let target: Store | null = store
@@ -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`,