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.
- package/dist/index.d.mts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +67 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -38
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +27 -33
- package/internal/dist/index.d.ts +27 -33
- package/internal/dist/index.js +45 -69
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +34 -39
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/caching.ts +12 -5
- package/internal/src/future.ts +2 -4
- package/internal/src/mutable/create-mutable-atom-family.ts +4 -4
- package/internal/src/mutable/create-mutable-atom.ts +6 -5
- package/internal/src/mutable/is-atom-token-mutable.ts +3 -3
- package/internal/src/mutable/tracker-family.ts +4 -4
- package/internal/src/mutable/tracker.ts +20 -19
- package/internal/src/operation.ts +5 -2
- package/internal/src/selector/create-read-write-selector.ts +2 -2
- package/internal/src/selector/register-selector.ts +2 -2
- package/internal/src/set-state/{set-atom-state.ts → set-atom.ts} +1 -1
- package/internal/src/set-state/set-selector-state.ts +1 -12
- package/internal/src/set-state/set-state-internal.ts +4 -5
- package/internal/src/store/withdraw-new-family-member.ts +7 -7
- package/internal/src/store/withdraw.ts +15 -9
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +1 -1
- package/internal/src/transaction/redo-transaction.ts +1 -1
- package/internal/src/transaction/undo-transaction.ts +1 -1
- package/package.json +11 -8
- package/react-devtools/dist/index.d.mts +4 -4
- package/react-devtools/dist/index.d.ts +4 -4
- package/react-devtools/dist/index.js +3 -3
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +3 -3
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime-client/dist/index.d.mts +21 -0
- package/realtime-client/dist/index.d.ts +21 -0
- package/realtime-client/dist/index.js +173 -0
- package/realtime-client/dist/index.js.map +1 -0
- package/realtime-client/dist/index.mjs +144 -0
- package/realtime-client/dist/index.mjs.map +1 -0
- package/realtime-client/package.json +15 -0
- package/realtime-client/src/index.ts +7 -0
- package/realtime-client/src/realtime-state.ts +10 -0
- package/realtime-client/src/use-pull-family-member.ts +26 -0
- package/realtime-client/src/use-pull-mutable-family-member.ts +38 -0
- package/realtime-client/src/use-pull-mutable.ts +32 -0
- package/realtime-client/src/use-pull.ts +19 -0
- package/realtime-client/src/use-push.ts +25 -0
- package/realtime-client/src/use-server-action.ts +49 -0
- package/realtime-server/dist/index.d.mts +25 -0
- package/realtime-server/dist/index.d.ts +25 -0
- package/realtime-server/dist/index.js +316 -0
- package/realtime-server/dist/index.js.map +1 -0
- package/realtime-server/dist/index.mjs +289 -0
- package/realtime-server/dist/index.mjs.map +1 -0
- package/realtime-server/package.json +15 -0
- package/realtime-server/src/README.md +33 -0
- package/realtime-server/src/hook-composition/expose-family.ts +105 -0
- package/realtime-server/src/hook-composition/expose-mutable-family.ts +127 -0
- package/realtime-server/src/hook-composition/expose-mutable.ts +45 -0
- package/realtime-server/src/hook-composition/expose-single.ts +39 -0
- package/realtime-server/src/hook-composition/index.ts +14 -0
- package/realtime-server/src/hook-composition/receive-state.ts +30 -0
- package/realtime-server/src/hook-composition/receive-transaction.ts +37 -0
- package/realtime-server/src/index.ts +1 -0
- package/src/get-set.ts +48 -0
- package/src/index.ts +3 -60
- package/src/subscribe.ts +3 -3
package/internal/src/caching.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StateUpdate } from "
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
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
|
}
|
package/internal/src/future.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
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
|
|
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:
|
|
15
|
+
options: MutableAtomFamilyOptions<Core, SerializableCore, Key>,
|
|
16
16
|
store: Store = IMPLICIT.STORE,
|
|
17
|
-
):
|
|
17
|
+
): MutableAtomFamily<Core, SerializableCore, Key> {
|
|
18
18
|
const coreFamily = Object.assign(
|
|
19
19
|
createAtomFamily<Core, Key>(options, store),
|
|
20
20
|
options,
|
|
21
|
-
) as
|
|
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
|
|
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:
|
|
17
|
+
options: MutableAtomOptions<Core, SerializableCore>,
|
|
17
18
|
store: Store = IMPLICIT.STORE,
|
|
18
|
-
):
|
|
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
|
-
|
|
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
|
|
49
|
+
return coreState as MutableAtomToken<Core, SerializableCore>
|
|
49
50
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { AtomToken, MutableAtomToken } from "atom.io"
|
|
2
2
|
|
|
3
3
|
export function isAtomTokenMutable(
|
|
4
|
-
token:
|
|
5
|
-
): token is
|
|
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
|
|
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:
|
|
19
|
+
public readonly findLatestUpdateState: AtomFamily<
|
|
20
20
|
typeof this.Update | null,
|
|
21
21
|
FamilyMemberKey
|
|
22
22
|
>
|
|
23
|
-
public readonly findMutableState:
|
|
23
|
+
public readonly findMutableState: AtomFamily<Core, FamilyMemberKey>
|
|
24
24
|
|
|
25
25
|
public constructor(
|
|
26
|
-
findMutableState:
|
|
26
|
+
findMutableState: AtomFamily<Core, FamilyMemberKey>,
|
|
27
27
|
store: Store = IMPLICIT.STORE,
|
|
28
28
|
) {
|
|
29
29
|
this.findLatestUpdateState = createAtomFamily<
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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:
|
|
20
|
+
mutableState: MutableAtomToken<Mutable, Json.Serializable>,
|
|
20
21
|
store: Store = IMPLICIT.STORE,
|
|
21
|
-
):
|
|
22
|
+
): AtomToken<typeof this.Update | null> {
|
|
22
23
|
const latestUpdateStateKey = `*${mutableState.key}`
|
|
23
24
|
deleteAtom(latestUpdateStateKey, target(store))
|
|
24
|
-
const familyMetaData:
|
|
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:
|
|
47
|
-
latestUpdateState:
|
|
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 =
|
|
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
|
-
|
|
63
|
+
setState(latestUpdateState, update, store)
|
|
63
64
|
},
|
|
64
65
|
)
|
|
65
66
|
},
|
|
66
67
|
)
|
|
67
|
-
|
|
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
|
-
|
|
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:
|
|
97
|
-
latestUpdateState:
|
|
97
|
+
mutableState: MutableAtomToken<Core, Json.Serializable>,
|
|
98
|
+
latestUpdateState: AtomToken<typeof this.Update | null>,
|
|
98
99
|
store: Store = IMPLICIT.STORE,
|
|
99
100
|
): void {
|
|
100
|
-
|
|
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 =
|
|
110
|
+
const unsubscribe = subscribeToTimeline(
|
|
110
111
|
{ key: timelineId, type: `timeline` },
|
|
111
112
|
(update) => {
|
|
112
113
|
unsubscribe()
|
|
113
|
-
|
|
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
|
-
|
|
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:
|
|
151
|
-
public latestUpdateState:
|
|
151
|
+
public mutableState: MutableAtomToken<Mutable, Json.Serializable>
|
|
152
|
+
public latestUpdateState: AtomToken<typeof this.Update | null>
|
|
152
153
|
|
|
153
154
|
public constructor(
|
|
154
|
-
mutableState:
|
|
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 = (
|
|
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
|
-
|
|
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
|
-
|
|
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 ===
|
|
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 ===
|
|
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
|
|
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
|
-
|
|
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 {
|
|
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 (`
|
|
14
|
-
|
|
12
|
+
if (state.type === `selector`) {
|
|
13
|
+
state.set(value)
|
|
15
14
|
} else {
|
|
16
|
-
|
|
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> |
|
|
14
|
+
): Atom<T> | undefined
|
|
15
15
|
export function withdrawNewFamilyMember<T>(
|
|
16
16
|
token: SelectorToken<T>,
|
|
17
17
|
store: Store,
|
|
18
|
-
): Selector<T> |
|
|
18
|
+
): Selector<T> | undefined
|
|
19
19
|
export function withdrawNewFamilyMember<T>(
|
|
20
20
|
token: ReadonlySelectorToken<T>,
|
|
21
21
|
store: Store,
|
|
22
|
-
): ReadonlySelector<T> |
|
|
22
|
+
): ReadonlySelector<T> | undefined
|
|
23
23
|
export function withdrawNewFamilyMember<T>(
|
|
24
24
|
token: StateToken<T>,
|
|
25
25
|
store: Store,
|
|
26
|
-
): Atom<T> | Selector<T> |
|
|
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> |
|
|
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> |
|
|
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
|
|
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>(
|
|
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> |
|
|
26
|
+
): Selector<T> | undefined
|
|
24
27
|
export function withdraw<T>(
|
|
25
28
|
token: StateToken<T>,
|
|
26
29
|
store: Store,
|
|
27
|
-
): Atom<T> | Selector<T> |
|
|
30
|
+
): Atom<T> | Selector<T> | undefined
|
|
28
31
|
export function withdraw<T>(
|
|
29
32
|
token: ReadonlySelectorToken<T>,
|
|
30
33
|
store: Store,
|
|
31
|
-
): ReadonlySelector<T> |
|
|
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> |
|
|
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> |
|
|
40
|
-
export function withdraw<T>(
|
|
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
|
-
|
|
|
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
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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.
|
|
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.
|
|
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.
|
|
45
|
+
"eslint": "8.51.0",
|
|
46
46
|
"framer-motion": "10.16.4",
|
|
47
|
-
"happy-dom": "12.
|
|
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
|
|
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,
|
|
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:
|
|
160
|
-
latestUpdateState:
|
|
161
|
-
constructor(mutableState:
|
|
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,
|
|
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:
|
|
160
|
-
latestUpdateState:
|
|
161
|
-
constructor(mutableState:
|
|
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 = (
|
|
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
|
{
|