atom.io 0.33.2 → 0.33.4
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/data/index.d.ts +3 -3
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/eslint-plugin/index.d.ts.map +1 -1
- package/dist/internal/index.d.ts +118 -54
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +381 -128
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +11 -10
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +4 -4
- package/dist/introspection/index.js.map +1 -1
- package/dist/json/index.d.ts +3 -3
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +2 -2
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +157 -36
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +15 -3
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/{devtools-Jyn42mZm.css → react-devtools/index.css} +1 -1
- package/dist/react-devtools/index.css.map +1 -0
- package/dist/react-devtools/index.d.ts +0 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js +8 -3
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +3 -2
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +4 -1
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +27 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/web/index.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/data/dict.ts +5 -5
- package/src/data/struct-family.ts +2 -2
- package/src/data/struct.ts +1 -1
- package/src/internal/atom/create-regular-atom.ts +14 -17
- package/src/internal/caching.ts +1 -1
- package/src/internal/families/create-readonly-held-selector-family.ts +81 -0
- package/src/internal/families/{create-readonly-selector-family.ts → create-readonly-pure-selector-family.ts} +26 -23
- package/src/internal/families/create-selector-family.ts +39 -16
- package/src/internal/families/create-writable-held-selector-family.ts +80 -0
- package/src/internal/families/{create-writable-selector-family.ts → create-writable-pure-selector-family.ts} +26 -23
- package/src/internal/families/dispose-from-store.ts +4 -2
- package/src/internal/families/find-in-store.ts +8 -8
- package/src/internal/families/get-family-of-token.ts +8 -8
- package/src/internal/families/index.ts +3 -3
- package/src/internal/families/init-family-member.ts +12 -10
- package/src/internal/families/seek-in-store.ts +13 -11
- package/src/internal/get-state/get-from-store.ts +5 -2
- package/src/internal/get-state/read-or-compute-value.ts +4 -2
- package/src/internal/index.ts +97 -20
- package/src/internal/join/join-internal.ts +18 -18
- package/src/internal/keys.ts +1 -1
- package/src/internal/mutable/create-mutable-atom.ts +17 -15
- package/src/internal/mutable/get-json-family.ts +4 -4
- package/src/internal/mutable/get-json-token.ts +7 -7
- package/src/internal/selector/create-readonly-held-selector.ts +50 -0
- package/src/internal/selector/create-readonly-pure-selector.ts +51 -0
- package/src/internal/selector/create-standalone-selector.ts +48 -15
- package/src/internal/selector/create-writable-held-selector.ts +68 -0
- package/src/internal/selector/{create-writable-selector.ts → create-writable-pure-selector.ts} +18 -25
- package/src/internal/selector/dispose-selector.ts +37 -7
- package/src/internal/selector/get-selector-dependency-keys.ts +1 -1
- package/src/internal/selector/index.ts +4 -2
- package/src/internal/selector/register-selector.ts +17 -5
- package/src/internal/selector/trace-selector-atoms.ts +5 -5
- package/src/internal/selector/update-selector-atoms.ts +16 -10
- package/src/internal/set-state/emit-update.ts +4 -2
- package/src/internal/set-state/set-atom-or-selector.ts +2 -1
- package/src/internal/store/counterfeit.ts +13 -11
- package/src/internal/store/deposit.ts +18 -14
- package/src/internal/store/store.ts +9 -14
- package/src/internal/store/withdraw.ts +83 -7
- package/src/internal/subscribe/subscribe-in-store.ts +4 -2
- package/src/internal/subscribe/subscribe-to-state.ts +2 -1
- package/src/internal/timeline/create-timeline.ts +4 -2
- package/src/internal/transaction/build-transaction.ts +1 -1
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-introspection-states.ts +9 -9
- package/src/introspection/attach-selector-index.ts +3 -3
- package/src/introspection/attach-timeline-family.ts +2 -2
- package/src/introspection/attach-timeline-index.ts +2 -2
- package/src/introspection/attach-transaction-index.ts +2 -2
- package/src/introspection/attach-transaction-logs.ts +2 -2
- package/src/introspection/attach-type-selectors.ts +5 -5
- package/src/introspection/auditor.ts +3 -3
- package/src/json/select-json-family.ts +5 -5
- package/src/json/select-json.ts +1 -1
- package/src/main/find-state.ts +8 -8
- package/src/main/index.ts +51 -6
- package/src/main/join.ts +13 -13
- package/src/main/logger.ts +32 -15
- package/src/main/selector.ts +164 -30
- package/src/main/transaction.ts +3 -3
- package/src/main/validators.ts +16 -12
- package/src/react-devtools/StateEditor.tsx +14 -4
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/TimelineIndex.tsx +2 -2
- package/src/react-devtools/TransactionIndex.tsx +2 -2
- package/src/realtime/shared-room-store.ts +3 -3
- package/src/realtime-client/realtime-client-stores/client-main-store.ts +1 -1
- package/src/realtime-react/use-pull-selector-family-member.ts +1 -0
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +2 -2
- package/dist/devtools-CAg2k57t.js +0 -0
- package/dist/devtools-Jyn42mZm.css.map +0 -1
- package/src/internal/selector/create-readonly-selector.ts +0 -55
|
@@ -11,8 +11,10 @@ export const readOrComputeValue = <T>(
|
|
|
11
11
|
return readCachedValue(state, target)
|
|
12
12
|
}
|
|
13
13
|
switch (state.type) {
|
|
14
|
-
case `
|
|
15
|
-
case `
|
|
14
|
+
case `readonly_held_selector`:
|
|
15
|
+
case `readonly_pure_selector`:
|
|
16
|
+
case `writable_held_selector`:
|
|
17
|
+
case `writable_pure_selector`:
|
|
16
18
|
target.logger.info(`🧮`, state.type, state.key, `computing value`)
|
|
17
19
|
return state.get()
|
|
18
20
|
case `atom`:
|
package/src/internal/index.ts
CHANGED
|
@@ -3,14 +3,18 @@ import type {
|
|
|
3
3
|
FamilyMetadata,
|
|
4
4
|
MutableAtomFamilyToken,
|
|
5
5
|
MutableAtomToken,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
ReadonlyHeldSelectorFamilyToken,
|
|
7
|
+
ReadonlyHeldSelectorToken,
|
|
8
|
+
ReadonlyPureSelectorFamilyToken,
|
|
9
|
+
ReadonlyPureSelectorToken,
|
|
8
10
|
RegularAtomFamilyToken,
|
|
9
11
|
RegularAtomToken,
|
|
10
12
|
StateCreation,
|
|
11
13
|
StateDisposal,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
WritableHeldSelectorFamilyToken,
|
|
15
|
+
WritableHeldSelectorToken,
|
|
16
|
+
WritablePureSelectorFamilyToken,
|
|
17
|
+
WritablePureSelectorToken,
|
|
14
18
|
} from "atom.io"
|
|
15
19
|
import type { Canonical, Json, JsonInterface } from "atom.io/json"
|
|
16
20
|
|
|
@@ -76,16 +80,39 @@ export type Atom<T> =
|
|
|
76
80
|
| RegularAtom<T>
|
|
77
81
|
| (T extends Transceiver<any> ? MutableAtom<T, any> : never)
|
|
78
82
|
|
|
79
|
-
export type
|
|
80
|
-
type: `
|
|
83
|
+
export type WritableHeldSelector<T> = AtomIOState & {
|
|
84
|
+
type: `writable_held_selector`
|
|
85
|
+
const: T
|
|
81
86
|
get: () => T
|
|
82
87
|
set: (newValue: T | ((oldValue: T) => T)) => void
|
|
83
88
|
}
|
|
84
|
-
export type
|
|
85
|
-
type: `
|
|
89
|
+
export type ReadonlyHeldSelector<T> = AtomIOState & {
|
|
90
|
+
type: `readonly_held_selector`
|
|
91
|
+
const: T
|
|
86
92
|
get: () => T
|
|
87
93
|
}
|
|
88
|
-
export type
|
|
94
|
+
export type WritablePureSelector<T> = AtomIOState & {
|
|
95
|
+
type: `writable_pure_selector`
|
|
96
|
+
get: () => T
|
|
97
|
+
set: (newValue: T | ((oldValue: T) => T)) => void
|
|
98
|
+
}
|
|
99
|
+
export type ReadonlyPureSelector<T> = AtomIOState & {
|
|
100
|
+
type: `readonly_pure_selector`
|
|
101
|
+
get: () => T
|
|
102
|
+
}
|
|
103
|
+
export type ReadonlySelector<T> =
|
|
104
|
+
| ReadonlyHeldSelector<T>
|
|
105
|
+
| ReadonlyPureSelector<T>
|
|
106
|
+
export type WritableSelector<T> =
|
|
107
|
+
| WritableHeldSelector<T>
|
|
108
|
+
| WritablePureSelector<T>
|
|
109
|
+
export type HeldSelector<T> = ReadonlyHeldSelector<T> | WritableHeldSelector<T>
|
|
110
|
+
export type PureSelector<T> = ReadonlyPureSelector<T> | WritablePureSelector<T>
|
|
111
|
+
export type Selector<T> =
|
|
112
|
+
| ReadonlyHeldSelector<T>
|
|
113
|
+
| ReadonlyPureSelector<T>
|
|
114
|
+
| WritableHeldSelector<T>
|
|
115
|
+
| WritablePureSelector<T>
|
|
89
116
|
|
|
90
117
|
export type WritableState<T> = Atom<T> | WritableSelector<T>
|
|
91
118
|
export type ReadableState<T> = Atom<T> | Selector<T>
|
|
@@ -120,34 +147,84 @@ export type AtomFamily<T, K extends Canonical = Canonical> =
|
|
|
120
147
|
| RegularAtomFamily<T, K>
|
|
121
148
|
|
|
122
149
|
// biome-ignore format: intersection
|
|
123
|
-
export type
|
|
124
|
-
&
|
|
125
|
-
& ((key: K) =>
|
|
150
|
+
export type WritablePureSelectorFamily<T, K extends Canonical> =
|
|
151
|
+
& WritablePureSelectorFamilyToken<T, K>
|
|
152
|
+
& ((key: K) => WritablePureSelectorToken<T>)
|
|
153
|
+
& {
|
|
154
|
+
default: (key: K) => T,
|
|
155
|
+
subject: Subject<
|
|
156
|
+
| StateCreation<WritablePureSelectorToken<T>>
|
|
157
|
+
| StateDisposal<WritablePureSelectorToken<T>>
|
|
158
|
+
>
|
|
159
|
+
install: (store: Store) => void
|
|
160
|
+
internalRoles : string[] | undefined
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// biome-ignore format: intersection
|
|
164
|
+
export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
165
|
+
& WritableHeldSelectorFamilyToken<T, K>
|
|
166
|
+
& ((key: K) => WritableHeldSelectorToken<T>)
|
|
126
167
|
& {
|
|
127
168
|
default: (key: K) => T,
|
|
128
|
-
subject: Subject<
|
|
169
|
+
subject: Subject<
|
|
170
|
+
| StateCreation<WritableHeldSelectorToken<T>>
|
|
171
|
+
| StateDisposal<WritableHeldSelectorToken<T>>
|
|
172
|
+
>
|
|
129
173
|
install: (store: Store) => void
|
|
130
174
|
internalRoles : string[] | undefined
|
|
131
175
|
}
|
|
132
176
|
|
|
133
177
|
// biome-ignore format: intersection
|
|
134
|
-
export type
|
|
135
|
-
&
|
|
136
|
-
& ((key: K) =>
|
|
178
|
+
export type ReadonlyPureSelectorFamily<T, K extends Canonical> =
|
|
179
|
+
& ReadonlyPureSelectorFamilyToken<T, K>
|
|
180
|
+
& ((key: K) => ReadonlyPureSelectorToken<T>)
|
|
137
181
|
& {
|
|
138
182
|
default: (key: K) => T,
|
|
139
|
-
subject: Subject<
|
|
183
|
+
subject: Subject<
|
|
184
|
+
| StateCreation<ReadonlyPureSelectorToken<T>>
|
|
185
|
+
| StateDisposal<ReadonlyPureSelectorToken<T>>
|
|
186
|
+
>
|
|
140
187
|
install: (store: Store) => void
|
|
141
188
|
internalRoles : string[] | undefined
|
|
142
189
|
}
|
|
143
190
|
|
|
191
|
+
// biome-ignore format: intersection
|
|
192
|
+
export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
193
|
+
& ReadonlyHeldSelectorFamilyToken<T, K>
|
|
194
|
+
& ((key: K) => ReadonlyHeldSelectorToken<T>)
|
|
195
|
+
& {
|
|
196
|
+
default: (key: K) => T,
|
|
197
|
+
subject: Subject<
|
|
198
|
+
| StateCreation<ReadonlyHeldSelectorToken<T>>
|
|
199
|
+
| StateDisposal<ReadonlyHeldSelectorToken<T>>
|
|
200
|
+
>
|
|
201
|
+
install: (store: Store) => void
|
|
202
|
+
internalRoles : string[] | undefined
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export type PureSelectorFamily<T, K extends Canonical> =
|
|
206
|
+
| ReadonlyPureSelectorFamily<T, K>
|
|
207
|
+
| WritablePureSelectorFamily<T, K>
|
|
208
|
+
|
|
209
|
+
export type HeldSelectorFamily<T, K extends Canonical> =
|
|
210
|
+
| ReadonlyHeldSelectorFamily<T, K>
|
|
211
|
+
| WritableHeldSelectorFamily<T, K>
|
|
212
|
+
|
|
213
|
+
export type ReadonlySelectorFamily<T, K extends Canonical> =
|
|
214
|
+
| ReadonlyHeldSelectorFamily<T, K>
|
|
215
|
+
| ReadonlyPureSelectorFamily<T, K>
|
|
216
|
+
|
|
217
|
+
export type WritableSelectorFamily<T, K extends Canonical> =
|
|
218
|
+
| WritableHeldSelectorFamily<T, K>
|
|
219
|
+
| WritablePureSelectorFamily<T, K>
|
|
220
|
+
|
|
144
221
|
export type SelectorFamily<T, K extends Canonical> =
|
|
145
|
-
|
|
|
146
|
-
|
|
|
222
|
+
| HeldSelectorFamily<T, K>
|
|
223
|
+
| PureSelectorFamily<T, K>
|
|
147
224
|
|
|
148
225
|
export type WritableFamily<T, K extends Canonical> =
|
|
149
226
|
| AtomFamily<T, K>
|
|
150
|
-
|
|
|
227
|
+
| WritablePureSelectorFamily<T, K>
|
|
151
228
|
export type ReadableFamily<T, K extends Canonical> =
|
|
152
229
|
| AtomFamily<T, K>
|
|
153
230
|
| SelectorFamily<T, K>
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
JoinOptions,
|
|
6
6
|
MutableAtomFamilyToken,
|
|
7
7
|
Read,
|
|
8
|
-
|
|
8
|
+
ReadonlyPureSelectorFamilyToken,
|
|
9
9
|
RegularAtomFamilyToken,
|
|
10
10
|
setState,
|
|
11
11
|
SetterToolkit,
|
|
@@ -19,7 +19,7 @@ import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
|
19
19
|
|
|
20
20
|
import { capitalize } from "../capitalize"
|
|
21
21
|
import {
|
|
22
|
-
|
|
22
|
+
createReadonlyPureSelectorFamily,
|
|
23
23
|
createRegularAtomFamily,
|
|
24
24
|
findInStore,
|
|
25
25
|
} from "../families"
|
|
@@ -45,23 +45,23 @@ export type JoinStateFamilies<
|
|
|
45
45
|
> = Cardinality extends `1:1`
|
|
46
46
|
? (Content extends Json.Object
|
|
47
47
|
? {
|
|
48
|
-
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]:
|
|
48
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
49
49
|
[AType, Content] | null,
|
|
50
50
|
BType
|
|
51
51
|
>
|
|
52
52
|
} & {
|
|
53
|
-
readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]:
|
|
53
|
+
readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
54
54
|
[BType, Content] | null,
|
|
55
55
|
AType
|
|
56
56
|
>
|
|
57
57
|
}
|
|
58
58
|
: {}) & {
|
|
59
|
-
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]:
|
|
59
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
60
60
|
AType | null,
|
|
61
61
|
BType
|
|
62
62
|
>
|
|
63
63
|
} & {
|
|
64
|
-
readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]:
|
|
64
|
+
readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
65
65
|
BType | null,
|
|
66
66
|
AType
|
|
67
67
|
>
|
|
@@ -69,23 +69,23 @@ export type JoinStateFamilies<
|
|
|
69
69
|
: Cardinality extends `1:n`
|
|
70
70
|
? (Content extends Json.Object
|
|
71
71
|
? {
|
|
72
|
-
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]:
|
|
72
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
73
73
|
[AType, Content] | null,
|
|
74
74
|
BType
|
|
75
75
|
>
|
|
76
76
|
} & {
|
|
77
|
-
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]:
|
|
77
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
78
78
|
[BType, Content][],
|
|
79
79
|
AType
|
|
80
80
|
>
|
|
81
81
|
}
|
|
82
82
|
: {}) & {
|
|
83
|
-
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]:
|
|
83
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
84
84
|
AType | null,
|
|
85
85
|
BType
|
|
86
86
|
>
|
|
87
87
|
} & {
|
|
88
|
-
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]:
|
|
88
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
89
89
|
BType[],
|
|
90
90
|
AType
|
|
91
91
|
>
|
|
@@ -93,23 +93,23 @@ export type JoinStateFamilies<
|
|
|
93
93
|
: Cardinality extends `n:n`
|
|
94
94
|
? (Content extends Json.Object
|
|
95
95
|
? {
|
|
96
|
-
readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]:
|
|
96
|
+
readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
97
97
|
[AType, Content][],
|
|
98
98
|
BType
|
|
99
99
|
>
|
|
100
100
|
} & {
|
|
101
|
-
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]:
|
|
101
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
102
102
|
[BType, Content][],
|
|
103
103
|
AType
|
|
104
104
|
>
|
|
105
105
|
}
|
|
106
106
|
: {}) & {
|
|
107
|
-
readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]:
|
|
107
|
+
readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
108
108
|
AType[],
|
|
109
109
|
BType
|
|
110
110
|
>
|
|
111
111
|
} & {
|
|
112
|
-
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]:
|
|
112
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorFamilyToken<
|
|
113
113
|
BType[],
|
|
114
114
|
AType
|
|
115
115
|
>
|
|
@@ -412,7 +412,7 @@ export class Join<
|
|
|
412
412
|
)
|
|
413
413
|
|
|
414
414
|
const createSingleKeySelectorFamily = () =>
|
|
415
|
-
|
|
415
|
+
createReadonlyPureSelectorFamily<string | null, string>(
|
|
416
416
|
store,
|
|
417
417
|
{
|
|
418
418
|
key: `${options.key}/singleRelatedKey`,
|
|
@@ -429,7 +429,7 @@ export class Join<
|
|
|
429
429
|
[`join`, `keys`],
|
|
430
430
|
)
|
|
431
431
|
const getMultipleKeySelectorFamily = () => {
|
|
432
|
-
return
|
|
432
|
+
return createReadonlyPureSelectorFamily<string[], string>(
|
|
433
433
|
store,
|
|
434
434
|
{
|
|
435
435
|
key: `${options.key}/multipleRelatedKeys`,
|
|
@@ -445,7 +445,7 @@ export class Join<
|
|
|
445
445
|
)
|
|
446
446
|
}
|
|
447
447
|
const createSingleEntrySelectorFamily = () =>
|
|
448
|
-
|
|
448
|
+
createReadonlyPureSelectorFamily<[string, Content] | null, string>(
|
|
449
449
|
store,
|
|
450
450
|
{
|
|
451
451
|
key: `${options.key}/singleRelatedEntry`,
|
|
@@ -468,7 +468,7 @@ export class Join<
|
|
|
468
468
|
[`join`, `entries`],
|
|
469
469
|
)
|
|
470
470
|
const getMultipleEntrySelectorFamily = () =>
|
|
471
|
-
|
|
471
|
+
createReadonlyPureSelectorFamily<[string, Content][], string>(
|
|
472
472
|
store,
|
|
473
473
|
{
|
|
474
474
|
key: `${options.key}/multipleRelatedEntries`,
|
package/src/internal/keys.ts
CHANGED
|
@@ -13,7 +13,7 @@ export const isAtomKey = (store: Store, key: string): key is AtomKey<unknown> =>
|
|
|
13
13
|
export const isSelectorKey = (
|
|
14
14
|
store: Store,
|
|
15
15
|
key: string,
|
|
16
|
-
): key is SelectorKey<unknown> => newest(store).
|
|
16
|
+
): key is SelectorKey<unknown> => newest(store).writableSelectors.has(key)
|
|
17
17
|
export const isReadonlySelectorKey = (
|
|
18
18
|
store: Store,
|
|
19
19
|
key: string,
|
|
@@ -7,7 +7,12 @@ import type {
|
|
|
7
7
|
import type { Json } from "atom.io/json"
|
|
8
8
|
import { selectJson } from "atom.io/json"
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
cacheValue,
|
|
12
|
+
type MutableAtom,
|
|
13
|
+
prettyPrintTokenType,
|
|
14
|
+
setIntoStore,
|
|
15
|
+
} from ".."
|
|
11
16
|
import { markAtomAsDefault } from "../atom"
|
|
12
17
|
import { newest } from "../lineage"
|
|
13
18
|
import { deposit, type Store } from "../store"
|
|
@@ -31,12 +36,14 @@ export function createMutableAtom<
|
|
|
31
36
|
`creating in store "${store.config.name}"`,
|
|
32
37
|
)
|
|
33
38
|
const target = newest(store)
|
|
34
|
-
const
|
|
35
|
-
|
|
39
|
+
const { key, default: def } = options
|
|
40
|
+
const existing = target.atoms.get(key)
|
|
41
|
+
const type = `mutable_atom`
|
|
42
|
+
if (existing && existing.type === type) {
|
|
36
43
|
store.logger.error(
|
|
37
44
|
`❌`,
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
type,
|
|
46
|
+
key,
|
|
40
47
|
`Tried to create atom, but it already exists in the store.`,
|
|
41
48
|
)
|
|
42
49
|
return deposit(existing)
|
|
@@ -44,14 +51,9 @@ export function createMutableAtom<
|
|
|
44
51
|
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
45
52
|
const newAtom: MutableAtom<T, J> = {
|
|
46
53
|
...options,
|
|
47
|
-
type
|
|
54
|
+
type,
|
|
48
55
|
install: (s: Store) => {
|
|
49
|
-
s.logger.info(
|
|
50
|
-
`🛠️`,
|
|
51
|
-
`atom`,
|
|
52
|
-
options.key,
|
|
53
|
-
`installing in store "${s.config.name}"`,
|
|
54
|
-
)
|
|
56
|
+
s.logger.info(`🛠️`, `atom`, key, `installing in store "${s.config.name}"`)
|
|
55
57
|
return createMutableAtom(s, options, family)
|
|
56
58
|
},
|
|
57
59
|
subject,
|
|
@@ -59,10 +61,10 @@ export function createMutableAtom<
|
|
|
59
61
|
if (family) {
|
|
60
62
|
newAtom.family = family
|
|
61
63
|
}
|
|
62
|
-
const initialValue =
|
|
64
|
+
const initialValue = def()
|
|
63
65
|
target.atoms.set(newAtom.key, newAtom)
|
|
64
|
-
markAtomAsDefault(store,
|
|
65
|
-
cacheValue(target,
|
|
66
|
+
markAtomAsDefault(store, key)
|
|
67
|
+
cacheValue(target, key, initialValue, subject)
|
|
66
68
|
const token = deposit(newAtom)
|
|
67
69
|
if (options.effects) {
|
|
68
70
|
let effectIndex = 0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MutableAtomFamilyToken } from "atom.io"
|
|
2
2
|
import type { Canonical, Json } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { WritablePureSelectorFamily } from ".."
|
|
5
5
|
import { newest } from "../lineage"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
import type { Transceiver } from "./transceiver"
|
|
@@ -13,10 +13,10 @@ export const getJsonFamily = <
|
|
|
13
13
|
>(
|
|
14
14
|
mutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>,
|
|
15
15
|
store: Store,
|
|
16
|
-
):
|
|
16
|
+
): WritablePureSelectorFamily<SerializableCore, Key> => {
|
|
17
17
|
const target = newest(store)
|
|
18
18
|
const key = `${mutableAtomFamily.key}:JSON`
|
|
19
|
-
const jsonFamily:
|
|
20
|
-
target.families.get(key) as
|
|
19
|
+
const jsonFamily: WritablePureSelectorFamily<SerializableCore, Key> =
|
|
20
|
+
target.families.get(key) as WritablePureSelectorFamily<SerializableCore, Key>
|
|
21
21
|
return jsonFamily
|
|
22
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
MutableAtomToken,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
WritablePureSelectorFamilyToken,
|
|
4
|
+
WritablePureSelectorToken,
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
import type { Json } from "atom.io/json"
|
|
7
7
|
|
|
@@ -16,24 +16,24 @@ export const getJsonToken = <
|
|
|
16
16
|
>(
|
|
17
17
|
store: Store,
|
|
18
18
|
mutableAtomToken: MutableAtomToken<Core, SerializableCore>,
|
|
19
|
-
):
|
|
19
|
+
): WritablePureSelectorToken<SerializableCore> => {
|
|
20
20
|
if (mutableAtomToken.family) {
|
|
21
21
|
const target = newest(store)
|
|
22
22
|
const jsonFamilyKey = `${mutableAtomToken.family.key}:JSON`
|
|
23
|
-
const jsonFamilyToken:
|
|
23
|
+
const jsonFamilyToken: WritablePureSelectorFamilyToken<
|
|
24
24
|
SerializableCore,
|
|
25
25
|
string
|
|
26
26
|
> = {
|
|
27
27
|
key: jsonFamilyKey,
|
|
28
|
-
type: `
|
|
28
|
+
type: `writable_pure_selector_family`,
|
|
29
29
|
}
|
|
30
30
|
const family = withdraw(target, jsonFamilyToken)
|
|
31
31
|
const subKey = JSON.parse(mutableAtomToken.family.subKey)
|
|
32
32
|
const jsonToken = findInStore(store, family, subKey)
|
|
33
33
|
return jsonToken
|
|
34
34
|
}
|
|
35
|
-
const token:
|
|
36
|
-
type: `
|
|
35
|
+
const token: WritablePureSelectorToken<SerializableCore> = {
|
|
36
|
+
type: `writable_pure_selector`,
|
|
37
37
|
key: `${mutableAtomToken.key}:JSON`,
|
|
38
38
|
}
|
|
39
39
|
return token
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FamilyMetadata,
|
|
3
|
+
ReadonlyHeldSelectorOptions,
|
|
4
|
+
ReadonlyHeldSelectorToken,
|
|
5
|
+
} from "atom.io"
|
|
6
|
+
|
|
7
|
+
import type { ReadonlyHeldSelector } from ".."
|
|
8
|
+
import { cacheValue } from "../caching"
|
|
9
|
+
import { newest } from "../lineage"
|
|
10
|
+
import type { Store } from "../store"
|
|
11
|
+
import { Subject } from "../subject"
|
|
12
|
+
import { registerSelector } from "./register-selector"
|
|
13
|
+
|
|
14
|
+
export const createReadonlyHeldSelector = <T extends object>(
|
|
15
|
+
store: Store,
|
|
16
|
+
options: ReadonlyHeldSelectorOptions<T>,
|
|
17
|
+
family: FamilyMetadata | undefined,
|
|
18
|
+
): ReadonlyHeldSelectorToken<T> => {
|
|
19
|
+
const target = newest(store)
|
|
20
|
+
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
21
|
+
const covered = new Set<string>()
|
|
22
|
+
const { key, const: constant } = options
|
|
23
|
+
const type = `readonly_held_selector` as const
|
|
24
|
+
const { get, find, json } = registerSelector(target, type, key, covered)
|
|
25
|
+
const getSelf = () => {
|
|
26
|
+
options.get({ get, find, json }, constant)
|
|
27
|
+
cacheValue(newest(store), key, constant, subject)
|
|
28
|
+
covered.clear()
|
|
29
|
+
return constant
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const readonlySelector: ReadonlyHeldSelector<T> = {
|
|
33
|
+
...options,
|
|
34
|
+
type,
|
|
35
|
+
subject,
|
|
36
|
+
install: (s: Store) => createReadonlyHeldSelector(s, options, family),
|
|
37
|
+
get: getSelf,
|
|
38
|
+
...(family && { family }),
|
|
39
|
+
}
|
|
40
|
+
target.readonlySelectors.set(key, readonlySelector)
|
|
41
|
+
store.logger.info(`✨`, type, key, `=`, constant)
|
|
42
|
+
const token: ReadonlyHeldSelectorToken<T> = {
|
|
43
|
+
key,
|
|
44
|
+
type,
|
|
45
|
+
}
|
|
46
|
+
if (family) {
|
|
47
|
+
token.family = family
|
|
48
|
+
}
|
|
49
|
+
return token
|
|
50
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FamilyMetadata,
|
|
3
|
+
ReadonlyPureSelectorOptions,
|
|
4
|
+
ReadonlyPureSelectorToken,
|
|
5
|
+
} from "atom.io"
|
|
6
|
+
|
|
7
|
+
import type { ReadonlyPureSelector } from ".."
|
|
8
|
+
import { cacheValue } from "../caching"
|
|
9
|
+
import { newest } from "../lineage"
|
|
10
|
+
import type { Store } from "../store"
|
|
11
|
+
import { Subject } from "../subject"
|
|
12
|
+
import { registerSelector } from "./register-selector"
|
|
13
|
+
|
|
14
|
+
export const createReadonlyPureSelector = <T>(
|
|
15
|
+
store: Store,
|
|
16
|
+
options: ReadonlyPureSelectorOptions<T>,
|
|
17
|
+
family: FamilyMetadata | undefined,
|
|
18
|
+
): ReadonlyPureSelectorToken<T> => {
|
|
19
|
+
const target = newest(store)
|
|
20
|
+
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
21
|
+
const covered = new Set<string>()
|
|
22
|
+
const key = options.key
|
|
23
|
+
const type = `readonly_pure_selector` as const
|
|
24
|
+
const { get, find, json } = registerSelector(target, type, key, covered)
|
|
25
|
+
const getSelf = () => {
|
|
26
|
+
const value = options.get({ get, find, json })
|
|
27
|
+
cacheValue(newest(store), key, value, subject)
|
|
28
|
+
covered.clear()
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const readonlySelector: ReadonlyPureSelector<T> = {
|
|
33
|
+
...options,
|
|
34
|
+
type,
|
|
35
|
+
subject,
|
|
36
|
+
install: (s: Store) => createReadonlyPureSelector(s, options, family),
|
|
37
|
+
get: getSelf,
|
|
38
|
+
...(family && { family }),
|
|
39
|
+
}
|
|
40
|
+
target.readonlySelectors.set(key, readonlySelector)
|
|
41
|
+
const initialValue = getSelf()
|
|
42
|
+
store.logger.info(`✨`, type, key, `=`, initialValue)
|
|
43
|
+
const token: ReadonlyPureSelectorToken<T> = {
|
|
44
|
+
key,
|
|
45
|
+
type,
|
|
46
|
+
}
|
|
47
|
+
if (family) {
|
|
48
|
+
token.family = family
|
|
49
|
+
}
|
|
50
|
+
return token
|
|
51
|
+
}
|
|
@@ -1,34 +1,67 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
ReadonlyHeldSelectorOptions,
|
|
3
|
+
ReadonlyHeldSelectorToken,
|
|
4
|
+
ReadonlyPureSelectorOptions,
|
|
5
|
+
ReadonlyPureSelectorToken,
|
|
6
|
+
WritableHeldSelectorOptions,
|
|
7
|
+
WritableHeldSelectorToken,
|
|
8
|
+
WritablePureSelectorOptions,
|
|
9
|
+
WritablePureSelectorToken,
|
|
6
10
|
} from "atom.io"
|
|
7
11
|
|
|
8
12
|
import type { Store } from "../store"
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
13
|
+
import { createReadonlyHeldSelector } from "./create-readonly-held-selector"
|
|
14
|
+
import { createReadonlyPureSelector } from "./create-readonly-pure-selector"
|
|
15
|
+
import { createWritableHeldSelector } from "./create-writable-held-selector"
|
|
16
|
+
import { createWritablePureSelector } from "./create-writable-pure-selector"
|
|
11
17
|
|
|
12
|
-
export function createStandaloneSelector<T>(
|
|
18
|
+
export function createStandaloneSelector<T extends object>(
|
|
19
|
+
store: Store,
|
|
20
|
+
options: WritableHeldSelectorOptions<T>,
|
|
21
|
+
): WritableHeldSelectorToken<T>
|
|
22
|
+
export function createStandaloneSelector<T extends object>(
|
|
13
23
|
store: Store,
|
|
14
|
-
options:
|
|
15
|
-
):
|
|
24
|
+
options: ReadonlyHeldSelectorOptions<T>,
|
|
25
|
+
): ReadonlyHeldSelectorToken<T>
|
|
16
26
|
export function createStandaloneSelector<T>(
|
|
17
27
|
store: Store,
|
|
18
|
-
options:
|
|
19
|
-
):
|
|
28
|
+
options: WritablePureSelectorOptions<T>,
|
|
29
|
+
): WritablePureSelectorToken<T>
|
|
20
30
|
export function createStandaloneSelector<T>(
|
|
21
31
|
store: Store,
|
|
22
|
-
options:
|
|
23
|
-
):
|
|
32
|
+
options: ReadonlyPureSelectorOptions<T>,
|
|
33
|
+
): ReadonlyPureSelectorToken<T>
|
|
34
|
+
export function createStandaloneSelector(
|
|
35
|
+
store: Store,
|
|
36
|
+
options:
|
|
37
|
+
| ReadonlyHeldSelectorOptions<any>
|
|
38
|
+
| ReadonlyPureSelectorOptions<any>
|
|
39
|
+
| WritableHeldSelectorOptions<any>
|
|
40
|
+
| WritablePureSelectorOptions<any>,
|
|
41
|
+
):
|
|
42
|
+
| ReadonlyHeldSelectorToken<any>
|
|
43
|
+
| ReadonlyPureSelectorToken<any>
|
|
44
|
+
| WritableHeldSelectorToken<any>
|
|
45
|
+
| WritablePureSelectorToken<any> {
|
|
24
46
|
const isWritable = `set` in options
|
|
47
|
+
const isHeld = `const` in options
|
|
25
48
|
|
|
49
|
+
if (isHeld && isWritable) {
|
|
50
|
+
const state = createWritableHeldSelector(store, options, undefined)
|
|
51
|
+
store.on.selectorCreation.next(state)
|
|
52
|
+
return state
|
|
53
|
+
}
|
|
54
|
+
if (isHeld) {
|
|
55
|
+
const state = createReadonlyHeldSelector(store, options, undefined)
|
|
56
|
+
store.on.selectorCreation.next(state)
|
|
57
|
+
return state
|
|
58
|
+
}
|
|
26
59
|
if (isWritable) {
|
|
27
|
-
const state =
|
|
60
|
+
const state = createWritablePureSelector(store, options, undefined)
|
|
28
61
|
store.on.selectorCreation.next(state)
|
|
29
62
|
return state
|
|
30
63
|
}
|
|
31
|
-
const state =
|
|
64
|
+
const state = createReadonlyPureSelector(store, options, undefined)
|
|
32
65
|
store.on.selectorCreation.next(state)
|
|
33
66
|
return state
|
|
34
67
|
}
|