atom.io 0.18.1 → 0.18.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/chunk-3J2EGSBE.js +31 -0
- package/dist/chunk-3J2EGSBE.js.map +1 -0
- package/dist/{chunk-JDUNWJFB.js → chunk-A4ZCNKWQ.js} +2 -2
- package/dist/chunk-A4ZCNKWQ.js.map +1 -0
- package/internal/dist/index.cjs +46 -100
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +23 -23
- package/internal/dist/index.js +46 -100
- package/internal/dist/index.js.map +1 -1
- package/internal/src/families/create-regular-atom-family.ts +4 -4
- package/internal/src/get-state/get-from-store.ts +2 -5
- package/internal/src/mutable/create-mutable-atom-family.ts +4 -4
- package/internal/src/selector/register-selector.ts +3 -14
- package/internal/src/set-state/set-into-store.ts +2 -5
- package/internal/src/store/withdraw-new-family-member.ts +38 -28
- package/internal/src/store/withdraw.ts +20 -23
- package/internal/src/subscribe/subscribe-to-state.ts +2 -3
- package/internal/src/subscribe/subscribe-to-timeline.ts +0 -5
- package/internal/src/subscribe/subscribe-to-transaction.ts +0 -5
- package/internal/src/timeline/add-atom-to-timeline.ts +6 -15
- package/internal/src/timeline/create-timeline.ts +0 -27
- package/package.json +6 -5
- package/react/dist/index.cjs +2 -3
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.js +2 -3
- package/react/dist/index.js.map +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.cjs +1 -1
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.js +1 -1
- package/realtime-client/dist/index.cjs +1 -1
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.js +13 -37
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-server/dist/index.cjs +3 -3
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.js +3 -3
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/ipc-sockets/parent-socket.ts +4 -3
- package/realtime-testing/dist/index.cjs +43 -5
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.js +4 -5
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +3 -5
- package/dist/chunk-JDUNWJFB.js.map +0 -1
|
@@ -10,7 +10,6 @@ import { stringifyJson } from "atom.io/json"
|
|
|
10
10
|
|
|
11
11
|
import { createRegularAtom } from "../atom"
|
|
12
12
|
import { newest } from "../lineage"
|
|
13
|
-
import { deposit, withdraw } from "../store"
|
|
14
13
|
import type { Store } from "../store"
|
|
15
14
|
import { Subject } from "../subject"
|
|
16
15
|
|
|
@@ -24,10 +23,11 @@ export function createRegularAtomFamily<T, K extends Json.Serializable>(
|
|
|
24
23
|
const subKey = stringifyJson(key)
|
|
25
24
|
const family: FamilyMetadata = { key: options.key, subKey }
|
|
26
25
|
const fullKey = `${options.key}(${subKey})`
|
|
27
|
-
const
|
|
26
|
+
const target = newest(store)
|
|
27
|
+
const atomAlreadyCreated = target.atoms.has(fullKey)
|
|
28
28
|
let token: RegularAtomToken<any>
|
|
29
|
-
if (
|
|
30
|
-
token =
|
|
29
|
+
if (atomAlreadyCreated) {
|
|
30
|
+
token = { type: `atom`, key: fullKey, family }
|
|
31
31
|
} else {
|
|
32
32
|
const individualOptions: RegularAtomOptions<any> = {
|
|
33
33
|
key: fullKey,
|
|
@@ -2,13 +2,10 @@ import type { ReadableToken } from "atom.io"
|
|
|
2
2
|
|
|
3
3
|
import { NotFoundError } from "../not-found-error"
|
|
4
4
|
import type { Store } from "../store"
|
|
5
|
-
import { withdraw,
|
|
5
|
+
import { withdraw, withdrawOrCreate } from "../store"
|
|
6
6
|
import { readOrComputeValue } from "./read-or-compute-value"
|
|
7
7
|
|
|
8
8
|
export function getFromStore<T>(token: ReadableToken<T>, store: Store): T {
|
|
9
|
-
const state =
|
|
10
|
-
if (state === undefined) {
|
|
11
|
-
throw new NotFoundError(token, store)
|
|
12
|
-
}
|
|
9
|
+
const state = withdrawOrCreate(token, store)
|
|
13
10
|
return readOrComputeValue(state, store)
|
|
14
11
|
}
|
|
@@ -11,7 +11,6 @@ import { stringifyJson } from "atom.io/json"
|
|
|
11
11
|
|
|
12
12
|
import { newest } from "../lineage"
|
|
13
13
|
import { createMutableAtom } from "../mutable"
|
|
14
|
-
import { deposit, withdraw } from "../store"
|
|
15
14
|
import type { Store } from "../store"
|
|
16
15
|
import { Subject } from "../subject"
|
|
17
16
|
import { FamilyTracker } from "./tracker-family"
|
|
@@ -31,10 +30,11 @@ export function createMutableAtomFamily<
|
|
|
31
30
|
const subKey = stringifyJson(key)
|
|
32
31
|
const family: FamilyMetadata = { key: options.key, subKey }
|
|
33
32
|
const fullKey = `${options.key}(${subKey})`
|
|
34
|
-
const
|
|
33
|
+
const target = newest(store)
|
|
34
|
+
const atomAlreadyCreated = target.atoms.has(fullKey)
|
|
35
35
|
let token: MutableAtomToken<T, J>
|
|
36
|
-
if (
|
|
37
|
-
token =
|
|
36
|
+
if (atomAlreadyCreated) {
|
|
37
|
+
token = { type: `mutable_atom`, key: fullKey, family }
|
|
38
38
|
} else {
|
|
39
39
|
const individualOptions: MutableAtomOptions<T, J> = {
|
|
40
40
|
key: fullKey,
|
|
@@ -5,7 +5,7 @@ import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
|
5
5
|
import { newest } from "../lineage"
|
|
6
6
|
import { setAtomOrSelector } from "../set-state"
|
|
7
7
|
import type { Store } from "../store"
|
|
8
|
-
import {
|
|
8
|
+
import { withdrawOrCreate } from "../store"
|
|
9
9
|
import { updateSelectorAtoms } from "./update-selector-atoms"
|
|
10
10
|
|
|
11
11
|
export const registerSelector = (
|
|
@@ -15,13 +15,7 @@ export const registerSelector = (
|
|
|
15
15
|
get: (dependency) => {
|
|
16
16
|
const target = newest(store)
|
|
17
17
|
|
|
18
|
-
const dependencyState =
|
|
19
|
-
withdraw(dependency, store) ?? withdrawNewFamilyMember(dependency, store)
|
|
20
|
-
if (dependencyState === undefined) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
`State "${dependency.key}" not found in store "${store.config.name}".`,
|
|
23
|
-
)
|
|
24
|
-
}
|
|
18
|
+
const dependencyState = withdrawOrCreate(dependency, store)
|
|
25
19
|
const dependencyValue = readOrComputeValue(dependencyState, store)
|
|
26
20
|
|
|
27
21
|
store.logger.info(
|
|
@@ -46,12 +40,7 @@ export const registerSelector = (
|
|
|
46
40
|
return dependencyValue
|
|
47
41
|
},
|
|
48
42
|
set: (WritableToken, newValue) => {
|
|
49
|
-
const state =
|
|
50
|
-
if (state === undefined) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`State "${WritableToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
43
|
+
const state = withdrawOrCreate(WritableToken, store)
|
|
55
44
|
setAtomOrSelector(state, newValue, store)
|
|
56
45
|
},
|
|
57
46
|
find: ((token, key) => findInStore(token, key, store)) as typeof findState,
|
|
@@ -3,7 +3,7 @@ import type { WritableToken } from "atom.io"
|
|
|
3
3
|
import { NotFoundError } from "../not-found-error"
|
|
4
4
|
import { closeOperation, openOperation } from "../operation"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
|
-
import {
|
|
6
|
+
import { withdrawOrCreate } from "../store"
|
|
7
7
|
import { setAtomOrSelector } from "./set-atom-or-selector"
|
|
8
8
|
|
|
9
9
|
export function setIntoStore<T, New extends T>(
|
|
@@ -15,10 +15,7 @@ export function setIntoStore<T, New extends T>(
|
|
|
15
15
|
if (rejection) {
|
|
16
16
|
return
|
|
17
17
|
}
|
|
18
|
-
const state =
|
|
19
|
-
if (state === undefined) {
|
|
20
|
-
throw new NotFoundError(token, store)
|
|
21
|
-
}
|
|
18
|
+
const state = withdrawOrCreate(token, store)
|
|
22
19
|
setAtomOrSelector(state, value, store)
|
|
23
20
|
closeOperation(store)
|
|
24
21
|
}
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
WritableSelectorToken,
|
|
6
6
|
WritableToken,
|
|
7
7
|
} from "atom.io"
|
|
8
|
+
|
|
8
9
|
import type {
|
|
9
10
|
Atom,
|
|
10
11
|
ReadableState,
|
|
@@ -13,47 +14,56 @@ import type {
|
|
|
13
14
|
WritableSelector,
|
|
14
15
|
WritableState,
|
|
15
16
|
} from ".."
|
|
16
|
-
import { newest, withdraw } from ".."
|
|
17
|
+
import { NotFoundError, newest, withdraw } from ".."
|
|
17
18
|
|
|
18
|
-
export function
|
|
19
|
+
export function withdrawOrCreate<T>(
|
|
19
20
|
token: RegularAtomToken<T>,
|
|
20
21
|
store: Store,
|
|
21
|
-
): Atom<T>
|
|
22
|
-
export function
|
|
22
|
+
): Atom<T>
|
|
23
|
+
export function withdrawOrCreate<T>(
|
|
23
24
|
token: WritableSelectorToken<T>,
|
|
24
25
|
store: Store,
|
|
25
|
-
): WritableSelector<T>
|
|
26
|
-
export function
|
|
26
|
+
): WritableSelector<T>
|
|
27
|
+
export function withdrawOrCreate<T>(
|
|
27
28
|
token: ReadonlySelectorToken<T>,
|
|
28
29
|
store: Store,
|
|
29
|
-
): ReadonlySelector<T>
|
|
30
|
-
export function
|
|
30
|
+
): ReadonlySelector<T>
|
|
31
|
+
export function withdrawOrCreate<T>(
|
|
31
32
|
token: WritableToken<T>,
|
|
32
33
|
store: Store,
|
|
33
|
-
): WritableState<T>
|
|
34
|
-
export function
|
|
34
|
+
): WritableState<T>
|
|
35
|
+
export function withdrawOrCreate<T>(
|
|
35
36
|
token: ReadableToken<T>,
|
|
36
37
|
store: Store,
|
|
37
|
-
): ReadableState<T>
|
|
38
|
-
export function
|
|
38
|
+
): ReadableState<T>
|
|
39
|
+
export function withdrawOrCreate<T>(
|
|
39
40
|
token: ReadableToken<T>,
|
|
40
41
|
store: Store,
|
|
41
|
-
): ReadableState<T>
|
|
42
|
-
|
|
43
|
-
store
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
42
|
+
): ReadableState<T> {
|
|
43
|
+
try {
|
|
44
|
+
const state = withdraw(token, store)
|
|
45
|
+
return state
|
|
46
|
+
} catch (notFoundError) {
|
|
47
|
+
if (token.family) {
|
|
48
|
+
store.logger.info(
|
|
49
|
+
`👪`,
|
|
50
|
+
token.type,
|
|
51
|
+
token.key,
|
|
52
|
+
`creating new family member in store "${store.config.name}"`,
|
|
53
|
+
)
|
|
54
|
+
const target = newest(store)
|
|
55
|
+
const family = target.families.get(token.family.key)
|
|
56
|
+
if (family) {
|
|
57
|
+
const jsonSubKey = JSON.parse(token.family.subKey)
|
|
58
|
+
family(jsonSubKey)
|
|
59
|
+
const state = withdraw(token, store)
|
|
60
|
+
return state
|
|
61
|
+
}
|
|
62
|
+
throw new NotFoundError(
|
|
63
|
+
{ key: token.family.key, type: `${token.type}_family` },
|
|
64
|
+
store,
|
|
65
|
+
)
|
|
56
66
|
}
|
|
67
|
+
throw notFoundError
|
|
57
68
|
}
|
|
58
|
-
return undefined
|
|
59
69
|
}
|
|
@@ -37,6 +37,8 @@ import type {
|
|
|
37
37
|
WritableSelector,
|
|
38
38
|
WritableState,
|
|
39
39
|
} from ".."
|
|
40
|
+
import { NotFoundError } from ".."
|
|
41
|
+
|
|
40
42
|
import type { Timeline } from "../timeline"
|
|
41
43
|
import type { Transaction } from "../transaction"
|
|
42
44
|
import type { Store } from "./store"
|
|
@@ -63,40 +65,34 @@ export type Withdrawable =
|
|
|
63
65
|
export function withdraw<T>(
|
|
64
66
|
token: RegularAtomToken<T>,
|
|
65
67
|
store: Store,
|
|
66
|
-
): RegularAtom<T>
|
|
68
|
+
): RegularAtom<T>
|
|
67
69
|
export function withdraw<T extends Transceiver<any>>(
|
|
68
70
|
token: MutableAtomToken<T, any>,
|
|
69
71
|
store: Store,
|
|
70
|
-
): MutableAtom<T, any>
|
|
71
|
-
export function withdraw<T>(
|
|
72
|
-
token: AtomToken<T>,
|
|
73
|
-
store: Store,
|
|
74
|
-
): Atom<T> | undefined
|
|
72
|
+
): MutableAtom<T, any>
|
|
73
|
+
export function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>
|
|
75
74
|
export function withdraw<T>(
|
|
76
75
|
token: WritableSelectorToken<T>,
|
|
77
76
|
store: Store,
|
|
78
|
-
): WritableSelector<T>
|
|
77
|
+
): WritableSelector<T>
|
|
79
78
|
export function withdraw<T>(
|
|
80
79
|
token: ReadonlySelectorToken<T>,
|
|
81
80
|
store: Store,
|
|
82
|
-
): ReadonlySelector<T>
|
|
83
|
-
export function withdraw<T>(
|
|
84
|
-
token: SelectorToken<T>,
|
|
85
|
-
store: Store,
|
|
86
|
-
): Selector<T> | undefined
|
|
81
|
+
): ReadonlySelector<T>
|
|
82
|
+
export function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>
|
|
87
83
|
export function withdraw<T>(
|
|
88
84
|
token: WritableToken<T>,
|
|
89
85
|
store: Store,
|
|
90
|
-
): WritableState<T>
|
|
86
|
+
): WritableState<T>
|
|
91
87
|
export function withdraw<T>(
|
|
92
88
|
token: ReadableToken<T>,
|
|
93
89
|
store: Store,
|
|
94
|
-
): ReadableState<T>
|
|
90
|
+
): ReadableState<T>
|
|
95
91
|
|
|
96
92
|
export function withdraw<T, K extends Json.Serializable>(
|
|
97
93
|
token: RegularAtomFamilyToken<T, K>,
|
|
98
94
|
store: Store,
|
|
99
|
-
): RegularAtomFamily<T, K>
|
|
95
|
+
): RegularAtomFamily<T, K>
|
|
100
96
|
export function withdraw<
|
|
101
97
|
T extends Transceiver<any>,
|
|
102
98
|
J extends Json.Serializable,
|
|
@@ -104,32 +100,32 @@ export function withdraw<
|
|
|
104
100
|
>(
|
|
105
101
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
106
102
|
store: Store,
|
|
107
|
-
): MutableAtomFamily<T, J, K>
|
|
103
|
+
): MutableAtomFamily<T, J, K>
|
|
108
104
|
export function withdraw<T, K extends Json.Serializable>(
|
|
109
105
|
token: AtomFamilyToken<T>,
|
|
110
106
|
store: Store,
|
|
111
|
-
): AtomFamily<T, any>
|
|
107
|
+
): AtomFamily<T, any>
|
|
112
108
|
export function withdraw<T, K extends Json.Serializable>(
|
|
113
109
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
114
110
|
store: Store,
|
|
115
|
-
): ReadonlySelectorFamily<T, any>
|
|
111
|
+
): ReadonlySelectorFamily<T, any>
|
|
116
112
|
export function withdraw<T, K extends Json.Serializable>(
|
|
117
113
|
token: WritableSelectorFamilyToken<T, K>,
|
|
118
114
|
store: Store,
|
|
119
|
-
): WritableSelectorFamily<T, any>
|
|
115
|
+
): WritableSelectorFamily<T, any>
|
|
120
116
|
export function withdraw<T, K extends Json.Serializable>(
|
|
121
117
|
token: SelectorFamilyToken<T, K>,
|
|
122
118
|
store: Store,
|
|
123
|
-
): SelectorFamily<T, any>
|
|
119
|
+
): SelectorFamily<T, any>
|
|
124
120
|
|
|
125
121
|
export function withdraw<T>(
|
|
126
122
|
token: TransactionToken<T>,
|
|
127
123
|
store: Store,
|
|
128
|
-
): Transaction<T extends ƒn ? T : never>
|
|
124
|
+
): Transaction<T extends ƒn ? T : never>
|
|
129
125
|
export function withdraw<T>(
|
|
130
126
|
token: TimelineToken<T>,
|
|
131
127
|
store: Store,
|
|
132
|
-
): Timeline<T extends TimelineManageable ? T : never>
|
|
128
|
+
): Timeline<T extends TimelineManageable ? T : never>
|
|
133
129
|
export function withdraw<T>(
|
|
134
130
|
token:
|
|
135
131
|
| RegularAtomFamilyToken<T, any>
|
|
@@ -142,7 +138,7 @@ export function withdraw<T>(
|
|
|
142
138
|
? MutableAtomFamilyToken<T, any, any> | MutableAtomToken<T, any>
|
|
143
139
|
: never),
|
|
144
140
|
store: Store,
|
|
145
|
-
): Withdrawable
|
|
141
|
+
): Withdrawable {
|
|
146
142
|
let withdrawn: Withdrawable | undefined
|
|
147
143
|
let target: Store | null = store
|
|
148
144
|
while (target !== null) {
|
|
@@ -175,4 +171,5 @@ export function withdraw<T>(
|
|
|
175
171
|
}
|
|
176
172
|
target = target.child
|
|
177
173
|
}
|
|
174
|
+
throw new NotFoundError(token, store)
|
|
178
175
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReadableToken, UpdateHandler } from "atom.io"
|
|
2
2
|
import type { Store } from "../store"
|
|
3
|
-
import {
|
|
3
|
+
import { withdrawOrCreate } from "../store"
|
|
4
4
|
import { subscribeToRootAtoms } from "./subscribe-to-root-atoms"
|
|
5
5
|
|
|
6
6
|
export function subscribeToState<T>(
|
|
@@ -9,8 +9,7 @@ export function subscribeToState<T>(
|
|
|
9
9
|
key: string,
|
|
10
10
|
store: Store,
|
|
11
11
|
): () => void {
|
|
12
|
-
const state =
|
|
13
|
-
withdraw<T>(token, store) ?? withdrawNewFamilyMember(token, store)
|
|
12
|
+
const state = withdrawOrCreate(token, store)
|
|
14
13
|
if (state === undefined) {
|
|
15
14
|
throw new Error(
|
|
16
15
|
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
@@ -9,11 +9,6 @@ export const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(
|
|
|
9
9
|
store: Store,
|
|
10
10
|
): (() => void) => {
|
|
11
11
|
const tl = withdraw(token, store)
|
|
12
|
-
if (tl === undefined) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`,
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
12
|
store.logger.info(`👀`, `timeline`, token.key, `Adding subscription "${key}"`)
|
|
18
13
|
const unsubscribe = tl.subject.subscribe(key, handleUpdate)
|
|
19
14
|
return () => {
|
|
@@ -9,11 +9,6 @@ export const subscribeToTransaction = <ƒ extends ƒn>(
|
|
|
9
9
|
store: Store,
|
|
10
10
|
): (() => void) => {
|
|
11
11
|
const tx = withdraw(token, store)
|
|
12
|
-
if (tx === undefined) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`,
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
12
|
store.logger.info(
|
|
18
13
|
`👀`,
|
|
19
14
|
`transaction`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AtomToken, TransactionUpdate, ƒn } from "atom.io"
|
|
1
|
+
import type { AtomToken, TransactionToken, TransactionUpdate, ƒn } from "atom.io"
|
|
2
2
|
import type { TimelineUpdate } from "atom.io"
|
|
3
3
|
|
|
4
4
|
import { newest } from "../lineage"
|
|
@@ -17,16 +17,11 @@ export const addAtomToTimeline = (
|
|
|
17
17
|
store: Store,
|
|
18
18
|
): void => {
|
|
19
19
|
let maybeAtom = withdraw(atomToken, store)
|
|
20
|
-
if (maybeAtom
|
|
20
|
+
if (maybeAtom.type === `mutable_atom`) {
|
|
21
21
|
const updateToken = getUpdateToken(maybeAtom)
|
|
22
22
|
maybeAtom = withdraw(updateToken, store)
|
|
23
23
|
}
|
|
24
24
|
const atom = maybeAtom
|
|
25
|
-
if (atom === undefined) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`,
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
25
|
store.timelineAtoms.set({ atomKey: atom.key, timelineKey: tl.key })
|
|
31
26
|
|
|
32
27
|
atom.subject.subscribe(`timeline`, (update) => {
|
|
@@ -70,15 +65,11 @@ export const addAtomToTimeline = (
|
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
67
|
if (currentTransactionKey) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
77
|
-
if (currentTransaction === undefined) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`,
|
|
80
|
-
)
|
|
68
|
+
const txToken: TransactionToken<any> = {
|
|
69
|
+
key: currentTransactionKey,
|
|
70
|
+
type: `transaction`,
|
|
81
71
|
}
|
|
72
|
+
const currentTransaction = withdraw(txToken, store)
|
|
82
73
|
if (tl.transactionKey !== currentTransactionKey) {
|
|
83
74
|
if (tl.transactionKey) {
|
|
84
75
|
store.logger.error(
|
|
@@ -89,15 +89,6 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
89
89
|
) {
|
|
90
90
|
const familyToken: AtomFamilyToken<any> = tokenOrFamily
|
|
91
91
|
const family = withdraw(familyToken, store)
|
|
92
|
-
if (family === undefined) {
|
|
93
|
-
store.logger.error(
|
|
94
|
-
`❌`,
|
|
95
|
-
`timeline`,
|
|
96
|
-
options.key,
|
|
97
|
-
`Failed to add family "${familyToken.key}" because it does not exist in the store`,
|
|
98
|
-
)
|
|
99
|
-
continue
|
|
100
|
-
}
|
|
101
92
|
const familyKey = family.key
|
|
102
93
|
target.timelineAtoms.set({ atomKey: familyKey, timelineKey })
|
|
103
94
|
family.subject.subscribe(`timeline:${options.key}`, (token) => {
|
|
@@ -110,26 +101,8 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
110
101
|
}
|
|
111
102
|
} else {
|
|
112
103
|
let atom = withdraw(tokenOrFamily, store)
|
|
113
|
-
if (atom === undefined) {
|
|
114
|
-
store.logger.error(
|
|
115
|
-
`❌`,
|
|
116
|
-
`timeline`,
|
|
117
|
-
options.key,
|
|
118
|
-
`Failed to add atom "${atomKey}" because it does not exist in the store`,
|
|
119
|
-
)
|
|
120
|
-
continue
|
|
121
|
-
}
|
|
122
104
|
if (isMutable(atom)) {
|
|
123
105
|
const updateAtom = withdraw(getUpdateToken(atom), store)
|
|
124
|
-
if (updateAtom === undefined) {
|
|
125
|
-
store.logger.error(
|
|
126
|
-
`❌`,
|
|
127
|
-
`timeline`,
|
|
128
|
-
options.key,
|
|
129
|
-
`Failed to add update atom "${atomKey}" because it does not exist in the store`,
|
|
130
|
-
)
|
|
131
|
-
continue
|
|
132
|
-
}
|
|
133
106
|
atom = updateAtom
|
|
134
107
|
atomKey = atom.key
|
|
135
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"test": "vitest",
|
|
40
40
|
"test:coverage": "vitest run --coverage",
|
|
41
41
|
"test:once": "bun run test:manifest && cross-env IMPORT=dist vitest run",
|
|
42
|
+
"test:once:public": "cross-env IMPORT=dist vitest run public",
|
|
42
43
|
"test:manifest": "tsx __scripts__/manifest-test.node"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"@testing-library/react": "14.2.1",
|
|
78
79
|
"@types/http-proxy": "1.17.14",
|
|
79
80
|
"@types/npmlog": "7.0.0",
|
|
80
|
-
"@types/react": "18.2.
|
|
81
|
+
"@types/react": "18.2.61",
|
|
81
82
|
"@types/tmp": "0.2.6",
|
|
82
83
|
"@vitest/coverage-v8": "1.3.1",
|
|
83
84
|
"@vitest/ui": "1.3.1",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
"drizzle-kit": "0.20.14",
|
|
86
87
|
"drizzle-orm": "0.29.4",
|
|
87
88
|
"eslint": "8.57.0",
|
|
88
|
-
"framer-motion": "11.0.
|
|
89
|
+
"framer-motion": "11.0.8",
|
|
89
90
|
"happy-dom": "13.6.2",
|
|
90
91
|
"http-proxy": "1.18.1",
|
|
91
92
|
"npmlog": "7.0.1",
|
|
@@ -93,10 +94,10 @@
|
|
|
93
94
|
"preact": "10.19.6",
|
|
94
95
|
"react": "18.2.0",
|
|
95
96
|
"react-dom": "18.2.0",
|
|
96
|
-
"react-router-dom": "6.22.
|
|
97
|
+
"react-router-dom": "6.22.2",
|
|
97
98
|
"socket.io": "4.7.4",
|
|
98
99
|
"socket.io-client": "4.7.4",
|
|
99
|
-
"tmp": "0.2.
|
|
100
|
+
"tmp": "0.2.3",
|
|
100
101
|
"tsup": "8.0.2",
|
|
101
102
|
"typescript": "5.3.3",
|
|
102
103
|
"vite": "5.1.4",
|
package/react/dist/index.cjs
CHANGED
|
@@ -61,10 +61,9 @@ function useTL(token) {
|
|
|
61
61
|
const timeline = internal.withdraw(token, store);
|
|
62
62
|
const tokenRef = React5__namespace.useRef(token);
|
|
63
63
|
const rebuildMeta = () => {
|
|
64
|
-
var _a, _b;
|
|
65
64
|
return {
|
|
66
|
-
at:
|
|
67
|
-
length:
|
|
65
|
+
at: timeline.at,
|
|
66
|
+
length: timeline.history.length,
|
|
68
67
|
undo: () => atom_io.undo(token),
|
|
69
68
|
redo: () => atom_io.redo(token)
|
|
70
69
|
};
|
package/react/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACThD,SAAS,aAAa,oBAAoB;AAE1C,YAAYA,YAAW;AAahB,SAAS,KACf,OACA,KACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,oBACZ,YAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,aAAa,YAAY,MAAM,KAAK;AAAA,EAChE;AACA,SAAO,OAAO;AACf;;;AC7BA,SAAS,eAAAC,cAAa,oBAAoB;AAE1C,YAAYD,YAAW;;;ACNvB,SAAS,eAAAC,cAAa,cAAc,wBAAwB;AAE5D,YAAYD,YAAW;AAWhB,SAAS,KACf,OACA,KACI;AACJ,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,qBACf,MAAM,SAAS,6BACZC,aAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,iBAAiB,YAAY,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IACzE,MAAM,aAAa,YAAY,KAAK;AAAA,IACpC,MAAM,aAAa,YAAY,KAAK;AAAA,EACrC;AACD;;;ADXO,SAAS,QAIf,OAGA,KACe;AACf,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,wBACZA,aAAY,OAAO,KAAY,KAAK,IACpC;AACJ,QAAM,YAAY,aAAa,UAAU;AACzC,SAAO,KAAK,SAAS;AACtB;;;AErCA,SAAS,MAAM,YAAY;AAE3B,SAAS,qBAAqB,gBAAgB;AAC9C,YAAYD,YAAW;AAWhB,SAAS,MAAM,OAAyC;AAC9D,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,QAAM,WAAW,SAAS,OAAO,KAAK;AACtC,QAAM,WAAiB,cAAO,KAAK;AACnC,QAAM,cAAc,MAAM;
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACThD,SAAS,aAAa,oBAAoB;AAE1C,YAAYA,YAAW;AAahB,SAAS,KACf,OACA,KACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,oBACZ,YAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,aAAa,YAAY,MAAM,KAAK;AAAA,EAChE;AACA,SAAO,OAAO;AACf;;;AC7BA,SAAS,eAAAC,cAAa,oBAAoB;AAE1C,YAAYD,YAAW;;;ACNvB,SAAS,eAAAC,cAAa,cAAc,wBAAwB;AAE5D,YAAYD,YAAW;AAWhB,SAAS,KACf,OACA,KACI;AACJ,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,qBACf,MAAM,SAAS,6BACZC,aAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,iBAAiB,YAAY,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IACzE,MAAM,aAAa,YAAY,KAAK;AAAA,IACpC,MAAM,aAAa,YAAY,KAAK;AAAA,EACrC;AACD;;;ADXO,SAAS,QAIf,OAGA,KACe;AACf,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,wBACZA,aAAY,OAAO,KAAY,KAAK,IACpC;AACJ,QAAM,YAAY,aAAa,UAAU;AACzC,SAAO,KAAK,SAAS;AACtB;;;AErCA,SAAS,MAAM,YAAY;AAE3B,SAAS,qBAAqB,gBAAgB;AAC9C,YAAYD,YAAW;AAWhB,SAAS,MAAM,OAAyC;AAC9D,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,QAAM,WAAW,SAAS,OAAO,KAAK;AACtC,QAAM,WAAiB,cAAO,KAAK;AACnC,QAAM,cAAc,MAAM;AACzB,WAAO;AAAA,MACN,IAAI,SAAS;AAAA,MACb,QAAQ,SAAS,QAAQ;AAAA,MACzB,MAAM,MAAM,KAAK,KAAK;AAAA,MACtB,MAAM,MAAM,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AACA,QAAM,OAAa,cAAqB,YAAY,CAAC;AACrD,QAAM,WAAW,MAAM;AACtB,QACC,KAAK,QAAQ,QAAO,qCAAU,OAC9B,KAAK,QAAQ,YAAW,qCAAU,QAAQ,WAC1C,SAAS,YAAY,OACpB;AACD,eAAS,UAAU;AACnB,WAAK,UAAU,YAAY;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EACb;AACA,SAAa;AAAA,IACZ,CAAC,aAAa,oBAAoB,OAAO,UAAU,UAAU,EAAE,IAAI,KAAK;AAAA,IACxE;AAAA,IACA;AAAA,EACD;AACD","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type { ReadableToken, WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { findInStore, setIntoStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K> | WritableToken<T>,\n\tkey?: K,\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst setter: React.MutableRefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tif (setter.current === null) {\n\t\tsetter.current = (next) => setIntoStore(stateToken, next, store)\n\t}\n\treturn setter.current\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableToken,\n} from \"atom.io\"\nimport { findInStore, getJsonToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\nimport { useO } from \"./use-o\"\n\nexport function useJSON<Serializable extends Json.Serializable>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Json.Serializable,\n>(token: MutableAtomFamilyToken<any, Serializable, Key>, key: Key): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Serializable,\n>(\n\ttoken:\n\t\t| MutableAtomFamilyToken<any, Serializable, Key>\n\t\t| MutableAtomToken<any, Serializable>,\n\tkey?: Key,\n): Serializable {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `mutable_atom_family`\n\t\t\t? findInStore(token, key as Key, store)\n\t\t\t: token\n\tconst jsonToken = getJsonToken(stateToken)\n\treturn useO(jsonToken)\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport { findInStore, getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useO<T>(token: ReadableToken<T>): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K> | ReadableToken<T>,\n\tkey?: K,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family` ||\n\t\ttoken.type === `readonly_selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),\n\t\t() => getFromStore(stateToken, store),\n\t\t() => getFromStore(stateToken, store),\n\t)\n}\n","import { redo, undo } from \"atom.io\"\nimport type { TimelineToken } from \"atom.io\"\nimport { subscribeToTimeline, withdraw } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tconst timeline = withdraw(token, store)\n\tconst tokenRef = React.useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline.at,\n\t\t\tlength: timeline.history.length,\n\t\t\tundo: () => undo(token),\n\t\t\tredo: () => redo(token),\n\t\t}\n\t}\n\tconst meta = React.useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn React.useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"]}
|
package/react/dist/index.js
CHANGED
|
@@ -39,10 +39,9 @@ function useTL(token) {
|
|
|
39
39
|
const timeline = withdraw(token, store);
|
|
40
40
|
const tokenRef = React5.useRef(token);
|
|
41
41
|
const rebuildMeta = () => {
|
|
42
|
-
var _a, _b;
|
|
43
42
|
return {
|
|
44
|
-
at:
|
|
45
|
-
length:
|
|
43
|
+
at: timeline.at,
|
|
44
|
+
length: timeline.history.length,
|
|
46
45
|
undo: () => undo(token),
|
|
47
46
|
redo: () => redo(token)
|
|
48
47
|
};
|
package/react/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACThD,SAAS,aAAa,oBAAoB;AAE1C,YAAYA,YAAW;AAahB,SAAS,KACf,OACA,KACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,oBACZ,YAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,aAAa,YAAY,MAAM,KAAK;AAAA,EAChE;AACA,SAAO,OAAO;AACf;;;AC7BA,SAAS,eAAAC,cAAa,oBAAoB;AAE1C,YAAYD,YAAW;;;ACNvB,SAAS,eAAAC,cAAa,cAAc,wBAAwB;AAE5D,YAAYD,YAAW;AAWhB,SAAS,KACf,OACA,KACI;AACJ,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,qBACf,MAAM,SAAS,6BACZC,aAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,iBAAiB,YAAY,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IACzE,MAAM,aAAa,YAAY,KAAK;AAAA,IACpC,MAAM,aAAa,YAAY,KAAK;AAAA,EACrC;AACD;;;ADXO,SAAS,QAIf,OAGA,KACe;AACf,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,wBACZA,aAAY,OAAO,KAAY,KAAK,IACpC;AACJ,QAAM,YAAY,aAAa,UAAU;AACzC,SAAO,KAAK,SAAS;AACtB;;;AErCA,SAAS,MAAM,YAAY;AAE3B,SAAS,qBAAqB,gBAAgB;AAC9C,YAAYD,YAAW;AAWhB,SAAS,MAAM,OAAyC;AAC9D,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,QAAM,WAAW,SAAS,OAAO,KAAK;AACtC,QAAM,WAAiB,cAAO,KAAK;AACnC,QAAM,cAAc,MAAM;
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACThD,SAAS,aAAa,oBAAoB;AAE1C,YAAYA,YAAW;AAahB,SAAS,KACf,OACA,KACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,oBACZ,YAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,aAAa,YAAY,MAAM,KAAK;AAAA,EAChE;AACA,SAAO,OAAO;AACf;;;AC7BA,SAAS,eAAAC,cAAa,oBAAoB;AAE1C,YAAYD,YAAW;;;ACNvB,SAAS,eAAAC,cAAa,cAAc,wBAAwB;AAE5D,YAAYD,YAAW;AAWhB,SAAS,KACf,OACA,KACI;AACJ,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,qBACf,MAAM,SAAS,6BACZC,aAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,iBAAiB,YAAY,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IACzE,MAAM,aAAa,YAAY,KAAK;AAAA,IACpC,MAAM,aAAa,YAAY,KAAK;AAAA,EACrC;AACD;;;ADXO,SAAS,QAIf,OAGA,KACe;AACf,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,wBACZA,aAAY,OAAO,KAAY,KAAK,IACpC;AACJ,QAAM,YAAY,aAAa,UAAU;AACzC,SAAO,KAAK,SAAS;AACtB;;;AErCA,SAAS,MAAM,YAAY;AAE3B,SAAS,qBAAqB,gBAAgB;AAC9C,YAAYD,YAAW;AAWhB,SAAS,MAAM,OAAyC;AAC9D,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,QAAM,WAAW,SAAS,OAAO,KAAK;AACtC,QAAM,WAAiB,cAAO,KAAK;AACnC,QAAM,cAAc,MAAM;AACzB,WAAO;AAAA,MACN,IAAI,SAAS;AAAA,MACb,QAAQ,SAAS,QAAQ;AAAA,MACzB,MAAM,MAAM,KAAK,KAAK;AAAA,MACtB,MAAM,MAAM,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AACA,QAAM,OAAa,cAAqB,YAAY,CAAC;AACrD,QAAM,WAAW,MAAM;AACtB,QACC,KAAK,QAAQ,QAAO,qCAAU,OAC9B,KAAK,QAAQ,YAAW,qCAAU,QAAQ,WAC1C,SAAS,YAAY,OACpB;AACD,eAAS,UAAU;AACnB,WAAK,UAAU,YAAY;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EACb;AACA,SAAa;AAAA,IACZ,CAAC,aAAa,oBAAoB,OAAO,UAAU,UAAU,EAAE,IAAI,KAAK;AAAA,IACxE;AAAA,IACA;AAAA,EACD;AACD","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type { ReadableToken, WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { findInStore, setIntoStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K> | WritableToken<T>,\n\tkey?: K,\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst setter: React.MutableRefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tif (setter.current === null) {\n\t\tsetter.current = (next) => setIntoStore(stateToken, next, store)\n\t}\n\treturn setter.current\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableToken,\n} from \"atom.io\"\nimport { findInStore, getJsonToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\nimport { useO } from \"./use-o\"\n\nexport function useJSON<Serializable extends Json.Serializable>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Json.Serializable,\n>(token: MutableAtomFamilyToken<any, Serializable, Key>, key: Key): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Serializable,\n>(\n\ttoken:\n\t\t| MutableAtomFamilyToken<any, Serializable, Key>\n\t\t| MutableAtomToken<any, Serializable>,\n\tkey?: Key,\n): Serializable {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `mutable_atom_family`\n\t\t\t? findInStore(token, key as Key, store)\n\t\t\t: token\n\tconst jsonToken = getJsonToken(stateToken)\n\treturn useO(jsonToken)\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport { findInStore, getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useO<T>(token: ReadableToken<T>): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K> | ReadableToken<T>,\n\tkey?: K,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family` ||\n\t\ttoken.type === `readonly_selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),\n\t\t() => getFromStore(stateToken, store),\n\t\t() => getFromStore(stateToken, store),\n\t)\n}\n","import { redo, undo } from \"atom.io\"\nimport type { TimelineToken } from \"atom.io\"\nimport { subscribeToTimeline, withdraw } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tconst timeline = withdraw(token, store)\n\tconst tokenRef = React.useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline.at,\n\t\t\tlength: timeline.history.length,\n\t\t\tundo: () => undo(token),\n\t\t\tredo: () => redo(token),\n\t\t}\n\t}\n\tconst meta = React.useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn React.useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"]}
|
package/react/src/use-tl.ts
CHANGED
|
@@ -19,8 +19,8 @@ export function useTL(token: TimelineToken<any>): TimelineMeta {
|
|
|
19
19
|
const tokenRef = React.useRef(token)
|
|
20
20
|
const rebuildMeta = () => {
|
|
21
21
|
return {
|
|
22
|
-
at: timeline
|
|
23
|
-
length: timeline
|
|
22
|
+
at: timeline.at,
|
|
23
|
+
length: timeline.history.length,
|
|
24
24
|
undo: () => undo(token),
|
|
25
25
|
redo: () => redo(token),
|
|
26
26
|
}
|
|
@@ -525,7 +525,7 @@ var persistAtom = (storage) => ({ stringify, parse }) => (key) => ({ setSelf, on
|
|
|
525
525
|
storage.setItem(key, stringify(newValue));
|
|
526
526
|
});
|
|
527
527
|
};
|
|
528
|
-
var lazyLocalStorageEffect = persistAtom(localStorage)(JSON);
|
|
528
|
+
var lazyLocalStorageEffect = persistAtom(window.localStorage)(JSON);
|
|
529
529
|
var OpenClose = ({ isOpen, setIsOpen, disabled }) => {
|
|
530
530
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
531
531
|
"button",
|