atom.io 0.40.1 → 0.40.3
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 +1 -1
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/internal/index.d.ts +155 -144
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +91 -39
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +4 -4
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +80 -56
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +11 -11
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/struct.ts +2 -2
- package/src/internal/atom/create-regular-atom.ts +8 -7
- package/src/internal/atom/dispose-atom.ts +6 -3
- package/src/internal/atom/has-role.ts +1 -1
- package/src/internal/caching.ts +15 -15
- package/src/internal/events/ingest-creation-disposal.ts +1 -1
- package/src/internal/families/create-readonly-held-selector-family.ts +6 -7
- package/src/internal/families/create-readonly-pure-selector-family.ts +23 -17
- package/src/internal/families/create-regular-atom-family.ts +17 -15
- package/src/internal/families/create-selector-family.ts +9 -9
- package/src/internal/families/create-writable-held-selector-family.ts +6 -7
- package/src/internal/families/create-writable-pure-selector-family.ts +24 -18
- package/src/internal/families/dispose-from-store.ts +10 -7
- package/src/internal/families/find-in-store.ts +23 -23
- package/src/internal/families/get-family-of-token.ts +17 -17
- package/src/internal/families/mint-in-store.ts +11 -11
- package/src/internal/families/seek-in-store.ts +26 -26
- package/src/internal/get-state/get-fallback.ts +8 -8
- package/src/internal/get-state/get-from-store.ts +17 -12
- package/src/internal/get-state/read-or-compute-value.ts +78 -14
- package/src/internal/get-state/reduce-reference.ts +10 -10
- package/src/internal/index.ts +58 -53
- package/src/internal/join/join-internal.ts +15 -6
- package/src/internal/mutable/create-mutable-atom-family.ts +7 -8
- package/src/internal/mutable/get-json-family.ts +3 -2
- package/src/internal/mutable/get-update-family.ts +7 -5
- package/src/internal/mutable/tracker-family.ts +5 -1
- package/src/internal/mutable/tracker.ts +5 -1
- package/src/internal/operation.ts +4 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +8 -6
- package/src/internal/selector/create-standalone-selector.ts +10 -10
- package/src/internal/selector/create-writable-pure-selector.ts +9 -7
- package/src/internal/selector/dispose-selector.ts +2 -2
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/internal/selector/trace-selector-atoms.ts +3 -3
- package/src/internal/selector/update-selector-atoms.ts +1 -1
- package/src/internal/set-state/dispatch-state-update.ts +9 -5
- package/src/internal/set-state/evict-downstream.ts +4 -1
- package/src/internal/set-state/operate-on-store.ts +16 -10
- package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
- package/src/internal/set-state/reset-in-store.ts +9 -6
- package/src/internal/set-state/set-atom-or-selector.ts +1 -1
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/set-state/set-into-store.ts +10 -7
- package/src/internal/set-state/set-selector.ts +1 -1
- package/src/internal/store/deposit.ts +38 -30
- package/src/internal/store/mint-or-counterfeit.ts +23 -23
- package/src/internal/store/store.ts +9 -9
- package/src/internal/store/withdraw.ts +68 -62
- package/src/internal/subscribe/recall-state.ts +4 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
- package/src/internal/subscribe/subscribe-to-state.ts +4 -4
- package/src/internal/timeline/create-timeline.ts +5 -5
- package/src/internal/utility-types.ts +2 -0
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-selector-index.ts +4 -2
- package/src/introspection/attach-timeline-family.ts +13 -11
- package/src/introspection/attach-timeline-index.ts +1 -1
- package/src/introspection/attach-transaction-index.ts +1 -1
- package/src/introspection/attach-transaction-logs.ts +4 -2
- package/src/introspection/attach-type-selectors.ts +2 -1
- package/src/introspection/index.ts +3 -5
- package/src/main/atom.ts +15 -9
- package/src/main/events.ts +25 -23
- package/src/main/get-state.ts +10 -8
- package/src/main/reset-state.ts +4 -4
- package/src/main/selector.ts +41 -24
- package/src/main/set-state.ts +8 -4
- package/src/main/timeline.ts +5 -3
- package/src/main/tokens.ts +72 -44
- package/src/main/validators.ts +4 -4
- package/src/react/parse-state-overloads.ts +10 -10
- package/src/react/use-i.ts +6 -6
- package/src/react/use-loadable.ts +15 -15
- package/src/react/use-o.ts +9 -9
- package/src/react-devtools/StateEditor.tsx +5 -3
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/Updates.tsx +1 -1
- package/src/react-devtools/store.ts +16 -7
|
@@ -199,7 +199,8 @@ export class Join<
|
|
|
199
199
|
this.core = { relatedKeysAtoms }
|
|
200
200
|
const getRelatedKeys: Read<
|
|
201
201
|
(key: string) => SetRTX<AType> | SetRTX<BType>
|
|
202
|
-
> = ({ get }, key) =>
|
|
202
|
+
> = ({ get }, key) =>
|
|
203
|
+
get(relatedKeysAtoms, key) as SetRTX<AType> | SetRTX<BType>
|
|
203
204
|
const addRelation: Write<(a: string, b: string) => void> = (
|
|
204
205
|
{ set },
|
|
205
206
|
a,
|
|
@@ -331,7 +332,7 @@ export class Join<
|
|
|
331
332
|
let contentAtoms: RegularAtomFamilyToken<Content, string>
|
|
332
333
|
|
|
333
334
|
if (defaultContent) {
|
|
334
|
-
contentAtoms = createRegularAtomFamily<Content, ContentKey>(
|
|
335
|
+
contentAtoms = createRegularAtomFamily<Content, ContentKey, never>(
|
|
335
336
|
store,
|
|
336
337
|
{
|
|
337
338
|
key: `${options.key}/content`,
|
|
@@ -398,7 +399,7 @@ export class Join<
|
|
|
398
399
|
)
|
|
399
400
|
|
|
400
401
|
const createSingleKeySelectorFamily = () =>
|
|
401
|
-
createReadonlyPureSelectorFamily<string | null, string>(
|
|
402
|
+
createReadonlyPureSelectorFamily<string | null, string, never>(
|
|
402
403
|
store,
|
|
403
404
|
{
|
|
404
405
|
key: `${options.key}/singleRelatedKey`,
|
|
@@ -415,7 +416,7 @@ export class Join<
|
|
|
415
416
|
[`join`, `keys`],
|
|
416
417
|
)
|
|
417
418
|
const getMultipleKeySelectorFamily = () => {
|
|
418
|
-
return createReadonlyPureSelectorFamily<string[], string>(
|
|
419
|
+
return createReadonlyPureSelectorFamily<string[], string, never>(
|
|
419
420
|
store,
|
|
420
421
|
{
|
|
421
422
|
key: `${options.key}/multipleRelatedKeys`,
|
|
@@ -431,7 +432,11 @@ export class Join<
|
|
|
431
432
|
)
|
|
432
433
|
}
|
|
433
434
|
const createSingleEntrySelectorFamily = () =>
|
|
434
|
-
createReadonlyPureSelectorFamily<
|
|
435
|
+
createReadonlyPureSelectorFamily<
|
|
436
|
+
[string, ViewOf<Content>] | null,
|
|
437
|
+
string,
|
|
438
|
+
never
|
|
439
|
+
>(
|
|
435
440
|
store,
|
|
436
441
|
{
|
|
437
442
|
key: `${options.key}/singleRelatedEntry`,
|
|
@@ -454,7 +459,11 @@ export class Join<
|
|
|
454
459
|
[`join`, `entries`],
|
|
455
460
|
)
|
|
456
461
|
const getMultipleEntrySelectorFamily = () =>
|
|
457
|
-
createReadonlyPureSelectorFamily<
|
|
462
|
+
createReadonlyPureSelectorFamily<
|
|
463
|
+
[string, ViewOf<Content>][],
|
|
464
|
+
string,
|
|
465
|
+
never
|
|
466
|
+
>(
|
|
458
467
|
store,
|
|
459
468
|
{
|
|
460
469
|
key: `${options.key}/multipleRelatedEntries`,
|
|
@@ -44,7 +44,7 @@ export function createMutableAtomFamily<
|
|
|
44
44
|
|
|
45
45
|
const subject = new Subject<StateLifecycleEvent<MutableAtomToken<T>>>()
|
|
46
46
|
|
|
47
|
-
const
|
|
47
|
+
const create = (key: K): MutableAtomToken<T> => {
|
|
48
48
|
const subKey = stringifyJson(key)
|
|
49
49
|
const family: FamilyMetadata = { key: options.key, subKey }
|
|
50
50
|
const fullKey = `${options.key}(${subKey})`
|
|
@@ -58,22 +58,21 @@ export function createMutableAtomFamily<
|
|
|
58
58
|
individualOptions.effects = options.effects(key)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// subject.next({ type: `state_creation`, token, timestamp: Date.now() })
|
|
64
|
-
return token
|
|
61
|
+
return createMutableAtom(target, individualOptions, family)
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
const atomFamily
|
|
64
|
+
const atomFamily: MutableAtomFamily<T, K> = {
|
|
65
|
+
...familyToken,
|
|
66
|
+
create,
|
|
68
67
|
class: options.class,
|
|
69
68
|
subject,
|
|
70
69
|
install: (s: RootStore) => createMutableAtomFamily(s, options),
|
|
71
70
|
internalRoles,
|
|
72
|
-
}
|
|
71
|
+
}
|
|
73
72
|
|
|
74
73
|
store.families.set(options.key, atomFamily)
|
|
75
74
|
|
|
76
|
-
createWritablePureSelectorFamily<AsJSON<T>, K>(
|
|
75
|
+
createWritablePureSelectorFamily<AsJSON<T>, K, never>(
|
|
77
76
|
store,
|
|
78
77
|
{
|
|
79
78
|
key: `${options.key}:JSON`,
|
|
@@ -12,12 +12,13 @@ export const getJsonFamily = <
|
|
|
12
12
|
>(
|
|
13
13
|
mutableAtomFamily: MutableAtomFamilyToken<Core, Key>,
|
|
14
14
|
store: Store,
|
|
15
|
-
): WritablePureSelectorFamily<ReturnType<Core[`toJSON`]>, Key> => {
|
|
15
|
+
): WritablePureSelectorFamily<ReturnType<Core[`toJSON`]>, Key, never> => {
|
|
16
16
|
const target = newest(store)
|
|
17
17
|
const key = `${mutableAtomFamily.key}:JSON`
|
|
18
18
|
const jsonFamily = target.families.get(key) as WritablePureSelectorFamily<
|
|
19
19
|
ReturnType<Core[`toJSON`]>,
|
|
20
|
-
Key
|
|
20
|
+
Key,
|
|
21
|
+
never
|
|
21
22
|
>
|
|
22
23
|
return jsonFamily
|
|
23
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MutableAtomFamilyToken } from "atom.io"
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { RegularAtomFamily } from ".."
|
|
5
5
|
import { newest } from "../lineage"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
import type { SignalFrom, Transceiver } from "./transceiver"
|
|
@@ -12,11 +12,13 @@ export const getUpdateFamily = <
|
|
|
12
12
|
>(
|
|
13
13
|
mutableAtomFamily: MutableAtomFamilyToken<T, K>,
|
|
14
14
|
store: Store,
|
|
15
|
-
):
|
|
15
|
+
): RegularAtomFamily<SignalFrom<T>, K, never> => {
|
|
16
16
|
const target = newest(store)
|
|
17
17
|
const key = `*${mutableAtomFamily.key}`
|
|
18
|
-
const updateFamily
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const updateFamily = target.families.get(key) as RegularAtomFamily<
|
|
19
|
+
SignalFrom<T>,
|
|
20
|
+
K,
|
|
21
|
+
never
|
|
22
|
+
>
|
|
21
23
|
return updateFamily
|
|
22
24
|
}
|
|
@@ -18,7 +18,11 @@ export class FamilyTracker<
|
|
|
18
18
|
public readonly mutableAtoms: MutableAtomFamily<T, K>
|
|
19
19
|
|
|
20
20
|
public constructor(mutableAtoms: MutableAtomFamily<T, K>, store: RootStore) {
|
|
21
|
-
const latestSignalAtoms = createRegularAtomFamily<
|
|
21
|
+
const latestSignalAtoms = createRegularAtomFamily<
|
|
22
|
+
SignalFrom<T> | null,
|
|
23
|
+
K,
|
|
24
|
+
never
|
|
25
|
+
>(
|
|
22
26
|
store,
|
|
23
27
|
{
|
|
24
28
|
key: `*${mutableAtoms.key}`,
|
|
@@ -31,7 +31,11 @@ export class Tracker<T extends Transceiver<any, any, any>> {
|
|
|
31
31
|
subKey: mutableState.family.subKey,
|
|
32
32
|
}
|
|
33
33
|
: undefined
|
|
34
|
-
const latestSignalState = createRegularAtom<
|
|
34
|
+
const latestSignalState = createRegularAtom<
|
|
35
|
+
SignalFrom<T> | null,
|
|
36
|
+
any,
|
|
37
|
+
never
|
|
38
|
+
>(
|
|
35
39
|
store,
|
|
36
40
|
{
|
|
37
41
|
key: latestSignalStateKey,
|
|
@@ -8,7 +8,9 @@ export type OperationProgress =
|
|
|
8
8
|
| {
|
|
9
9
|
open: false
|
|
10
10
|
}
|
|
11
|
-
export type OpenOperation<
|
|
11
|
+
export type OpenOperation<
|
|
12
|
+
R extends ReadableToken<any, any> = ReadableToken<any, any>,
|
|
13
|
+
> = {
|
|
12
14
|
open: true
|
|
13
15
|
token: R
|
|
14
16
|
done: Set<string>
|
|
@@ -19,7 +21,7 @@ export type OpenOperation<R extends ReadableToken<any> = ReadableToken<any>> = {
|
|
|
19
21
|
|
|
20
22
|
export function openOperation(
|
|
21
23
|
store: Store,
|
|
22
|
-
token: ReadableToken<any>,
|
|
24
|
+
token: ReadableToken<any, any, any>,
|
|
23
25
|
): number | (Store & { operation: OpenOperation }) {
|
|
24
26
|
if (store.operation.open) {
|
|
25
27
|
const rejectionTime = performance.now()
|
|
@@ -2,7 +2,9 @@ import type {
|
|
|
2
2
|
FamilyMetadata,
|
|
3
3
|
ReadonlyPureSelectorOptions,
|
|
4
4
|
ReadonlyPureSelectorToken,
|
|
5
|
+
StateUpdate,
|
|
5
6
|
} from "atom.io"
|
|
7
|
+
import type { Canonical } from "atom.io/json"
|
|
6
8
|
|
|
7
9
|
import type { ReadonlyPureSelector, RootStore } from ".."
|
|
8
10
|
import { writeToCache } from "../caching"
|
|
@@ -11,13 +13,13 @@ import type { Store } from "../store"
|
|
|
11
13
|
import { Subject } from "../subject"
|
|
12
14
|
import { registerSelector } from "./register-selector"
|
|
13
15
|
|
|
14
|
-
export function createReadonlyPureSelector<T>(
|
|
16
|
+
export function createReadonlyPureSelector<T, K extends Canonical, E>(
|
|
15
17
|
store: Store,
|
|
16
|
-
options: ReadonlyPureSelectorOptions<T>,
|
|
17
|
-
family: FamilyMetadata | undefined,
|
|
18
|
-
): ReadonlyPureSelectorToken<T> {
|
|
18
|
+
options: ReadonlyPureSelectorOptions<T, E>,
|
|
19
|
+
family: FamilyMetadata<K> | undefined,
|
|
20
|
+
): ReadonlyPureSelectorToken<T, K, E> {
|
|
19
21
|
const target = newest(store)
|
|
20
|
-
const subject = new Subject<
|
|
22
|
+
const subject = new Subject<StateUpdate<E | T>>()
|
|
21
23
|
const covered = new Set<string>()
|
|
22
24
|
const key = options.key
|
|
23
25
|
const type = `readonly_pure_selector` as const
|
|
@@ -43,7 +45,7 @@ export function createReadonlyPureSelector<T>(
|
|
|
43
45
|
return cached
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
const readonlySelector: ReadonlyPureSelector<T> = {
|
|
48
|
+
const readonlySelector: ReadonlyPureSelector<T, E> = {
|
|
47
49
|
...options,
|
|
48
50
|
type,
|
|
49
51
|
subject,
|
|
@@ -23,26 +23,26 @@ export function createStandaloneSelector<T extends object>(
|
|
|
23
23
|
store: Store,
|
|
24
24
|
options: ReadonlyHeldSelectorOptions<T>,
|
|
25
25
|
): ReadonlyHeldSelectorToken<T>
|
|
26
|
-
export function createStandaloneSelector<T>(
|
|
26
|
+
export function createStandaloneSelector<T, E>(
|
|
27
27
|
store: Store,
|
|
28
|
-
options: WritablePureSelectorOptions<T>,
|
|
29
|
-
): WritablePureSelectorToken<T>
|
|
30
|
-
export function createStandaloneSelector<T>(
|
|
28
|
+
options: WritablePureSelectorOptions<T, E>,
|
|
29
|
+
): WritablePureSelectorToken<T, any, E>
|
|
30
|
+
export function createStandaloneSelector<T, E>(
|
|
31
31
|
store: Store,
|
|
32
|
-
options: ReadonlyPureSelectorOptions<T>,
|
|
33
|
-
): ReadonlyPureSelectorToken<T>
|
|
32
|
+
options: ReadonlyPureSelectorOptions<T, E>,
|
|
33
|
+
): ReadonlyPureSelectorToken<T, any, E>
|
|
34
34
|
export function createStandaloneSelector(
|
|
35
35
|
store: Store,
|
|
36
36
|
options:
|
|
37
37
|
| ReadonlyHeldSelectorOptions<any>
|
|
38
|
-
| ReadonlyPureSelectorOptions<any>
|
|
38
|
+
| ReadonlyPureSelectorOptions<any, any>
|
|
39
39
|
| WritableHeldSelectorOptions<any>
|
|
40
|
-
| WritablePureSelectorOptions<any>,
|
|
40
|
+
| WritablePureSelectorOptions<any, any>,
|
|
41
41
|
):
|
|
42
42
|
| ReadonlyHeldSelectorToken<any>
|
|
43
|
-
| ReadonlyPureSelectorToken<any>
|
|
43
|
+
| ReadonlyPureSelectorToken<any, any, any>
|
|
44
44
|
| WritableHeldSelectorToken<any>
|
|
45
|
-
| WritablePureSelectorToken<any> {
|
|
45
|
+
| WritablePureSelectorToken<any, any, any> {
|
|
46
46
|
const isWritable = `set` in options
|
|
47
47
|
const isHeld = `const` in options
|
|
48
48
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FamilyMetadata,
|
|
3
|
+
StateUpdate,
|
|
3
4
|
WritablePureSelectorOptions,
|
|
4
5
|
WritablePureSelectorToken,
|
|
5
6
|
} from "atom.io"
|
|
7
|
+
import type { Canonical } from "atom.io/json"
|
|
6
8
|
|
|
7
9
|
import type { RootStore, WritablePureSelector } from ".."
|
|
8
10
|
import { writeToCache } from "../caching"
|
|
@@ -11,13 +13,13 @@ import type { Store } from "../store"
|
|
|
11
13
|
import { Subject } from "../subject"
|
|
12
14
|
import { registerSelector } from "./register-selector"
|
|
13
15
|
|
|
14
|
-
export function createWritablePureSelector<T>(
|
|
16
|
+
export function createWritablePureSelector<T, K extends Canonical, E>(
|
|
15
17
|
store: Store,
|
|
16
|
-
options: WritablePureSelectorOptions<T>,
|
|
17
|
-
family: FamilyMetadata | undefined,
|
|
18
|
-
): WritablePureSelectorToken<T> {
|
|
18
|
+
options: WritablePureSelectorOptions<T, E>,
|
|
19
|
+
family: FamilyMetadata<K> | undefined,
|
|
20
|
+
): WritablePureSelectorToken<T, K, E> {
|
|
19
21
|
const target = newest(store)
|
|
20
|
-
const subject = new Subject<
|
|
22
|
+
const subject = new Subject<StateUpdate<E | T>>()
|
|
21
23
|
const covered = new Set<string>()
|
|
22
24
|
const key = options.key
|
|
23
25
|
const type = `writable_pure_selector` as const
|
|
@@ -27,7 +29,7 @@ export function createWritablePureSelector<T>(
|
|
|
27
29
|
const { find, get, json } = setterToolkit
|
|
28
30
|
const getterToolkit = { find, get, json }
|
|
29
31
|
|
|
30
|
-
const getFrom = (innerTarget: Store): T => {
|
|
32
|
+
const getFrom = (innerTarget: Store): E | T => {
|
|
31
33
|
const upstreamStates = innerTarget.selectorGraph.getRelationEntries({
|
|
32
34
|
downstreamSelectorKey: key,
|
|
33
35
|
})
|
|
@@ -48,7 +50,7 @@ export function createWritablePureSelector<T>(
|
|
|
48
50
|
options.set(setterToolkit, newValue)
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const mySelector: WritablePureSelector<T> = {
|
|
53
|
+
const mySelector: WritablePureSelector<T, E> = {
|
|
52
54
|
...options,
|
|
53
55
|
type,
|
|
54
56
|
subject,
|
|
@@ -5,7 +5,7 @@ import { isChildStore, newest, withdraw } from ".."
|
|
|
5
5
|
|
|
6
6
|
export function disposeSelector(
|
|
7
7
|
store: Store,
|
|
8
|
-
selectorToken: SelectorToken<unknown>,
|
|
8
|
+
selectorToken: SelectorToken<unknown, any, any>,
|
|
9
9
|
): void {
|
|
10
10
|
const target = newest(store)
|
|
11
11
|
const { key, type, family: familyMeta } = selectorToken
|
|
@@ -21,7 +21,7 @@ export function disposeSelector(
|
|
|
21
21
|
if (molecule) {
|
|
22
22
|
target.moleculeData.delete(familyMeta.subKey, familyMeta.key)
|
|
23
23
|
}
|
|
24
|
-
let familyToken: SelectorFamilyToken<any, any>
|
|
24
|
+
let familyToken: SelectorFamilyToken<any, any, any>
|
|
25
25
|
switch (selectorToken.type) {
|
|
26
26
|
case `writable_held_selector`:
|
|
27
27
|
{
|
|
@@ -33,8 +33,8 @@ export function registerSelector(
|
|
|
33
33
|
return {
|
|
34
34
|
get: (
|
|
35
35
|
...params:
|
|
36
|
-
| [ReadableFamilyToken<any, any>, Canonical]
|
|
37
|
-
| [ReadableToken<any>]
|
|
36
|
+
| [ReadableFamilyToken<any, any, any>, Canonical]
|
|
37
|
+
| [ReadableToken<any, any, any>]
|
|
38
38
|
) => {
|
|
39
39
|
const target = newest(store)
|
|
40
40
|
const { token, family, subKey } = reduceReference(store, ...params)
|
|
@@ -6,10 +6,10 @@ export function traceRootSelectorAtoms(
|
|
|
6
6
|
store: Store,
|
|
7
7
|
selectorKey: string,
|
|
8
8
|
covered: Set<string> = new Set<string>(),
|
|
9
|
-
): Map<string, Atom<
|
|
9
|
+
): Map<string, Atom<any, any>> {
|
|
10
10
|
const dependencies = getSelectorDependencyKeys(store, selectorKey)
|
|
11
11
|
|
|
12
|
-
const roots = new Map<string, Atom<unknown>>()
|
|
12
|
+
const roots = new Map<string, Atom<unknown, unknown>>()
|
|
13
13
|
|
|
14
14
|
while (dependencies.length > 0) {
|
|
15
15
|
// biome-ignore lint/style/noNonNullAssertion: just checked length ^^^
|
|
@@ -19,7 +19,7 @@ export function traceRootSelectorAtoms(
|
|
|
19
19
|
}
|
|
20
20
|
covered.add(dependencyKey)
|
|
21
21
|
if (isAtomKey(store, dependencyKey)) {
|
|
22
|
-
const atom = store.atoms.get(dependencyKey) as Atom<unknown>
|
|
22
|
+
const atom = store.atoms.get(dependencyKey) as Atom<unknown, unknown>
|
|
23
23
|
roots.set(atom.key, atom)
|
|
24
24
|
} else {
|
|
25
25
|
dependencies.push(...getSelectorDependencyKeys(store, dependencyKey))
|
|
@@ -12,7 +12,7 @@ export function updateSelectorAtoms(
|
|
|
12
12
|
| `writable_held_selector`
|
|
13
13
|
| `writable_pure_selector`,
|
|
14
14
|
selectorKey: string,
|
|
15
|
-
dependency: ReadableToken<unknown>,
|
|
15
|
+
dependency: ReadableToken<unknown, any, unknown>,
|
|
16
16
|
covered: Set<string>,
|
|
17
17
|
): void {
|
|
18
18
|
const target = newest(store)
|
|
@@ -17,12 +17,12 @@ import { isChildStore, isRootStore } from "../transaction"
|
|
|
17
17
|
import { evictDownstreamFromAtom } from "./evict-downstream"
|
|
18
18
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
19
19
|
|
|
20
|
-
export function dispatchOrDeferStateUpdate<T>(
|
|
20
|
+
export function dispatchOrDeferStateUpdate<T, E>(
|
|
21
21
|
target: Store & { operation: OpenOperation<any> },
|
|
22
|
-
state: WritableState<T>,
|
|
23
|
-
{ oldValue, newValue }: ProtoUpdate<T>,
|
|
22
|
+
state: WritableState<T, E>,
|
|
23
|
+
{ oldValue, newValue }: ProtoUpdate<E | T>,
|
|
24
24
|
stateIsNewlyCreated: boolean,
|
|
25
|
-
family?: WritableFamily<T, any>,
|
|
25
|
+
family?: WritableFamily<T, any, E>,
|
|
26
26
|
): void {
|
|
27
27
|
const token = deposit(state)
|
|
28
28
|
if (stateIsNewlyCreated && family) {
|
|
@@ -128,7 +128,11 @@ export function dispatchOrDeferStateUpdate<T>(
|
|
|
128
128
|
const mutable = target.atoms.get(keyOfMutable) as MutableAtom<
|
|
129
129
|
Transceiver<unknown, any, any>
|
|
130
130
|
>
|
|
131
|
-
const transceiver = readOrComputeValue
|
|
131
|
+
const transceiver = readOrComputeValue<Transceiver<any, any, any>, never>(
|
|
132
|
+
target,
|
|
133
|
+
mutable,
|
|
134
|
+
`mut`,
|
|
135
|
+
)
|
|
132
136
|
const accepted = transceiver.do(update.newValue) === null
|
|
133
137
|
if (accepted === true) {
|
|
134
138
|
evictDownstreamFromAtom(target, mutable)
|
|
@@ -4,7 +4,10 @@ import { newest } from "../lineage"
|
|
|
4
4
|
import { isDone, markDone } from "../operation"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
|
|
7
|
-
export function evictDownstreamFromAtom(
|
|
7
|
+
export function evictDownstreamFromAtom(
|
|
8
|
+
store: Store,
|
|
9
|
+
atom: Atom<any, any>,
|
|
10
|
+
): void {
|
|
8
11
|
const target = newest(store)
|
|
9
12
|
const { key, type } = atom
|
|
10
13
|
const downstreamKeys = target.selectorAtoms.getRelatedKeys(key)
|
|
@@ -18,25 +18,31 @@ export type ProtoUpdate<T> = { oldValue: T; newValue: T }
|
|
|
18
18
|
export const OWN_OP: unique symbol = Symbol(`OWN_OP`)
|
|
19
19
|
export const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)
|
|
20
20
|
|
|
21
|
-
export function operateOnStore<
|
|
21
|
+
export function operateOnStore<
|
|
22
|
+
T,
|
|
23
|
+
K extends Canonical,
|
|
24
|
+
New extends T,
|
|
25
|
+
Key extends K,
|
|
26
|
+
E,
|
|
27
|
+
>(
|
|
22
28
|
store: Store,
|
|
23
29
|
opMode: typeof JOIN_OP | typeof OWN_OP,
|
|
24
30
|
...params:
|
|
25
31
|
| [
|
|
26
|
-
token: WritableFamilyToken<T,
|
|
27
|
-
key:
|
|
32
|
+
token: WritableFamilyToken<T, K, E>,
|
|
33
|
+
key: Key,
|
|
28
34
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
29
35
|
]
|
|
30
36
|
| [
|
|
31
|
-
token: WritableToken<T>,
|
|
37
|
+
token: WritableToken<T, Key, E>,
|
|
32
38
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
33
39
|
]
|
|
34
40
|
): void {
|
|
35
|
-
let existingToken: WritableToken<T> | undefined
|
|
36
|
-
let brandNewToken: WritableToken<T> | undefined
|
|
37
|
-
let token: WritableToken<T>
|
|
38
|
-
let family: WritableFamily<T,
|
|
39
|
-
let key:
|
|
41
|
+
let existingToken: WritableToken<T, Key, E> | undefined
|
|
42
|
+
let brandNewToken: WritableToken<T, Key, E> | undefined
|
|
43
|
+
let token: WritableToken<T, Key, E>
|
|
44
|
+
let family: WritableFamily<T, K, E> | undefined
|
|
45
|
+
let key: Key | null
|
|
40
46
|
let value: New | typeof RESET_STATE | ((oldValue: T) => New)
|
|
41
47
|
if (params.length === 2) {
|
|
42
48
|
token = params[0]
|
|
@@ -116,7 +122,7 @@ export function operateOnStore<T, New extends T>(
|
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
const state = withdraw(target, token)
|
|
119
|
-
let protoUpdate: ProtoUpdate<T>
|
|
125
|
+
let protoUpdate: ProtoUpdate<E | T>
|
|
120
126
|
if (value === RESET_STATE) {
|
|
121
127
|
protoUpdate = resetAtomOrSelector(target, state)
|
|
122
128
|
} else {
|
|
@@ -5,10 +5,10 @@ import { dispatchOrDeferStateUpdate } from "./dispatch-state-update"
|
|
|
5
5
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
6
6
|
import { setAtom } from "./set-atom"
|
|
7
7
|
|
|
8
|
-
function resetAtom<T>(
|
|
8
|
+
function resetAtom<T, E>(
|
|
9
9
|
target: Store & { operation: OpenOperation },
|
|
10
|
-
atom: Atom<T>,
|
|
11
|
-
): ProtoUpdate<T> {
|
|
10
|
+
atom: Atom<T, E>,
|
|
11
|
+
): ProtoUpdate<E | T> {
|
|
12
12
|
switch (atom.type) {
|
|
13
13
|
case `mutable_atom`:
|
|
14
14
|
return setAtom(target, atom, new atom.class())
|
|
@@ -20,11 +20,11 @@ function resetAtom<T>(
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function resetAtomOrSelector<T>(
|
|
23
|
+
export function resetAtomOrSelector<T, E>(
|
|
24
24
|
target: Store & { operation: OpenOperation },
|
|
25
|
-
state: WritableState<T>,
|
|
26
|
-
): ProtoUpdate<T> {
|
|
27
|
-
let protoUpdate: ProtoUpdate<T>
|
|
25
|
+
state: WritableState<T, E>,
|
|
26
|
+
): ProtoUpdate<E | T> {
|
|
27
|
+
let protoUpdate: ProtoUpdate<E | T>
|
|
28
28
|
switch (state.type) {
|
|
29
29
|
case `atom`:
|
|
30
30
|
case `mutable_atom`:
|
|
@@ -6,26 +6,29 @@ import { setIntoStore } from "./set-into-store"
|
|
|
6
6
|
|
|
7
7
|
export const RESET_STATE: unique symbol = Symbol(`RESET`)
|
|
8
8
|
|
|
9
|
-
export function resetInStore(
|
|
9
|
+
export function resetInStore(
|
|
10
|
+
store: Store,
|
|
11
|
+
token: WritableToken<any, any, any>,
|
|
12
|
+
): void
|
|
10
13
|
|
|
11
14
|
export function resetInStore<K extends Canonical>(
|
|
12
15
|
store: Store,
|
|
13
|
-
token: WritableFamilyToken<any, K>,
|
|
16
|
+
token: WritableFamilyToken<any, K, any>,
|
|
14
17
|
key: K,
|
|
15
18
|
): void
|
|
16
19
|
|
|
17
20
|
export function resetInStore<T, K extends Canonical, Key extends K>(
|
|
18
21
|
store: Store,
|
|
19
22
|
...params:
|
|
20
|
-
| [token: WritableFamilyToken<T, K>, key: Key]
|
|
21
|
-
| [token: WritableToken<T>]
|
|
23
|
+
| [token: WritableFamilyToken<T, K, any>, key: Key]
|
|
24
|
+
| [token: WritableToken<T, any, any>]
|
|
22
25
|
): void
|
|
23
26
|
|
|
24
27
|
export function resetInStore<T, K extends Canonical, Key extends K>(
|
|
25
28
|
store: Store,
|
|
26
29
|
...params:
|
|
27
|
-
| [token: WritableFamilyToken<T, K>, key: Key]
|
|
28
|
-
| [token: WritableToken<T>]
|
|
30
|
+
| [token: WritableFamilyToken<T, K, any>, key: Key]
|
|
31
|
+
| [token: WritableToken<T, any, any>]
|
|
29
32
|
): void {
|
|
30
33
|
const subParams = [...params, RESET_STATE] as const
|
|
31
34
|
setIntoStore(store, ...subParams)
|
|
@@ -7,7 +7,7 @@ import { setSelector } from "./set-selector"
|
|
|
7
7
|
|
|
8
8
|
export const setAtomOrSelector = <T>(
|
|
9
9
|
target: Store & { operation: OpenOperation },
|
|
10
|
-
state: WritableState<T>,
|
|
10
|
+
state: WritableState<T, any>,
|
|
11
11
|
value: T | ((oldValue: T) => T),
|
|
12
12
|
): ProtoUpdate<T> => {
|
|
13
13
|
let protoUpdate: ProtoUpdate<T>
|
|
@@ -8,7 +8,7 @@ import type { ProtoUpdate } from "./operate-on-store"
|
|
|
8
8
|
|
|
9
9
|
export const setAtom = <T>(
|
|
10
10
|
target: Store & { operation: OpenOperation<any> },
|
|
11
|
-
atom: Atom<T>,
|
|
11
|
+
atom: Atom<T, any>,
|
|
12
12
|
next: T | ((oldValue: T) => T),
|
|
13
13
|
): ProtoUpdate<T> => {
|
|
14
14
|
const oldValue = readOrComputeValue(target, atom, `mut`)
|
|
@@ -5,9 +5,9 @@ import type { Store } from "../store"
|
|
|
5
5
|
import { operateOnStore, OWN_OP } from "./operate-on-store"
|
|
6
6
|
import type { RESET_STATE } from "./reset-in-store"
|
|
7
7
|
|
|
8
|
-
export function setIntoStore<T, New extends T>(
|
|
8
|
+
export function setIntoStore<T, New extends T, E>(
|
|
9
9
|
store: Store,
|
|
10
|
-
token: WritableToken<T>,
|
|
10
|
+
token: WritableToken<T, any, E>,
|
|
11
11
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
12
12
|
): void
|
|
13
13
|
|
|
@@ -16,9 +16,10 @@ export function setIntoStore<
|
|
|
16
16
|
K extends Canonical,
|
|
17
17
|
New extends T,
|
|
18
18
|
Key extends K,
|
|
19
|
+
E,
|
|
19
20
|
>(
|
|
20
21
|
store: Store,
|
|
21
|
-
token: WritableFamilyToken<T, K>,
|
|
22
|
+
token: WritableFamilyToken<T, K, E>,
|
|
22
23
|
key: Key,
|
|
23
24
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
24
25
|
): void
|
|
@@ -28,16 +29,17 @@ export function setIntoStore<
|
|
|
28
29
|
K extends Canonical,
|
|
29
30
|
New extends T,
|
|
30
31
|
Key extends K,
|
|
32
|
+
E,
|
|
31
33
|
>(
|
|
32
34
|
store: Store,
|
|
33
35
|
...params:
|
|
34
36
|
| [
|
|
35
|
-
token: WritableFamilyToken<T, K>,
|
|
37
|
+
token: WritableFamilyToken<T, K, E>,
|
|
36
38
|
key: Key,
|
|
37
39
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
38
40
|
]
|
|
39
41
|
| [
|
|
40
|
-
token: WritableToken<T>,
|
|
42
|
+
token: WritableToken<T, any, E>,
|
|
41
43
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
42
44
|
]
|
|
43
45
|
): void
|
|
@@ -47,16 +49,17 @@ export function setIntoStore<
|
|
|
47
49
|
K extends Canonical,
|
|
48
50
|
New extends T,
|
|
49
51
|
Key extends K,
|
|
52
|
+
E,
|
|
50
53
|
>(
|
|
51
54
|
store: Store,
|
|
52
55
|
...params:
|
|
53
56
|
| [
|
|
54
|
-
token: WritableFamilyToken<T, K>,
|
|
57
|
+
token: WritableFamilyToken<T, K, E>,
|
|
55
58
|
key: Key,
|
|
56
59
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
57
60
|
]
|
|
58
61
|
| [
|
|
59
|
-
token: WritableToken<T>,
|
|
62
|
+
token: WritableToken<T, any, E>,
|
|
60
63
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
61
64
|
]
|
|
62
65
|
): void {
|
|
@@ -7,7 +7,7 @@ import type { ProtoUpdate } from "./operate-on-store"
|
|
|
7
7
|
|
|
8
8
|
export function setSelector<T>(
|
|
9
9
|
target: Store & { operation: OpenOperation<any> },
|
|
10
|
-
selector: WritableSelector<T>,
|
|
10
|
+
selector: WritableSelector<T, any>,
|
|
11
11
|
next: T | ((oldValue: T) => T),
|
|
12
12
|
): ProtoUpdate<T> {
|
|
13
13
|
let oldValue: T
|