atom.io 0.8.0 → 0.8.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 (73) hide show
  1. package/dist/index.d.mts +8 -5
  2. package/dist/index.d.ts +8 -5
  3. package/dist/index.js +67 -72
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +34 -38
  6. package/dist/index.mjs.map +1 -1
  7. package/internal/dist/index.d.mts +27 -33
  8. package/internal/dist/index.d.ts +27 -33
  9. package/internal/dist/index.js +45 -69
  10. package/internal/dist/index.js.map +1 -1
  11. package/internal/dist/index.mjs +34 -39
  12. package/internal/dist/index.mjs.map +1 -1
  13. package/internal/src/caching.ts +12 -5
  14. package/internal/src/future.ts +2 -4
  15. package/internal/src/mutable/create-mutable-atom-family.ts +4 -4
  16. package/internal/src/mutable/create-mutable-atom.ts +6 -5
  17. package/internal/src/mutable/is-atom-token-mutable.ts +3 -3
  18. package/internal/src/mutable/tracker-family.ts +4 -4
  19. package/internal/src/mutable/tracker.ts +20 -19
  20. package/internal/src/operation.ts +5 -2
  21. package/internal/src/selector/create-read-write-selector.ts +2 -2
  22. package/internal/src/selector/register-selector.ts +2 -2
  23. package/internal/src/set-state/{set-atom-state.ts → set-atom.ts} +1 -1
  24. package/internal/src/set-state/set-selector-state.ts +1 -12
  25. package/internal/src/set-state/set-state-internal.ts +4 -5
  26. package/internal/src/store/withdraw-new-family-member.ts +7 -7
  27. package/internal/src/store/withdraw.ts +15 -9
  28. package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
  29. package/internal/src/timeline/add-atom-to-timeline.ts +2 -2
  30. package/internal/src/transaction/apply-transaction.ts +1 -1
  31. package/internal/src/transaction/redo-transaction.ts +1 -1
  32. package/internal/src/transaction/undo-transaction.ts +1 -1
  33. package/package.json +11 -8
  34. package/react-devtools/dist/index.d.mts +4 -4
  35. package/react-devtools/dist/index.d.ts +4 -4
  36. package/react-devtools/dist/index.js +3 -3
  37. package/react-devtools/dist/index.js.map +1 -1
  38. package/react-devtools/dist/index.mjs +3 -3
  39. package/react-devtools/dist/index.mjs.map +1 -1
  40. package/realtime-client/dist/index.d.mts +21 -0
  41. package/realtime-client/dist/index.d.ts +21 -0
  42. package/realtime-client/dist/index.js +173 -0
  43. package/realtime-client/dist/index.js.map +1 -0
  44. package/realtime-client/dist/index.mjs +144 -0
  45. package/realtime-client/dist/index.mjs.map +1 -0
  46. package/realtime-client/package.json +15 -0
  47. package/realtime-client/src/index.ts +7 -0
  48. package/realtime-client/src/realtime-state.ts +10 -0
  49. package/realtime-client/src/use-pull-family-member.ts +26 -0
  50. package/realtime-client/src/use-pull-mutable-family-member.ts +38 -0
  51. package/realtime-client/src/use-pull-mutable.ts +32 -0
  52. package/realtime-client/src/use-pull.ts +19 -0
  53. package/realtime-client/src/use-push.ts +25 -0
  54. package/realtime-client/src/use-server-action.ts +49 -0
  55. package/realtime-server/dist/index.d.mts +25 -0
  56. package/realtime-server/dist/index.d.ts +25 -0
  57. package/realtime-server/dist/index.js +316 -0
  58. package/realtime-server/dist/index.js.map +1 -0
  59. package/realtime-server/dist/index.mjs +289 -0
  60. package/realtime-server/dist/index.mjs.map +1 -0
  61. package/realtime-server/package.json +15 -0
  62. package/realtime-server/src/README.md +33 -0
  63. package/realtime-server/src/hook-composition/expose-family.ts +105 -0
  64. package/realtime-server/src/hook-composition/expose-mutable-family.ts +127 -0
  65. package/realtime-server/src/hook-composition/expose-mutable.ts +45 -0
  66. package/realtime-server/src/hook-composition/expose-single.ts +39 -0
  67. package/realtime-server/src/hook-composition/index.ts +14 -0
  68. package/realtime-server/src/hook-composition/receive-state.ts +30 -0
  69. package/realtime-server/src/hook-composition/receive-transaction.ts +37 -0
  70. package/realtime-server/src/index.ts +1 -0
  71. package/src/get-set.ts +48 -0
  72. package/src/index.ts +3 -60
  73. package/src/subscribe.ts +3 -3
@@ -1,4 +1,4 @@
1
- import type { StateUpdate } from "../../src"
1
+ import type { StateUpdate } from "atom.io"
2
2
  import { Future } from "./future"
3
3
  import type { Store } from "./store"
4
4
  import { IMPLICIT } from "./store"
@@ -18,10 +18,17 @@ export const cacheValue = (
18
18
  if (value instanceof Promise) {
19
19
  const future = new Future(value)
20
20
  target(store).valueMap.set(key, future)
21
- future.then((value) => {
22
- cacheValue(key, value, subject, store)
23
- subject.next({ newValue: value, oldValue: value })
24
- })
21
+ future
22
+ .then((value) => {
23
+ cacheValue(key, value, subject, store)
24
+ subject.next({ newValue: value, oldValue: value })
25
+ })
26
+ .catch((error) => {
27
+ store.config.logger?.error(
28
+ `Promised value for "${key}" rejected:`,
29
+ error,
30
+ )
31
+ })
25
32
  } else {
26
33
  target(store).valueMap.set(key, value)
27
34
  }
@@ -1,7 +1,5 @@
1
- import { E } from "vitest/dist/reporters-5f784f42"
2
-
3
- export type Eventual<T> = Promise<T> | T
4
- export type Fated<T, E extends Error = Error> = Eventual<E | T>
1
+ export type Loadable<T> = Promise<T> | T
2
+ export type Fated<T, E extends Error = Error> = Loadable<E | T>
5
3
 
6
4
  /**
7
5
  * A Promise that can be canceled.
@@ -1,4 +1,4 @@
1
- import type * as AtomIO from "atom.io"
1
+ import type { MutableAtomFamily, MutableAtomFamilyOptions } from "atom.io"
2
2
  import type { Json } from "atom.io/json"
3
3
  import { selectJsonFamily } from "atom.io/json"
4
4
 
@@ -12,13 +12,13 @@ export function createMutableAtomFamily<
12
12
  SerializableCore extends Json.Serializable,
13
13
  Key extends string,
14
14
  >(
15
- options: AtomIO.MutableAtomFamilyOptions<Core, SerializableCore, Key>,
15
+ options: MutableAtomFamilyOptions<Core, SerializableCore, Key>,
16
16
  store: Store = IMPLICIT.STORE,
17
- ): AtomIO.MutableAtomFamily<Core, SerializableCore, Key> {
17
+ ): MutableAtomFamily<Core, SerializableCore, Key> {
18
18
  const coreFamily = Object.assign(
19
19
  createAtomFamily<Core, Key>(options, store),
20
20
  options,
21
- ) as AtomIO.MutableAtomFamily<Core, SerializableCore, Key>
21
+ ) as MutableAtomFamily<Core, SerializableCore, Key>
22
22
  selectJsonFamily(coreFamily, options)
23
23
  new FamilyTracker(coreFamily, store)
24
24
  return coreFamily
@@ -1,4 +1,5 @@
1
- import * as AtomIO from "atom.io"
1
+ import type { MutableAtomOptions, MutableAtomToken } from "atom.io"
2
+ import { subscribe } from "atom.io"
2
3
  import type { Json } from "atom.io/json"
3
4
  import { selectJson } from "atom.io/json"
4
5
 
@@ -13,16 +14,16 @@ export function createMutableAtom<
13
14
  Core extends Transceiver<any>,
14
15
  SerializableCore extends Json.Serializable,
15
16
  >(
16
- options: AtomIO.MutableAtomOptions<Core, SerializableCore>,
17
+ options: MutableAtomOptions<Core, SerializableCore>,
17
18
  store: Store = IMPLICIT.STORE,
18
- ): AtomIO.MutableAtomToken<Core, SerializableCore> {
19
+ ): MutableAtomToken<Core, SerializableCore> {
19
20
  store.config.logger?.info(
20
21
  `🔧 creating mutable atom "${options.key}" in store "${store.config.name}"`,
21
22
  )
22
23
  const coreState = createAtom<Core>(options, undefined, store)
23
24
  new Tracker(coreState, store)
24
25
  const jsonState = selectJson(coreState, options, store)
25
- AtomIO.subscribe(
26
+ subscribe(
26
27
  jsonState,
27
28
  () => {
28
29
  store.config.logger?.info(
@@ -45,5 +46,5 @@ export function createMutableAtom<
45
46
  : store.transactionStatus.key
46
47
  }`,
47
48
  )
48
- return coreState as AtomIO.MutableAtomToken<Core, SerializableCore>
49
+ return coreState as MutableAtomToken<Core, SerializableCore>
49
50
  }
@@ -1,7 +1,7 @@
1
- import type * as AtomIO from "atom.io"
1
+ import type { AtomToken, MutableAtomToken } from "atom.io"
2
2
 
3
3
  export function isAtomTokenMutable(
4
- token: AtomIO.AtomToken<any>,
5
- ): token is AtomIO.MutableAtomToken<any, any> {
4
+ token: AtomToken<any>,
5
+ ): token is MutableAtomToken<any, any> {
6
6
  return token.key.endsWith(`::mutable`)
7
7
  }
@@ -1,4 +1,4 @@
1
- import type * as AtomIO from "atom.io"
1
+ import type { AtomFamily } from "atom.io"
2
2
  import type { Json } from "atom.io/json"
3
3
  import { parseJson } from "atom.io/json"
4
4
 
@@ -16,14 +16,14 @@ export class FamilyTracker<
16
16
  ? Signal
17
17
  : never
18
18
 
19
- public readonly findLatestUpdateState: AtomIO.AtomFamily<
19
+ public readonly findLatestUpdateState: AtomFamily<
20
20
  typeof this.Update | null,
21
21
  FamilyMemberKey
22
22
  >
23
- public readonly findMutableState: AtomIO.AtomFamily<Core, FamilyMemberKey>
23
+ public readonly findMutableState: AtomFamily<Core, FamilyMemberKey>
24
24
 
25
25
  public constructor(
26
- findMutableState: AtomIO.AtomFamily<Core, FamilyMemberKey>,
26
+ findMutableState: AtomFamily<Core, FamilyMemberKey>,
27
27
  store: Store = IMPLICIT.STORE,
28
28
  ) {
29
29
  this.findLatestUpdateState = createAtomFamily<
@@ -1,4 +1,5 @@
1
- import * as AtomIO from "atom.io"
1
+ import type { AtomToken, FamilyMetadata, MutableAtomToken } from "atom.io"
2
+ import { getState, setState, subscribe, subscribeToTimeline } from "atom.io"
2
3
  import type { Json } from "atom.io/json"
3
4
 
4
5
  import type { Store } from ".."
@@ -16,12 +17,12 @@ export class Tracker<Mutable extends Transceiver<any>> {
16
17
  private Update: Mutable extends Transceiver<infer Signal> ? Signal : never
17
18
 
18
19
  private initializeState(
19
- mutableState: AtomIO.MutableAtomToken<Mutable, Json.Serializable>,
20
+ mutableState: MutableAtomToken<Mutable, Json.Serializable>,
20
21
  store: Store = IMPLICIT.STORE,
21
- ): AtomIO.AtomToken<typeof this.Update | null> {
22
+ ): AtomToken<typeof this.Update | null> {
22
23
  const latestUpdateStateKey = `*${mutableState.key}`
23
24
  deleteAtom(latestUpdateStateKey, target(store))
24
- const familyMetaData: AtomIO.FamilyMetadata | undefined = mutableState.family
25
+ const familyMetaData: FamilyMetadata | undefined = mutableState.family
25
26
  ? {
26
27
  key: `*${mutableState.family.key}`,
27
28
  subKey: mutableState.family.subKey,
@@ -43,11 +44,11 @@ export class Tracker<Mutable extends Transceiver<any>> {
43
44
 
44
45
  private unsubscribeFromInnerValue: (() => void) | null = null
45
46
  private observeCore(
46
- mutableState: AtomIO.MutableAtomToken<Mutable, Json.Serializable>,
47
- latestUpdateState: AtomIO.AtomToken<typeof this.Update | null>,
47
+ mutableState: MutableAtomToken<Mutable, Json.Serializable>,
48
+ latestUpdateState: AtomToken<typeof this.Update | null>,
48
49
  store: Store = IMPLICIT.STORE,
49
50
  ): void {
50
- const originalInnerValue = AtomIO.getState(mutableState, store)
51
+ const originalInnerValue = getState(mutableState, store)
51
52
  this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
52
53
  `tracker:${store.config.name}:${
53
54
  store.transactionStatus.phase === `idle`
@@ -59,12 +60,12 @@ export class Tracker<Mutable extends Transceiver<any>> {
59
60
  mutableState.key,
60
61
  () => {
61
62
  unsubscribe()
62
- AtomIO.setState(latestUpdateState, update, store)
63
+ setState(latestUpdateState, update, store)
63
64
  },
64
65
  )
65
66
  },
66
67
  )
67
- AtomIO.subscribe(
68
+ subscribe(
68
69
  mutableState,
69
70
  (update) => {
70
71
  if (update.newValue !== update.oldValue) {
@@ -80,7 +81,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
80
81
  mutableState.key,
81
82
  () => {
82
83
  unsubscribe()
83
- AtomIO.setState(latestUpdateState, update, store)
84
+ setState(latestUpdateState, update, store)
84
85
  },
85
86
  )
86
87
  },
@@ -93,11 +94,11 @@ export class Tracker<Mutable extends Transceiver<any>> {
93
94
  }
94
95
 
95
96
  private updateCore<Core extends Transceiver<any>>(
96
- mutableState: AtomIO.MutableAtomToken<Core, Json.Serializable>,
97
- latestUpdateState: AtomIO.AtomToken<typeof this.Update | null>,
97
+ mutableState: MutableAtomToken<Core, Json.Serializable>,
98
+ latestUpdateState: AtomToken<typeof this.Update | null>,
98
99
  store: Store = IMPLICIT.STORE,
99
100
  ): void {
100
- AtomIO.subscribe(
101
+ subscribe(
101
102
  latestUpdateState,
102
103
  ({ newValue, oldValue }) => {
103
104
  const timelineId = store.timelineAtoms.getRelatedKey(
@@ -106,11 +107,11 @@ export class Tracker<Mutable extends Transceiver<any>> {
106
107
  if (timelineId) {
107
108
  const timelineData = store.timelines.get(timelineId)
108
109
  if (timelineData?.timeTraveling) {
109
- const unsubscribe = AtomIO.subscribeToTimeline(
110
+ const unsubscribe = subscribeToTimeline(
110
111
  { key: timelineId, type: `timeline` },
111
112
  (update) => {
112
113
  unsubscribe()
113
- AtomIO.setState(
114
+ setState(
114
115
  mutableState,
115
116
  (transceiver) => {
116
117
  if (update === `redo` && newValue) {
@@ -133,7 +134,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
133
134
  () => {
134
135
  unsubscribe()
135
136
  if (newValue) {
136
- AtomIO.setState(
137
+ setState(
137
138
  mutableState,
138
139
  (transceiver) => (transceiver.do(newValue), transceiver),
139
140
  store,
@@ -147,11 +148,11 @@ export class Tracker<Mutable extends Transceiver<any>> {
147
148
  )
148
149
  }
149
150
 
150
- public mutableState: AtomIO.MutableAtomToken<Mutable, Json.Serializable>
151
- public latestUpdateState: AtomIO.AtomToken<typeof this.Update | null>
151
+ public mutableState: MutableAtomToken<Mutable, Json.Serializable>
152
+ public latestUpdateState: AtomToken<typeof this.Update | null>
152
153
 
153
154
  public constructor(
154
- mutableState: AtomIO.MutableAtomToken<Mutable, Json.Serializable>,
155
+ mutableState: MutableAtomToken<Mutable, Json.Serializable>,
155
156
  store: Store = IMPLICIT.STORE,
156
157
  ) {
157
158
  this.mutableState = mutableState
@@ -16,13 +16,16 @@ export type OperationProgress =
16
16
  token: StateToken<any>
17
17
  }
18
18
 
19
- export const openOperation = (token: StateToken<any>, store: Store): void => {
19
+ export const openOperation = (
20
+ token: StateToken<any>,
21
+ store: Store,
22
+ ): `rejection` | undefined => {
20
23
  const core = target(store)
21
24
  if (core.operation.open) {
22
25
  store.config.logger?.error(
23
26
  `❌ failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`,
24
27
  )
25
- throw Symbol(`violation`)
28
+ return `rejection`
26
29
  }
27
30
  core.operation = {
28
31
  open: true,
@@ -26,14 +26,14 @@ export const createReadWriteSelector = <T>(
26
26
 
27
27
  const setSelf = (next: T | ((oldValue: T) => T)): void => {
28
28
  const oldValue = getSelf()
29
+ const newValue = become(next)(oldValue)
29
30
  store.config.logger?.info(
30
31
  ` <- "${options.key}" went (`,
31
32
  oldValue,
32
33
  `->`,
33
- next,
34
+ newValue,
34
35
  `)`,
35
36
  )
36
- const newValue = become(next)(oldValue)
37
37
  cacheValue(options.key, newValue, subject, store)
38
38
  markDone(options.key, store)
39
39
  if (store.transactionStatus.phase === `idle`) {
@@ -18,7 +18,7 @@ export const registerSelector = (
18
18
  .some(([_, { source }]) => source === dependency.key)
19
19
 
20
20
  const dependencyState = withdraw(dependency, store)
21
- if (dependencyState === null) {
21
+ if (dependencyState === undefined) {
22
22
  throw new Error(
23
23
  `State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
24
24
  )
@@ -51,7 +51,7 @@ export const registerSelector = (
51
51
  },
52
52
  set: (stateToken, newValue) => {
53
53
  const state = withdraw(stateToken, store)
54
- if (state === null) {
54
+ if (state === undefined) {
55
55
  throw new Error(
56
56
  `State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
57
57
  )
@@ -11,7 +11,7 @@ import { emitUpdate } from "./emit-update"
11
11
  import { evictDownStream } from "./evict-downstream"
12
12
  import { stowUpdate } from "./stow-update"
13
13
 
14
- export const setAtomState = <T>(
14
+ export const setAtom = <T>(
15
15
  atom: Atom<T>,
16
16
  next: T | ((oldValue: T) => T),
17
17
  store: Store = IMPLICIT.STORE,
@@ -1,19 +1,8 @@
1
- import { getState__INTERNAL } from "../get-state-internal"
2
1
  import type { Selector } from "../selector"
3
- import type { Store } from "../store"
4
- import { IMPLICIT } from "../store"
5
- import { become } from "./become"
6
2
 
7
3
  export const setSelectorState = <T>(
8
4
  selector: Selector<T>,
9
5
  next: T | ((oldValue: T) => T),
10
- store: Store = IMPLICIT.STORE,
11
6
  ): void => {
12
- const oldValue = getState__INTERNAL(selector, store)
13
- const newValue = become(next)(oldValue)
14
-
15
- store.config.logger?.info(`<< setting selector "${selector.key}" to`, newValue)
16
- store.config.logger?.info(` || propagating change made to "${selector.key}"`)
17
-
18
- selector.set(newValue)
7
+ selector.set(next)
19
8
  }
@@ -2,17 +2,16 @@ import type { Atom } from "../atom"
2
2
  import type { Selector } from "../selector"
3
3
  import type { Store } from "../store"
4
4
  import { IMPLICIT } from "../store"
5
- import { setAtomState } from "./set-atom-state"
6
- import { setSelectorState } from "./set-selector-state"
5
+ import { setAtom } from "./set-atom"
7
6
 
8
7
  export const setState__INTERNAL = <T>(
9
8
  state: Atom<T> | Selector<T>,
10
9
  value: T | ((oldValue: T) => T),
11
10
  store: Store = IMPLICIT.STORE,
12
11
  ): void => {
13
- if (`set` in state) {
14
- setSelectorState(state, value, store)
12
+ if (state.type === `selector`) {
13
+ state.set(value)
15
14
  } else {
16
- setAtomState(state, value, store)
15
+ setAtom(state, value, store)
17
16
  }
18
17
  }
@@ -11,23 +11,23 @@ import { target } from "../transaction"
11
11
  export function withdrawNewFamilyMember<T>(
12
12
  token: AtomToken<T>,
13
13
  store: Store,
14
- ): Atom<T> | null
14
+ ): Atom<T> | undefined
15
15
  export function withdrawNewFamilyMember<T>(
16
16
  token: SelectorToken<T>,
17
17
  store: Store,
18
- ): Selector<T> | null
18
+ ): Selector<T> | undefined
19
19
  export function withdrawNewFamilyMember<T>(
20
20
  token: ReadonlySelectorToken<T>,
21
21
  store: Store,
22
- ): ReadonlySelector<T> | null
22
+ ): ReadonlySelector<T> | undefined
23
23
  export function withdrawNewFamilyMember<T>(
24
24
  token: StateToken<T>,
25
25
  store: Store,
26
- ): Atom<T> | Selector<T> | null
26
+ ): Atom<T> | Selector<T> | undefined
27
27
  export function withdrawNewFamilyMember<T>(
28
28
  token: ReadonlySelectorToken<T> | StateToken<T>,
29
29
  store: Store,
30
- ): Atom<T> | ReadonlySelector<T> | Selector<T> | null
30
+ ): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined
31
31
  export function withdrawNewFamilyMember<T>(
32
32
  token:
33
33
  | AtomToken<T>
@@ -35,7 +35,7 @@ export function withdrawNewFamilyMember<T>(
35
35
  | SelectorToken<T>
36
36
  | StateToken<T>,
37
37
  store: Store,
38
- ): Atom<T> | ReadonlySelector<T> | Selector<T> | null {
38
+ ): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined {
39
39
  store.config.logger?.info(
40
40
  `👪 creating new family member "${token.key}" in store "${store.config.name}"`,
41
41
  )
@@ -49,5 +49,5 @@ export function withdrawNewFamilyMember<T>(
49
49
  return state
50
50
  }
51
51
  }
52
- return null
52
+ return undefined
53
53
  }
@@ -16,28 +16,34 @@ import type { Transaction } from "../transaction"
16
16
  import { target } from "../transaction"
17
17
  import type { Store } from "./store"
18
18
 
19
- export function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | null
19
+ export function withdraw<T>(
20
+ token: AtomToken<T>,
21
+ store: Store,
22
+ ): Atom<T> | undefined
20
23
  export function withdraw<T>(
21
24
  token: SelectorToken<T>,
22
25
  store: Store,
23
- ): Selector<T> | null
26
+ ): Selector<T> | undefined
24
27
  export function withdraw<T>(
25
28
  token: StateToken<T>,
26
29
  store: Store,
27
- ): Atom<T> | Selector<T> | null
30
+ ): Atom<T> | Selector<T> | undefined
28
31
  export function withdraw<T>(
29
32
  token: ReadonlySelectorToken<T>,
30
33
  store: Store,
31
- ): ReadonlySelector<T> | null
34
+ ): ReadonlySelector<T> | undefined
32
35
  export function withdraw<T>(
33
36
  token: TransactionToken<T>,
34
37
  store: Store,
35
- ): Transaction<T extends ƒn ? T : never> | null
38
+ ): Transaction<T extends ƒn ? T : never> | undefined
36
39
  export function withdraw<T>(
37
40
  token: ReadonlySelectorToken<T> | StateToken<T>,
38
41
  store: Store,
39
- ): Atom<T> | ReadonlySelector<T> | Selector<T> | null
40
- export function withdraw<T>(token: TimelineToken, store: Store): Timeline | null
42
+ ): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined
43
+ export function withdraw<T>(
44
+ token: TimelineToken,
45
+ store: Store,
46
+ ): Timeline | undefined
41
47
  export function withdraw<T>(
42
48
  token:
43
49
  | ReadonlySelectorToken<T>
@@ -51,7 +57,7 @@ export function withdraw<T>(
51
57
  | Selector<T>
52
58
  | Timeline
53
59
  | Transaction<T extends ƒn ? T : never>
54
- | null {
60
+ | undefined {
55
61
  let core = target(store)
56
62
  let state =
57
63
  core.atoms.get(token.key) ??
@@ -109,5 +115,5 @@ export function withdraw<T>(
109
115
  return state
110
116
  }
111
117
  }
112
- return null
118
+ return undefined
113
119
  }
@@ -14,7 +14,7 @@ export const subscribeToRootAtoms = <T>(
14
14
  ? null
15
15
  : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
16
16
  const atom = withdraw(atomToken, store)
17
- if (atom === null) {
17
+ if (atom === undefined) {
18
18
  throw new Error(
19
19
  `Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`,
20
20
  )
@@ -15,7 +15,7 @@ export const addAtomToTimeline = (
15
15
  store: Store = IMPLICIT.STORE,
16
16
  ): void => {
17
17
  const atom = withdraw(atomToken, store)
18
- if (atom === null) {
18
+ if (atom === undefined) {
19
19
  throw new Error(
20
20
  `Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`,
21
21
  )
@@ -67,7 +67,7 @@ export const addAtomToTimeline = (
67
67
  { key: currentTransactionKey, type: `transaction` },
68
68
  store,
69
69
  )
70
- if (currentTransaction === null) {
70
+ if (currentTransaction === undefined) {
71
71
  throw new Error(
72
72
  `Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`,
73
73
  )
@@ -48,7 +48,7 @@ export const applyTransaction = <ƒ extends ƒn>(
48
48
  { key: store.transactionStatus.key, type: `transaction` },
49
49
  store,
50
50
  )
51
- if (myTransaction === null) {
51
+ if (myTransaction === undefined) {
52
52
  throw new Error(
53
53
  `Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`,
54
54
  )
@@ -12,7 +12,7 @@ export const redoTransactionUpdate = <ƒ extends ƒn>(
12
12
  for (const { key, newValue } of update.atomUpdates) {
13
13
  const token: AtomToken<unknown> = { key, type: `atom` }
14
14
  const state = withdraw(token, store)
15
- if (state === null) {
15
+ if (state === undefined) {
16
16
  throw new Error(
17
17
  `State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`,
18
18
  )
@@ -12,7 +12,7 @@ export const undoTransactionUpdate = <ƒ extends ƒn>(
12
12
  for (const { key, oldValue } of update.atomUpdates) {
13
13
  const token: AtomToken<unknown> = { key, type: `atom` }
14
14
  const state = withdraw(token, store)
15
- if (state === null) {
15
+ if (state === undefined) {
16
16
  throw new Error(
17
17
  `State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`,
18
18
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Reactive state graph for React, Preact, and vanilla",
5
5
  "peerDependencies": {
6
6
  "@floating-ui/react": ">=0.25.0",
@@ -38,13 +38,13 @@
38
38
  "@emotion/react": "11.11.1",
39
39
  "@testing-library/react": "14.0.0",
40
40
  "@types/mock-fs": "4.13.2",
41
- "@types/react": "18.2.25",
41
+ "@types/react": "18.2.28",
42
42
  "@types/tmp": "0.2.4",
43
43
  "@vitest/coverage-v8": "0.34.6",
44
44
  "concurrently": "8.2.1",
45
- "eslint": "8.50.0",
45
+ "eslint": "8.51.0",
46
46
  "framer-motion": "10.16.4",
47
- "happy-dom": "12.8.0",
47
+ "happy-dom": "12.9.1",
48
48
  "preact": "10.18.1",
49
49
  "react": "18.2.0",
50
50
  "react-dom": "18.2.0",
@@ -78,9 +78,12 @@
78
78
  "react-devtools/dist",
79
79
  "react-devtools/package.json",
80
80
  "react-devtools/src",
81
- "realtime/dist",
82
- "realtime/package.json",
83
- "realtime/src",
81
+ "realtime-client/dist",
82
+ "realtime-client/package.json",
83
+ "realtime-client/src",
84
+ "realtime-server/dist",
85
+ "realtime-server/package.json",
86
+ "realtime-server/src",
84
87
  "realtime-react/dist",
85
88
  "realtime-react/package.json",
86
89
  "realtime-react/src",
@@ -198,6 +201,6 @@
198
201
  "lint:eslint": "eslint .",
199
202
  "lint": "npm run lint:biome && npm run lint:eslint",
200
203
  "test": "vitest",
201
- "test:once": "cross-env LIB=dist vitest run"
204
+ "test:once": "cross-env IMPORT=dist vitest run"
202
205
  }
203
206
  }
@@ -1,5 +1,5 @@
1
1
  import * as atom_io from 'atom.io';
2
- import { FamilyMetadata, ƒn, TransactionUpdate, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, Logger } from 'atom.io';
2
+ import { FamilyMetadata, ƒn, TransactionUpdate, MutableAtomToken, AtomToken, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, Logger } from 'atom.io';
3
3
  import { Json } from 'atom.io/json';
4
4
 
5
5
  type ClassSignature = abstract new (...args: any) => any;
@@ -156,9 +156,9 @@ declare class Tracker<Mutable extends Transceiver<any>> {
156
156
  private unsubscribeFromInnerValue;
157
157
  private observeCore;
158
158
  private updateCore;
159
- mutableState: atom_io.MutableAtomToken<Mutable, Json.Serializable>;
160
- latestUpdateState: atom_io.AtomToken<typeof this$1.Update | null>;
161
- constructor(mutableState: atom_io.MutableAtomToken<Mutable, Json.Serializable>, store?: Store);
159
+ mutableState: MutableAtomToken<Mutable, Json.Serializable>;
160
+ latestUpdateState: AtomToken<typeof this$1.Update | null>;
161
+ constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store?: Store);
162
162
  }
163
163
 
164
164
  interface MutableAtom<T> extends Atom<T> {
@@ -1,5 +1,5 @@
1
1
  import * as atom_io from 'atom.io';
2
- import { FamilyMetadata, ƒn, TransactionUpdate, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, Logger } from 'atom.io';
2
+ import { FamilyMetadata, ƒn, TransactionUpdate, MutableAtomToken, AtomToken, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, Logger } from 'atom.io';
3
3
  import { Json } from 'atom.io/json';
4
4
 
5
5
  type ClassSignature = abstract new (...args: any) => any;
@@ -156,9 +156,9 @@ declare class Tracker<Mutable extends Transceiver<any>> {
156
156
  private unsubscribeFromInnerValue;
157
157
  private observeCore;
158
158
  private updateCore;
159
- mutableState: atom_io.MutableAtomToken<Mutable, Json.Serializable>;
160
- latestUpdateState: atom_io.AtomToken<typeof this$1.Update | null>;
161
- constructor(mutableState: atom_io.MutableAtomToken<Mutable, Json.Serializable>, store?: Store);
159
+ mutableState: MutableAtomToken<Mutable, Json.Serializable>;
160
+ latestUpdateState: AtomToken<typeof this$1.Update | null>;
161
+ constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store?: Store);
162
162
  }
163
163
 
164
164
  interface MutableAtom<T> extends Atom<T> {
@@ -1784,9 +1784,9 @@ var StringEditor = ({
1784
1784
  ) });
1785
1785
  };
1786
1786
  var DefaultFallback = ({ error, errorInfo }) => {
1787
- var _a2, _b;
1788
- const component = errorInfo == null ? void 0 : errorInfo.componentStack.split(` `).filter(Boolean)[2];
1789
- const message = (_b = (_a2 = error == null ? void 0 : error.toString()) != null ? _a2 : errorInfo == null ? void 0 : errorInfo.componentStack) != null ? _b : `Unknown error`;
1787
+ var _a2, _b, _c;
1788
+ const component = (_a2 = errorInfo == null ? void 0 : errorInfo.componentStack) == null ? void 0 : _a2.split(` `).filter(Boolean)[2];
1789
+ const message = (_c = (_b = error == null ? void 0 : error.toString()) != null ? _b : errorInfo == null ? void 0 : errorInfo.componentStack) != null ? _c : `Unknown error`;
1790
1790
  return /* @__PURE__ */ jsxRuntime.jsx(
1791
1791
  "div",
1792
1792
  {