atom.io 0.36.0 → 0.36.2

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 (105) hide show
  1. package/dist/internal/index.d.ts +93 -73
  2. package/dist/internal/index.d.ts.map +1 -1
  3. package/dist/internal/index.js +233 -248
  4. package/dist/internal/index.js.map +1 -1
  5. package/dist/introspection/index.d.ts +5 -6
  6. package/dist/introspection/index.d.ts.map +1 -1
  7. package/dist/introspection/index.js +2 -3
  8. package/dist/introspection/index.js.map +1 -1
  9. package/dist/main/index.d.ts +29 -37
  10. package/dist/main/index.d.ts.map +1 -1
  11. package/dist/main/index.js +8 -9
  12. package/dist/main/index.js.map +1 -1
  13. package/dist/react/index.d.ts +2 -2
  14. package/dist/react/index.d.ts.map +1 -1
  15. package/dist/react/index.js.map +1 -1
  16. package/dist/react-devtools/index.d.ts.map +1 -1
  17. package/dist/react-devtools/index.js.map +1 -1
  18. package/dist/realtime-client/index.d.ts +7 -8
  19. package/dist/realtime-client/index.d.ts.map +1 -1
  20. package/dist/realtime-client/index.js +3 -4
  21. package/dist/realtime-client/index.js.map +1 -1
  22. package/dist/realtime-react/index.d.ts +4 -4
  23. package/dist/realtime-react/index.d.ts.map +1 -1
  24. package/dist/realtime-react/index.js.map +1 -1
  25. package/dist/realtime-server/index.d.ts +2 -2
  26. package/dist/realtime-server/index.d.ts.map +1 -1
  27. package/dist/realtime-server/index.js.map +1 -1
  28. package/dist/transceivers/set-rtx/index.d.ts +9 -2
  29. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  30. package/dist/transceivers/set-rtx/index.js +3 -0
  31. package/dist/transceivers/set-rtx/index.js.map +1 -1
  32. package/package.json +3 -3
  33. package/src/internal/atom/create-regular-atom.ts +5 -5
  34. package/src/internal/atom/has-role.ts +12 -0
  35. package/src/internal/atom/index.ts +1 -0
  36. package/src/internal/caching.ts +60 -41
  37. package/src/internal/families/find-in-store.ts +1 -1
  38. package/src/internal/families/get-family-of-token.ts +1 -1
  39. package/src/internal/families/init-family-member.ts +1 -1
  40. package/src/internal/families/seek-in-store.ts +1 -1
  41. package/src/internal/get-state/read-or-compute-value.ts +26 -21
  42. package/src/internal/index.ts +8 -8
  43. package/src/internal/join/create-join.ts +3 -2
  44. package/src/internal/join/join-internal.ts +7 -4
  45. package/src/internal/mutable/create-mutable-atom-family.ts +6 -5
  46. package/src/internal/mutable/create-mutable-atom.ts +1 -1
  47. package/src/internal/mutable/get-json-family.ts +1 -1
  48. package/src/internal/mutable/get-json-token.ts +1 -1
  49. package/src/internal/mutable/get-update-family.ts +1 -1
  50. package/src/internal/mutable/get-update-token.ts +1 -1
  51. package/src/internal/mutable/tracker-family.ts +27 -31
  52. package/src/internal/mutable/tracker.ts +29 -23
  53. package/src/internal/mutable/transceiver.ts +11 -10
  54. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  55. package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
  56. package/src/internal/selector/create-writable-held-selector.ts +3 -4
  57. package/src/internal/selector/create-writable-pure-selector.ts +3 -3
  58. package/src/internal/set-state/evict-downstream.ts +17 -15
  59. package/src/internal/set-state/index.ts +1 -0
  60. package/src/internal/set-state/reset-in-store.ts +6 -50
  61. package/src/internal/set-state/set-atom.ts +17 -24
  62. package/src/internal/set-state/set-into-store.ts +29 -13
  63. package/src/internal/store/counterfeit.ts +1 -1
  64. package/src/internal/store/deposit.ts +7 -8
  65. package/src/internal/store/store.ts +6 -6
  66. package/src/internal/store/withdraw.ts +8 -8
  67. package/src/internal/subscribe/subscribe-in-store.ts +8 -8
  68. package/src/internal/subscribe/subscribe-to-timeline.ts +2 -2
  69. package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
  70. package/src/internal/timeline/create-timeline.ts +3 -3
  71. package/src/internal/transaction/act-upon-store.ts +2 -2
  72. package/src/internal/transaction/apply-transaction.ts +2 -2
  73. package/src/internal/transaction/build-transaction.ts +2 -2
  74. package/src/internal/transaction/create-transaction.ts +3 -3
  75. package/src/internal/transaction/index.ts +2 -2
  76. package/src/internal/transaction/is-root-store.ts +4 -2
  77. package/src/internal/utility-types.ts +1 -1
  78. package/src/introspection/attach-introspection-states.ts +3 -3
  79. package/src/introspection/attach-transaction-index.ts +4 -4
  80. package/src/introspection/attach-transaction-logs.ts +4 -4
  81. package/src/introspection/auditor.ts +3 -3
  82. package/src/main/atom.ts +4 -4
  83. package/src/main/dispose-state.ts +4 -3
  84. package/src/main/find-state.ts +1 -1
  85. package/src/main/get-state.ts +6 -5
  86. package/src/main/reset-state.ts +3 -3
  87. package/src/main/set-state.ts +3 -3
  88. package/src/main/subscribe.ts +3 -3
  89. package/src/main/tokens.ts +9 -18
  90. package/src/main/transaction.ts +13 -15
  91. package/src/react/use-json.ts +5 -5
  92. package/src/react-devtools/TransactionIndex.tsx +3 -3
  93. package/src/react-devtools/Updates.tsx +2 -2
  94. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
  95. package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -13
  96. package/src/realtime-client/pull-mutable-atom.ts +5 -8
  97. package/src/realtime-client/push-state.ts +6 -5
  98. package/src/realtime-client/server-action.ts +5 -4
  99. package/src/realtime-react/use-pull-mutable-atom.ts +1 -1
  100. package/src/realtime-react/use-pull-mutable-family-member.ts +1 -1
  101. package/src/realtime-react/use-server-action.ts +2 -2
  102. package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
  103. package/src/realtime-server/realtime-mutable-provider.ts +1 -1
  104. package/src/transceivers/set-rtx/set-rtx.ts +14 -1
  105. package/src/internal/set-state/copy-mutable-if-needed.ts +0 -29
@@ -1,9 +1,9 @@
1
1
  import type { TransactionToken, TransactionUpdateHandler } from "atom.io"
2
2
 
3
- import type { Func, Store } from ".."
3
+ import type { Fn, Store } from ".."
4
4
  import { withdraw } from ".."
5
5
 
6
- export const subscribeToTransaction = <F extends Func>(
6
+ export const subscribeToTransaction = <F extends Fn>(
7
7
  store: Store,
8
8
  token: TransactionToken<F>,
9
9
  key: string,
@@ -23,7 +23,7 @@ import { getUpdateToken } from "../mutable"
23
23
  import { type Store, withdraw } from "../store"
24
24
  import { Subject } from "../subject"
25
25
  import { isChildStore } from "../transaction"
26
- import type { Flat, Func } from "../utility-types"
26
+ import type { Flat, Fn } from "../utility-types"
27
27
 
28
28
  export type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<
29
29
  StateUpdate<TokenType<ManagedAtom>> & {
@@ -40,7 +40,7 @@ export type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {
40
40
  atomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[]
41
41
  }
42
42
  export type TimelineTransactionUpdate = Flat<
43
- TransactionUpdate<Func> & {
43
+ TransactionUpdate<Fn> & {
44
44
  key: string
45
45
  type: `transaction_update`
46
46
  timestamp: number
@@ -340,7 +340,7 @@ function addAtomFamilyToTimeline(
340
340
  function joinTransaction(
341
341
  store: Store,
342
342
  tl: Timeline<any>,
343
- txUpdateInProgress: TransactionUpdate<Func>,
343
+ txUpdateInProgress: TransactionUpdate<Fn>,
344
344
  ) {
345
345
  const currentTxKey = txUpdateInProgress.key
346
346
  const currentTxInstanceId = txUpdateInProgress.id
@@ -3,9 +3,9 @@ import type { TransactionToken } from "atom.io"
3
3
  import { NotFoundError } from "../not-found-error"
4
4
  import type { Store } from "../store"
5
5
  import { withdraw } from "../store"
6
- import type { Func } from "../utility-types"
6
+ import type { Fn } from "../utility-types"
7
7
 
8
- export function actUponStore<F extends Func>(
8
+ export function actUponStore<F extends Fn>(
9
9
  store: Store,
10
10
  token: TransactionToken<F>,
11
11
  id: string,
@@ -2,11 +2,11 @@ import { ingestTransactionUpdate } from "../ingest-updates"
2
2
  import { newest } from "../lineage"
3
3
  import type { Store } from "../store"
4
4
  import { withdraw } from "../store"
5
- import type { Func } from "../utility-types"
5
+ import type { Fn } from "../utility-types"
6
6
  import { isChildStore, isRootStore } from "./is-root-store"
7
7
  import { setEpochNumberOfAction } from "./set-epoch-number"
8
8
 
9
- export const applyTransaction = <F extends Func>(
9
+ export const applyTransaction = <F extends Fn>(
10
10
  output: ReturnType<F>,
11
11
  store: Store,
12
12
  ): void => {
@@ -16,7 +16,7 @@ import { newest } from "../lineage"
16
16
  import { getJsonToken } from "../mutable"
17
17
  import { resetInStore, setIntoStore } from "../set-state"
18
18
  import type { Store } from "../store"
19
- import type { Func } from "../utility-types"
19
+ import type { Fn } from "../utility-types"
20
20
  import type { TransactionProgress } from "."
21
21
  import { actUponStore, getEpochNumberOfAction } from "."
22
22
  import type { ChildStore, RootStore } from "./is-root-store"
@@ -66,7 +66,7 @@ export const buildTransaction = (
66
66
  miscResources: new LazyMap(parent.miscResources),
67
67
  }
68
68
  const epoch = getEpochNumberOfAction(store, key)
69
- const transactionMeta: TransactionProgress<Func> = {
69
+ const transactionMeta: TransactionProgress<Fn> = {
70
70
  phase: `building`,
71
71
  update: {
72
72
  type: `transaction_update`,
@@ -8,12 +8,12 @@ import { newest } from "../lineage"
8
8
  import type { Store } from "../store"
9
9
  import { deposit } from "../store"
10
10
  import { Subject } from "../subject"
11
- import type { Func } from "../utility-types"
11
+ import type { Fn } from "../utility-types"
12
12
  import { abortTransaction } from "./abort-transaction"
13
13
  import { applyTransaction } from "./apply-transaction"
14
14
  import { buildTransaction } from "./build-transaction"
15
15
 
16
- export type Transaction<F extends Func> = {
16
+ export type Transaction<F extends Fn> = {
17
17
  key: string
18
18
  type: `transaction`
19
19
  install: (store: Store) => void
@@ -21,7 +21,7 @@ export type Transaction<F extends Func> = {
21
21
  run: (parameters: Parameters<F>, id?: string) => ReturnType<F>
22
22
  }
23
23
 
24
- export function createTransaction<F extends Func>(
24
+ export function createTransaction<F extends Fn>(
25
25
  store: Store,
26
26
  options: TransactionOptions<F>,
27
27
  ): TransactionToken<F> {
@@ -1,7 +1,7 @@
1
1
  import type { ActorToolkit, TransactionUpdate } from "atom.io"
2
2
 
3
3
  import type { Junction } from "../junction"
4
- import type { Func } from "../utility-types"
4
+ import type { Fn } from "../utility-types"
5
5
 
6
6
  export * from "./abort-transaction"
7
7
  export * from "./act-upon-store"
@@ -16,7 +16,7 @@ export * from "./set-epoch-number"
16
16
  export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
17
17
  export type TransactionPhase = (typeof TRANSACTION_PHASES)[number]
18
18
 
19
- export type TransactionProgress<F extends Func> = {
19
+ export type TransactionProgress<F extends Fn> = {
20
20
  phase: `applying` | `building`
21
21
  update: TransactionUpdate<F>
22
22
  toolkit: ActorToolkit
@@ -1,5 +1,6 @@
1
+ import type { LazyMap } from "../lazy-map"
1
2
  import type { Store } from "../store"
2
- import type { Func } from "../utility-types"
3
+ import type { Fn } from "../utility-types"
3
4
  import type { TransactionEpoch, TransactionProgress } from "."
4
5
 
5
6
  export interface RootStore extends Store {
@@ -8,9 +9,10 @@ export interface RootStore extends Store {
8
9
  child: ChildStore | null
9
10
  }
10
11
  export interface ChildStore extends Store {
11
- transactionMeta: TransactionProgress<Func>
12
+ transactionMeta: TransactionProgress<Fn>
12
13
  parent: ChildStore | RootStore
13
14
  child: ChildStore | null
15
+ valueMap: LazyMap<string, any>
14
16
  }
15
17
 
16
18
  export function isRootStore(store: Store): store is RootStore {
@@ -1,4 +1,4 @@
1
- export type Func = (...parameters: any[]) => any
1
+ export type Fn = (...parameters: any[]) => any
2
2
 
3
3
  export type Flat<R extends { [K in PropertyKey]: any }> = {
4
4
  [K in keyof R]: R[K]
@@ -6,7 +6,7 @@ import type {
6
6
  TransactionToken,
7
7
  TransactionUpdate,
8
8
  } from "atom.io"
9
- import type { Func, Store, Timeline } from "atom.io/internal"
9
+ import type { Fn, Store, Timeline } from "atom.io/internal"
10
10
 
11
11
  import { type AtomTokenIndex, attachAtomIndex } from "./attach-atom-index"
12
12
  import type { SelectorTokenIndex } from "./attach-selector-index"
@@ -20,9 +20,9 @@ import { attachTypeSelectors } from "./attach-type-selectors"
20
20
  export type IntrospectionStates = {
21
21
  atomIndex: AtomToken<AtomTokenIndex>
22
22
  selectorIndex: AtomToken<SelectorTokenIndex>
23
- transactionIndex: AtomToken<TransactionToken<Func>[]>
23
+ transactionIndex: AtomToken<TransactionToken<Fn>[]>
24
24
  transactionLogSelectors: ReadonlyPureSelectorFamilyToken<
25
- TransactionUpdate<Func>[],
25
+ TransactionUpdate<Fn>[],
26
26
  string
27
27
  >
28
28
  timelineIndex: AtomToken<TimelineToken<any>[]>
@@ -1,16 +1,16 @@
1
1
  import type { AtomToken, TransactionToken } from "atom.io"
2
- import type { Func, Store } from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
3
  import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
4
4
 
5
5
  export const attachTransactionIndex = (
6
6
  store: Store,
7
- ): AtomToken<TransactionToken<Func>[]> => {
8
- return createRegularAtom<TransactionToken<Func>[]>(
7
+ ): AtomToken<TransactionToken<Fn>[]> => {
8
+ return createRegularAtom<TransactionToken<Fn>[]>(
9
9
  store,
10
10
  {
11
11
  key: `🔍 Transaction Token Index`,
12
12
  default: () => {
13
- const tokens: TransactionToken<Func>[] = []
13
+ const tokens: TransactionToken<Fn>[] = []
14
14
  for (const [key] of store.transactions) {
15
15
  if (isReservedIntrospectionKey(key)) {
16
16
  continue
@@ -1,12 +1,12 @@
1
1
  import type { ReadonlyPureSelectorFamilyToken, TransactionUpdate } from "atom.io"
2
- import type { Func, Store } from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
3
  import { createRegularAtomFamily, createSelectorFamily } from "atom.io/internal"
4
4
 
5
5
  export const attachTransactionLogs = (
6
6
  store: Store,
7
- ): ReadonlyPureSelectorFamilyToken<TransactionUpdate<Func>[], string> => {
7
+ ): ReadonlyPureSelectorFamilyToken<TransactionUpdate<Fn>[], string> => {
8
8
  const transactionUpdateLogAtoms = createRegularAtomFamily<
9
- TransactionUpdate<Func>[],
9
+ TransactionUpdate<Fn>[],
10
10
  string
11
11
  >(store, {
12
12
  key: `🔍 Transaction Update Log (Internal)`,
@@ -23,7 +23,7 @@ export const attachTransactionLogs = (
23
23
  ],
24
24
  })
25
25
  const findTransactionUpdateLogState = createSelectorFamily<
26
- TransactionUpdate<Func>[],
26
+ TransactionUpdate<Fn>[],
27
27
  string
28
28
  >(store, {
29
29
  key: `🔍 Transaction Update Log`,
@@ -4,7 +4,7 @@ import {
4
4
  type ReadableToken,
5
5
  type SelectorToken,
6
6
  } from "atom.io"
7
- import * as Internal from "atom.io/internal"
7
+ import { IMPLICIT, type Store } from "atom.io/internal"
8
8
 
9
9
  import type { FamilyNode } from "."
10
10
  import type { AtomTokenIndex } from "./attach-atom-index"
@@ -22,7 +22,7 @@ export type ListResourcesParam = {
22
22
  * @experimental
23
23
  */
24
24
  export class Auditor {
25
- public readonly store: Internal.Store
25
+ public readonly store: Store
26
26
  public auditorCreatedAt: number = performance.now()
27
27
  public statesCreatedAt: Map<string, number> = new Map()
28
28
  public readonly atomIndex: AtomToken<AtomTokenIndex>
@@ -37,7 +37,7 @@ export class Auditor {
37
37
  /**
38
38
  * @param {Store} store - The store to audit.
39
39
  */
40
- public constructor(store: Internal.Store = Internal.IMPLICIT.STORE) {
40
+ public constructor(store: Store = IMPLICIT.STORE) {
41
41
  this.store = store
42
42
  this.atomIndex = attachAtomIndex(this.store)
43
43
  this.selectorIndex = attachSelectorIndex(this.store)
package/src/main/atom.ts CHANGED
@@ -34,7 +34,7 @@ export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
34
34
  return createRegularAtom(IMPLICIT.STORE, options, undefined)
35
35
  }
36
36
 
37
- export type MutableAtomOptions<T extends Transceiver<any, any>> = {
37
+ export type MutableAtomOptions<T extends Transceiver<any, any, any>> = {
38
38
  /** The unique identifier of the atom */
39
39
  key: string
40
40
  /** A constructor for the atom's value */
@@ -51,7 +51,7 @@ export type MutableAtomOptions<T extends Transceiver<any, any>> = {
51
51
  * @returns
52
52
  * A reference to the atom created: a {@link MutableAtomToken}
53
53
  */
54
- export function mutableAtom<T extends Transceiver<any, any>>(
54
+ export function mutableAtom<T extends Transceiver<any, any, any>>(
55
55
  options: MutableAtomOptions<T>,
56
56
  ): MutableAtomToken<T> {
57
57
  return createMutableAtom(IMPLICIT.STORE, options, undefined)
@@ -99,7 +99,7 @@ export function atomFamily<T, K extends Canonical>(
99
99
  }
100
100
 
101
101
  export type MutableAtomFamilyOptions<
102
- T extends Transceiver<any, any>,
102
+ T extends Transceiver<any, any, any>,
103
103
  K extends Canonical,
104
104
  > = {
105
105
  /** The unique identifier of the atom family */
@@ -119,7 +119,7 @@ export type MutableAtomFamilyOptions<
119
119
  * A reference to the atom family created: a {@link MutableAtomFamilyToken}
120
120
  */
121
121
  export function mutableAtomFamily<
122
- T extends Transceiver<any, any>,
122
+ T extends Transceiver<any, any, any>,
123
123
  K extends Canonical,
124
124
  >(options: MutableAtomFamilyOptions<T, K>): MutableAtomFamilyToken<T, K> {
125
125
  return createMutableAtomFamily(IMPLICIT.STORE, options)
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { disposeFromStore, IMPLICIT } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { ReadableFamilyToken, ReadableToken } from "."
@@ -19,6 +19,7 @@ export function disposeState(token: ReadableToken<any>): void
19
19
  *
20
20
  * @param token - The token of the state family to dispose
21
21
  * @param key - The unique key of the state to dispose
22
+ * @overload Streamlined
22
23
  */
23
24
  export function disposeState<K extends Canonical>(
24
25
  token: ReadableFamilyToken<any, K>,
@@ -30,8 +31,8 @@ export function disposeState(
30
31
  | [token: ReadableToken<any>]
31
32
  ): void {
32
33
  if (params.length === 2) {
33
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, ...params)
34
+ disposeFromStore(IMPLICIT.STORE, ...params)
34
35
  } else {
35
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, ...params)
36
+ disposeFromStore(IMPLICIT.STORE, ...params)
36
37
  }
37
38
  }
@@ -30,7 +30,7 @@ import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
30
30
  * @overload Mutable Atom
31
31
  */
32
32
  export function findState<
33
- T extends Transceiver<any, any>,
33
+ T extends Transceiver<any, any, any>,
34
34
  K extends Canonical,
35
35
  Key extends K,
36
36
  >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T, K>
@@ -1,4 +1,5 @@
1
- import * as Internal from "atom.io/internal"
1
+ import type { ViewOf } from "atom.io/internal"
2
+ import { getFromStore, IMPLICIT } from "atom.io/internal"
2
3
  import type { Canonical } from "atom.io/json"
3
4
 
4
5
  import type { ReadableFamilyToken, ReadableToken } from "."
@@ -10,7 +11,7 @@ import type { ReadableFamilyToken, ReadableToken } from "."
10
11
  * @overload Default
11
12
  * @default
12
13
  */
13
- export function getState<T>(token: ReadableToken<T>): T
14
+ export function getState<T>(token: ReadableToken<T>): ViewOf<T>
14
15
 
15
16
  /**
16
17
  * Read or compute the current value of a state
@@ -22,7 +23,7 @@ export function getState<T>(token: ReadableToken<T>): T
22
23
  export function getState<T, K extends Canonical, Key extends K>(
23
24
  token: ReadableFamilyToken<T, K>,
24
25
  key: Key,
25
- ): T
26
+ ): ViewOf<T>
26
27
 
27
28
  export function getState(
28
29
  ...params:
@@ -30,7 +31,7 @@ export function getState(
30
31
  | [token: ReadableToken<any>]
31
32
  ): any {
32
33
  if (params.length === 2) {
33
- return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
34
+ return getFromStore(IMPLICIT.STORE, ...params)
34
35
  }
35
- return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
36
+ return getFromStore(IMPLICIT.STORE, ...params)
36
37
  }
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { IMPLICIT, resetInStore } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "."
@@ -26,8 +26,8 @@ export function resetState(
26
26
  | [token: WritableToken<any>]
27
27
  ): void {
28
28
  if (params.length === 2) {
29
- Internal.resetInStore(Internal.IMPLICIT.STORE, ...params)
29
+ resetInStore(IMPLICIT.STORE, ...params)
30
30
  } else {
31
- Internal.resetInStore(Internal.IMPLICIT.STORE, ...params)
31
+ resetInStore(IMPLICIT.STORE, ...params)
32
32
  }
33
33
  }
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { IMPLICIT, setIntoStore } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "./tokens"
@@ -45,8 +45,8 @@ export function setState<T, New extends T>(
45
45
  | [token: WritableToken<T>, value: New | Setter<T, New>]
46
46
  ): void {
47
47
  if (params.length === 2) {
48
- Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
48
+ setIntoStore(IMPLICIT.STORE, ...params)
49
49
  } else {
50
- Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
50
+ setIntoStore(IMPLICIT.STORE, ...params)
51
51
  }
52
52
  }
@@ -1,4 +1,4 @@
1
- import type { Flat, Func } from "atom.io/internal"
1
+ import type { Flat, Fn } from "atom.io/internal"
2
2
  import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
3
3
 
4
4
  import type {
@@ -20,7 +20,7 @@ export type KeyedStateUpdate<T> = Flat<
20
20
  }
21
21
  >
22
22
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
23
- export type TransactionUpdateHandler<F extends Func> = (
23
+ export type TransactionUpdateHandler<F extends Fn> = (
24
24
  data: TransactionUpdate<F>,
25
25
  ) => void
26
26
 
@@ -45,7 +45,7 @@ export function subscribe<T>(
45
45
  * @returns A function that can be called to unsubscribe from the transaction
46
46
  * @overload Transaction
47
47
  */
48
- export function subscribe<F extends Func>(
48
+ export function subscribe<F extends Fn>(
49
49
  token: TransactionToken<F>,
50
50
  handleUpdate: TransactionUpdateHandler<F>,
51
51
  key?: string,
@@ -1,4 +1,4 @@
1
- import type { AsJSON, Func, Transceiver } from "atom.io/internal"
1
+ import type { AsJSON, Fn, Transceiver } from "atom.io/internal"
2
2
  import type { Canonical, stringified } from "atom.io/json"
3
3
 
4
4
  /**
@@ -18,27 +18,22 @@ export type AtomIOToken =
18
18
  | TimelineToken<any>
19
19
  | TransactionToken<any>
20
20
 
21
- /**
22
- * These states cannot be set.
23
- */
24
21
  export type ReadableToken<T, K extends Canonical = any> =
25
22
  | AtomToken<T, K>
26
23
  | SelectorToken<T, K>
27
- /**
28
- * These states can be set.
29
- */
24
+
30
25
  export type WritableToken<T, K extends Canonical = any> =
31
26
  | AtomToken<T, K>
32
27
  | WritableSelectorToken<T, K>
33
28
 
34
29
  /**
35
- * States belonging to this family can be gotten from the store.
30
+ * States belonging to this family can be read from the store.
36
31
  */
37
32
  export type ReadableFamilyToken<T, K extends Canonical> =
38
33
  | AtomFamilyToken<T, K>
39
34
  | SelectorFamilyToken<T, K>
40
35
  /**
41
- * States belonging to this family can be set.
36
+ * States belonging to this family can be written directly.
42
37
  */
43
38
  export type WritableFamilyToken<T, K extends Canonical> =
44
39
  | AtomFamilyToken<T, K>
@@ -53,7 +48,7 @@ export type TimelineToken<M> = {
53
48
  __M?: M
54
49
  }
55
50
 
56
- export type TransactionToken<F extends Func> = {
51
+ export type TransactionToken<F extends Fn> = {
57
52
  /** The unique identifier of the transaction */
58
53
  key: string
59
54
  /** Discriminator */
@@ -63,7 +58,7 @@ export type TransactionToken<F extends Func> = {
63
58
  }
64
59
 
65
60
  export type AtomToken<T, K extends Canonical = any> =
66
- | MutableAtomToken<T extends Transceiver<any, any> ? T : never, K>
61
+ | MutableAtomToken<T extends Transceiver<any, any, any> ? T : never, K>
67
62
  | RegularAtomToken<T, K>
68
63
  export type RegularAtomToken<T, K extends Canonical = any> = {
69
64
  /** The unique identifier of the atom. */
@@ -76,7 +71,7 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
76
71
  __T?: T
77
72
  }
78
73
  export type MutableAtomToken<
79
- T extends Transceiver<any, any>,
74
+ T extends Transceiver<any, any, any>,
80
75
  K extends Canonical = any,
81
76
  > = {
82
77
  /** The unique identifier of the atom. */
@@ -87,8 +82,6 @@ export type MutableAtomToken<
87
82
  family?: FamilyMetadata<K>
88
83
  /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
89
84
  __J?: AsJSON<T>
90
- /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
91
- __U?: T extends Transceiver<infer Update, any> ? Update : never
92
85
  }
93
86
 
94
87
  export type SelectorToken<T, K extends Canonical = any> =
@@ -159,7 +152,7 @@ export type FamilyMetadata<K extends Canonical = any> = {
159
152
  }
160
153
 
161
154
  export type AtomFamilyToken<T, K extends Canonical = Canonical> =
162
- | MutableAtomFamilyToken<T extends Transceiver<any, any> ? T : never, K>
155
+ | MutableAtomFamilyToken<T extends Transceiver<any, any, any> ? T : never, K>
163
156
  | RegularAtomFamilyToken<T, K>
164
157
  export type RegularAtomFamilyToken<T, K extends Canonical> = {
165
158
  /** The unique identifier of the atom family */
@@ -172,7 +165,7 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
172
165
  __K?: K
173
166
  }
174
167
  export type MutableAtomFamilyToken<
175
- T extends Transceiver<any, any>,
168
+ T extends Transceiver<any, any, any>,
176
169
  K extends Canonical,
177
170
  > = {
178
171
  /** The unique identifier of the atom family */
@@ -181,8 +174,6 @@ export type MutableAtomFamilyToken<
181
174
  type: `mutable_atom_family`
182
175
  /** Never present. This is a marker that preserves the type of atoms in this family */
183
176
  __T?: T
184
- /** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
185
- __J?: AsJSON<T>
186
177
  /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
187
178
  __K?: K
188
179
  }
@@ -1,9 +1,4 @@
1
- import type {
2
- AsJSON,
3
- EnvironmentData,
4
- Func,
5
- Transceiver,
6
- } from "atom.io/internal"
1
+ import type { AsJSON, EnvironmentData, Fn, Transceiver } from "atom.io/internal"
7
2
  import {
8
3
  actUponStore,
9
4
  arbitrary,
@@ -33,6 +28,9 @@ export type StateCreation<Token extends ReadableToken<any>> = {
33
28
  export type StateDisposal<Token extends ReadableToken<any>> =
34
29
  | AtomDisposal<Token>
35
30
  | SelectorDisposal<Token>
31
+ export type StateLifecycleEvent<Token extends ReadableToken<any>> =
32
+ | StateCreation<Token>
33
+ | StateDisposal<Token>
36
34
 
37
35
  export type AtomDisposal<Token extends ReadableToken<any>> = {
38
36
  type: `state_disposal`
@@ -72,9 +70,9 @@ export type TransactionUpdateContent =
72
70
  | MoleculeTransfer
73
71
  | StateCreation<ReadableToken<unknown>>
74
72
  | StateDisposal<ReadableToken<unknown>>
75
- | TransactionUpdate<Func>
73
+ | TransactionUpdate<Fn>
76
74
 
77
- export type TransactionUpdate<F extends Func> = {
75
+ export type TransactionUpdate<F extends Fn> = {
78
76
  type: `transaction_update`
79
77
  key: string
80
78
  id: string
@@ -91,7 +89,7 @@ export type ActorToolkit = Readonly<{
91
89
  set: typeof setState
92
90
  reset: typeof resetState
93
91
  find: typeof findState
94
- json: <T extends Transceiver<any, any>>(
92
+ json: <T extends Transceiver<any, any, any>>(
95
93
  state: MutableAtomToken<T>,
96
94
  ) => WritablePureSelectorToken<AsJSON<T>>
97
95
  dispose: typeof disposeState
@@ -99,21 +97,21 @@ export type ActorToolkit = Readonly<{
99
97
  env: () => EnvironmentData
100
98
  }>
101
99
 
102
- export type Read<F extends Func> = (
100
+ export type Read<F extends Fn> = (
103
101
  toolkit: ReaderToolkit,
104
102
  ...parameters: Parameters<F>
105
103
  ) => ReturnType<F>
106
- export type Write<F extends Func> = (
104
+ export type Write<F extends Fn> = (
107
105
  toolkit: WriterToolkit,
108
106
  ...parameters: Parameters<F>
109
107
  ) => ReturnType<F>
110
- export type Transact<F extends Func> = (
108
+ export type Transact<F extends Fn> = (
111
109
  toolkit: ActorToolkit,
112
110
  ...parameters: Parameters<F>
113
111
  ) => ReturnType<F>
114
112
  export type TransactionIO<Token extends TransactionToken<any>> =
115
113
  Token extends TransactionToken<infer F> ? F : never
116
- export type TransactionOptions<F extends Func> = {
114
+ export type TransactionOptions<F extends Fn> = {
117
115
  /** The unique identifier of the transaction */
118
116
  key: string
119
117
  /** The operation to perform */
@@ -125,7 +123,7 @@ export type TransactionOptions<F extends Func> = {
125
123
  * @param options - {@link TransactionOptions}
126
124
  * @returns A reference to the transaction created: a {@link TransactionToken}
127
125
  */
128
- export function transaction<F extends Func>(
126
+ export function transaction<F extends Fn>(
129
127
  options: TransactionOptions<F>,
130
128
  ): TransactionToken<F> {
131
129
  return createTransaction(IMPLICIT.STORE, options)
@@ -137,7 +135,7 @@ export function transaction<F extends Func>(
137
135
  * @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
138
136
  * @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
139
137
  */
140
- export function runTransaction<F extends Func>(
138
+ export function runTransaction<F extends Fn>(
141
139
  token: TransactionToken<F>,
142
140
  id: string = arbitrary(),
143
141
  ): (...parameters: Parameters<F>) => ReturnType<F> {
@@ -7,14 +7,14 @@ import * as React from "react"
7
7
  import { StoreContext } from "./store-context"
8
8
  import { useO } from "./use-o"
9
9
 
10
- export function useJSON<T extends Transceiver<any, any>>(
10
+ export function useJSON<T extends Transceiver<any, any, any>>(
11
11
  token: MutableAtomToken<T>,
12
12
  ): AsJSON<T>
13
13
 
14
- export function useJSON<T extends Transceiver<any, any>, K extends Canonical>(
15
- token: MutableAtomFamilyToken<T, K>,
16
- key: K,
17
- ): AsJSON<T>
14
+ export function useJSON<
15
+ T extends Transceiver<any, any, any>,
16
+ K extends Canonical,
17
+ >(token: MutableAtomFamilyToken<T, K>, key: K): AsJSON<T>
18
18
 
19
19
  export function useJSON(
20
20
  token: MutableAtomFamilyToken<any, any> | MutableAtomToken<any>,
@@ -4,7 +4,7 @@ import type {
4
4
  TransactionToken,
5
5
  TransactionUpdate,
6
6
  } from "atom.io"
7
- import { findInStore, type Func } from "atom.io/internal"
7
+ import { findInStore, type Fn } from "atom.io/internal"
8
8
  import { useI, useO } from "atom.io/react"
9
9
  import { type FC, useContext } from "react"
10
10
 
@@ -13,9 +13,9 @@ import { DevtoolsContext } from "./store"
13
13
  import { article } from "./Updates"
14
14
 
15
15
  export const TransactionLog: FC<{
16
- token: TransactionToken<Func>
16
+ token: TransactionToken<Fn>
17
17
  isOpenState: RegularAtomToken<boolean>
18
- logState: ReadonlyPureSelectorToken<TransactionUpdate<Func>[]>
18
+ logState: ReadonlyPureSelectorToken<TransactionUpdate<Fn>[]>
19
19
  }> = ({ token, isOpenState, logState }) => {
20
20
  const log = useO(logState)
21
21
  const isOpen = useO(isOpenState)