atom.io 0.33.2 → 0.33.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 +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 +111 -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 +10 -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 +155 -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 +2 -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 +1 -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 +2 -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 +19 -19
- 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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FamilyMetadata,
|
|
3
|
+
ReadonlyHeldSelectorFamilyOptions,
|
|
4
|
+
ReadonlyHeldSelectorFamilyToken,
|
|
5
|
+
ReadonlyHeldSelectorToken,
|
|
6
|
+
StateCreation,
|
|
7
|
+
StateDisposal,
|
|
8
|
+
} from "atom.io"
|
|
9
|
+
import type { Canonical } from "atom.io/json"
|
|
10
|
+
import { stringifyJson } from "atom.io/json"
|
|
11
|
+
|
|
12
|
+
import type { ReadonlyHeldSelectorFamily } from ".."
|
|
13
|
+
import { prettyPrintTokenType } from ".."
|
|
14
|
+
import { newest } from "../lineage"
|
|
15
|
+
import { createReadonlyHeldSelector } from "../selector"
|
|
16
|
+
import type { Store } from "../store"
|
|
17
|
+
import { Subject } from "../subject"
|
|
18
|
+
|
|
19
|
+
export function createReadonlyHeldSelectorFamily<
|
|
20
|
+
T extends object,
|
|
21
|
+
K extends Canonical,
|
|
22
|
+
>(
|
|
23
|
+
store: Store,
|
|
24
|
+
options: ReadonlyHeldSelectorFamilyOptions<T, K>,
|
|
25
|
+
internalRoles?: string[],
|
|
26
|
+
): ReadonlyHeldSelectorFamilyToken<T, K> {
|
|
27
|
+
const familyKey = options.key
|
|
28
|
+
const type = `readonly_held_selector_family`
|
|
29
|
+
|
|
30
|
+
const familyToken = {
|
|
31
|
+
key: familyKey,
|
|
32
|
+
type,
|
|
33
|
+
} as const satisfies ReadonlyHeldSelectorFamilyToken<T, K>
|
|
34
|
+
|
|
35
|
+
const existing = store.families.get(familyKey)
|
|
36
|
+
if (existing) {
|
|
37
|
+
store.logger.error(
|
|
38
|
+
`❗`,
|
|
39
|
+
type,
|
|
40
|
+
familyKey,
|
|
41
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
42
|
+
existing,
|
|
43
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const subject = new Subject<
|
|
48
|
+
| StateCreation<ReadonlyHeldSelectorToken<T>>
|
|
49
|
+
| StateDisposal<ReadonlyHeldSelectorToken<T>>
|
|
50
|
+
>()
|
|
51
|
+
|
|
52
|
+
const familyFunction = (key: K): ReadonlyHeldSelectorToken<T> => {
|
|
53
|
+
const subKey = stringifyJson(key)
|
|
54
|
+
const family: FamilyMetadata = { key: familyKey, subKey }
|
|
55
|
+
const fullKey = `${familyKey}(${subKey})`
|
|
56
|
+
const target = newest(store)
|
|
57
|
+
|
|
58
|
+
const token = createReadonlyHeldSelector(
|
|
59
|
+
target,
|
|
60
|
+
{
|
|
61
|
+
key: fullKey,
|
|
62
|
+
const: options.const(key),
|
|
63
|
+
get: options.get(key),
|
|
64
|
+
},
|
|
65
|
+
family,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
subject.next({ type: `state_creation`, token })
|
|
69
|
+
return token
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
73
|
+
internalRoles,
|
|
74
|
+
subject,
|
|
75
|
+
install: (s: Store) => createReadonlyHeldSelectorFamily(s, options),
|
|
76
|
+
default: options.const,
|
|
77
|
+
}) satisfies ReadonlyHeldSelectorFamily<T, K>
|
|
78
|
+
|
|
79
|
+
store.families.set(familyKey, readonlySelectorFamily)
|
|
80
|
+
return familyToken
|
|
81
|
+
}
|
|
@@ -2,9 +2,9 @@ import type {
|
|
|
2
2
|
FamilyMetadata,
|
|
3
3
|
findState,
|
|
4
4
|
getState,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
ReadonlyPureSelectorFamilyOptions,
|
|
6
|
+
ReadonlyPureSelectorFamilyToken,
|
|
7
|
+
ReadonlyPureSelectorToken,
|
|
8
8
|
StateCreation,
|
|
9
9
|
StateDisposal,
|
|
10
10
|
} from "atom.io"
|
|
@@ -16,29 +16,32 @@ import {
|
|
|
16
16
|
getFromStore,
|
|
17
17
|
getJsonToken,
|
|
18
18
|
prettyPrintTokenType,
|
|
19
|
-
type
|
|
19
|
+
type ReadonlyPureSelectorFamily,
|
|
20
20
|
} from ".."
|
|
21
21
|
import { newest } from "../lineage"
|
|
22
|
-
import {
|
|
22
|
+
import { createReadonlyPureSelector } from "../selector"
|
|
23
23
|
import type { Store } from "../store"
|
|
24
24
|
import { Subject } from "../subject"
|
|
25
25
|
|
|
26
|
-
export function
|
|
26
|
+
export function createReadonlyPureSelectorFamily<T, K extends Canonical>(
|
|
27
27
|
store: Store,
|
|
28
|
-
options:
|
|
28
|
+
options: ReadonlyPureSelectorFamilyOptions<T, K>,
|
|
29
29
|
internalRoles?: string[],
|
|
30
|
-
):
|
|
30
|
+
): ReadonlyPureSelectorFamilyToken<T, K> {
|
|
31
|
+
const familyKey = options.key
|
|
32
|
+
const type = `readonly_pure_selector_family`
|
|
33
|
+
|
|
31
34
|
const familyToken = {
|
|
32
|
-
key:
|
|
33
|
-
type
|
|
34
|
-
} as const satisfies
|
|
35
|
+
key: familyKey,
|
|
36
|
+
type,
|
|
37
|
+
} as const satisfies ReadonlyPureSelectorFamilyToken<T, K>
|
|
35
38
|
|
|
36
|
-
const existing = store.families.get(
|
|
39
|
+
const existing = store.families.get(familyKey)
|
|
37
40
|
if (existing) {
|
|
38
41
|
store.logger.error(
|
|
39
42
|
`❗`,
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
type,
|
|
44
|
+
familyKey,
|
|
42
45
|
`Overwriting an existing ${prettyPrintTokenType(
|
|
43
46
|
existing,
|
|
44
47
|
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
@@ -46,17 +49,17 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
const subject = new Subject<
|
|
49
|
-
| StateCreation<
|
|
50
|
-
| StateDisposal<
|
|
52
|
+
| StateCreation<ReadonlyPureSelectorToken<T>>
|
|
53
|
+
| StateDisposal<ReadonlyPureSelectorToken<T>>
|
|
51
54
|
>()
|
|
52
55
|
|
|
53
|
-
const familyFunction = (key: K):
|
|
56
|
+
const familyFunction = (key: K): ReadonlyPureSelectorToken<T> => {
|
|
54
57
|
const subKey = stringifyJson(key)
|
|
55
|
-
const family: FamilyMetadata = { key:
|
|
56
|
-
const fullKey = `${
|
|
58
|
+
const family: FamilyMetadata = { key: familyKey, subKey }
|
|
59
|
+
const fullKey = `${familyKey}(${subKey})`
|
|
57
60
|
const target = newest(store)
|
|
58
61
|
|
|
59
|
-
const token =
|
|
62
|
+
const token = createReadonlyPureSelector(
|
|
60
63
|
target,
|
|
61
64
|
{
|
|
62
65
|
key: fullKey,
|
|
@@ -72,7 +75,7 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
72
75
|
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
73
76
|
internalRoles,
|
|
74
77
|
subject,
|
|
75
|
-
install: (s: Store) =>
|
|
78
|
+
install: (s: Store) => createReadonlyPureSelectorFamily(s, options),
|
|
76
79
|
default: (key: K) => {
|
|
77
80
|
const getFn = options.get(key)
|
|
78
81
|
return getFn({
|
|
@@ -83,8 +86,8 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
83
86
|
json: (token) => getJsonToken(store, token),
|
|
84
87
|
})
|
|
85
88
|
},
|
|
86
|
-
}) satisfies
|
|
89
|
+
}) satisfies ReadonlyPureSelectorFamily<T, K>
|
|
87
90
|
|
|
88
|
-
store.families.set(
|
|
91
|
+
store.families.set(familyKey, readonlySelectorFamily)
|
|
89
92
|
return familyToken
|
|
90
93
|
}
|
|
@@ -1,34 +1,57 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
ReadonlyHeldSelectorFamilyOptions,
|
|
3
|
+
ReadonlyHeldSelectorFamilyToken,
|
|
4
|
+
ReadonlyPureSelectorFamilyOptions,
|
|
5
|
+
ReadonlyPureSelectorFamilyToken,
|
|
4
6
|
SelectorFamilyToken,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
WritableHeldSelectorFamilyOptions,
|
|
8
|
+
WritableHeldSelectorFamilyToken,
|
|
9
|
+
WritablePureSelectorFamilyOptions,
|
|
10
|
+
WritablePureSelectorFamilyToken,
|
|
7
11
|
} from "atom.io"
|
|
8
12
|
import type { Canonical } from "atom.io/json"
|
|
9
13
|
|
|
10
14
|
import type { Store } from "../store"
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
15
|
+
import { createReadonlyHeldSelectorFamily } from "./create-readonly-held-selector-family"
|
|
16
|
+
import { createReadonlyPureSelectorFamily } from "./create-readonly-pure-selector-family"
|
|
17
|
+
import { createWritableHeldSelectorFamily } from "./create-writable-held-selector-family"
|
|
18
|
+
import { createWritablePureSelectorFamily } from "./create-writable-pure-selector-family"
|
|
13
19
|
|
|
14
|
-
export function createSelectorFamily<T, K extends Canonical>(
|
|
20
|
+
export function createSelectorFamily<T extends object, K extends Canonical>(
|
|
21
|
+
store: Store,
|
|
22
|
+
options: WritableHeldSelectorFamilyOptions<T, K>,
|
|
23
|
+
): WritableHeldSelectorFamilyToken<T, K>
|
|
24
|
+
export function createSelectorFamily<T extends object, K extends Canonical>(
|
|
15
25
|
store: Store,
|
|
16
|
-
options:
|
|
17
|
-
):
|
|
26
|
+
options: ReadonlyHeldSelectorFamilyOptions<T, K>,
|
|
27
|
+
): ReadonlyHeldSelectorFamilyToken<T, K>
|
|
18
28
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
19
29
|
store: Store,
|
|
20
|
-
options:
|
|
21
|
-
):
|
|
30
|
+
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
31
|
+
): WritablePureSelectorFamilyToken<T, K>
|
|
22
32
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
33
|
+
store: Store,
|
|
34
|
+
options: ReadonlyPureSelectorFamilyOptions<T, K>,
|
|
35
|
+
): ReadonlyPureSelectorFamilyToken<T, K>
|
|
36
|
+
export function createSelectorFamily(
|
|
23
37
|
store: Store,
|
|
24
38
|
options:
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
39
|
+
| ReadonlyHeldSelectorFamilyOptions<any, any>
|
|
40
|
+
| ReadonlyPureSelectorFamilyOptions<any, any>
|
|
41
|
+
| WritableHeldSelectorFamilyOptions<any, any>
|
|
42
|
+
| WritablePureSelectorFamilyOptions<any, any>,
|
|
43
|
+
): SelectorFamilyToken<any, any> {
|
|
28
44
|
const isWritable = `set` in options
|
|
45
|
+
const isHeld = `const` in options
|
|
29
46
|
|
|
47
|
+
if (isHeld && isWritable) {
|
|
48
|
+
return createWritableHeldSelectorFamily(store, options, undefined)
|
|
49
|
+
}
|
|
50
|
+
if (isHeld) {
|
|
51
|
+
return createReadonlyHeldSelectorFamily(store, options, undefined)
|
|
52
|
+
}
|
|
30
53
|
if (isWritable) {
|
|
31
|
-
return
|
|
54
|
+
return createWritablePureSelectorFamily(store, options)
|
|
32
55
|
}
|
|
33
|
-
return
|
|
56
|
+
return createReadonlyPureSelectorFamily(store, options)
|
|
34
57
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FamilyMetadata,
|
|
3
|
+
StateCreation,
|
|
4
|
+
StateDisposal,
|
|
5
|
+
WritableHeldSelectorFamilyOptions,
|
|
6
|
+
WritableHeldSelectorFamilyToken,
|
|
7
|
+
WritableHeldSelectorToken,
|
|
8
|
+
} from "atom.io"
|
|
9
|
+
import type { Canonical } from "atom.io/json"
|
|
10
|
+
import { stringifyJson } from "atom.io/json"
|
|
11
|
+
|
|
12
|
+
import { prettyPrintTokenType, type WritableHeldSelectorFamily } from ".."
|
|
13
|
+
import { newest } from "../lineage"
|
|
14
|
+
import { createWritableHeldSelector } from "../selector"
|
|
15
|
+
import type { Store } from "../store"
|
|
16
|
+
import { Subject } from "../subject"
|
|
17
|
+
|
|
18
|
+
export function createWritableHeldSelectorFamily<
|
|
19
|
+
T extends object,
|
|
20
|
+
K extends Canonical,
|
|
21
|
+
>(
|
|
22
|
+
store: Store,
|
|
23
|
+
options: WritableHeldSelectorFamilyOptions<T, K>,
|
|
24
|
+
internalRoles?: string[],
|
|
25
|
+
): WritableHeldSelectorFamilyToken<T, K> {
|
|
26
|
+
const familyKey = options.key
|
|
27
|
+
const type = `writable_held_selector_family`
|
|
28
|
+
|
|
29
|
+
const familyToken = {
|
|
30
|
+
key: familyKey,
|
|
31
|
+
type,
|
|
32
|
+
} as const satisfies WritableHeldSelectorFamilyToken<T, K>
|
|
33
|
+
|
|
34
|
+
const existing = store.families.get(familyKey)
|
|
35
|
+
if (existing) {
|
|
36
|
+
store.logger.error(
|
|
37
|
+
`❗`,
|
|
38
|
+
type,
|
|
39
|
+
familyKey,
|
|
40
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
41
|
+
existing,
|
|
42
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
const subject = new Subject<
|
|
46
|
+
| StateCreation<WritableHeldSelectorToken<T>>
|
|
47
|
+
| StateDisposal<WritableHeldSelectorToken<T>>
|
|
48
|
+
>()
|
|
49
|
+
|
|
50
|
+
const familyFunction = (key: K): WritableHeldSelectorToken<T> => {
|
|
51
|
+
const subKey = stringifyJson(key)
|
|
52
|
+
const family: FamilyMetadata = { key: familyKey, subKey }
|
|
53
|
+
const fullKey = `${familyKey}(${subKey})`
|
|
54
|
+
const target = newest(store)
|
|
55
|
+
|
|
56
|
+
const token = createWritableHeldSelector(
|
|
57
|
+
target,
|
|
58
|
+
{
|
|
59
|
+
key: fullKey,
|
|
60
|
+
const: options.const(key),
|
|
61
|
+
get: options.get(key),
|
|
62
|
+
set: options.set(key),
|
|
63
|
+
},
|
|
64
|
+
family,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
subject.next({ type: `state_creation`, token })
|
|
68
|
+
return token
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const selectorFamily = Object.assign(familyFunction, familyToken, {
|
|
72
|
+
internalRoles,
|
|
73
|
+
subject,
|
|
74
|
+
install: (s: Store) => createWritableHeldSelectorFamily(s, options),
|
|
75
|
+
default: options.const,
|
|
76
|
+
}) satisfies WritableHeldSelectorFamily<T, K>
|
|
77
|
+
|
|
78
|
+
store.families.set(familyKey, selectorFamily)
|
|
79
|
+
return familyToken
|
|
80
|
+
}
|
|
@@ -4,9 +4,9 @@ import type {
|
|
|
4
4
|
getState,
|
|
5
5
|
StateCreation,
|
|
6
6
|
StateDisposal,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
WritablePureSelectorFamilyOptions,
|
|
8
|
+
WritablePureSelectorFamilyToken,
|
|
9
|
+
WritablePureSelectorToken,
|
|
10
10
|
} from "atom.io"
|
|
11
11
|
import type { Canonical } from "atom.io/json"
|
|
12
12
|
import { stringifyJson } from "atom.io/json"
|
|
@@ -16,46 +16,49 @@ import {
|
|
|
16
16
|
getFromStore,
|
|
17
17
|
getJsonToken,
|
|
18
18
|
prettyPrintTokenType,
|
|
19
|
-
type
|
|
19
|
+
type WritablePureSelectorFamily,
|
|
20
20
|
} from ".."
|
|
21
21
|
import { newest } from "../lineage"
|
|
22
|
-
import {
|
|
22
|
+
import { createWritablePureSelector } from "../selector"
|
|
23
23
|
import type { Store } from "../store"
|
|
24
24
|
import { Subject } from "../subject"
|
|
25
25
|
|
|
26
|
-
export function
|
|
26
|
+
export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
27
27
|
store: Store,
|
|
28
|
-
options:
|
|
28
|
+
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
29
29
|
internalRoles?: string[],
|
|
30
|
-
):
|
|
30
|
+
): WritablePureSelectorFamilyToken<T, K> {
|
|
31
|
+
const familyKey = options.key
|
|
32
|
+
const type = `writable_pure_selector_family`
|
|
33
|
+
|
|
31
34
|
const familyToken = {
|
|
32
|
-
key:
|
|
33
|
-
type
|
|
34
|
-
} as const satisfies
|
|
35
|
+
key: familyKey,
|
|
36
|
+
type,
|
|
37
|
+
} as const satisfies WritablePureSelectorFamilyToken<T, K>
|
|
35
38
|
|
|
36
|
-
const existing = store.families.get(
|
|
39
|
+
const existing = store.families.get(familyKey)
|
|
37
40
|
if (existing) {
|
|
38
41
|
store.logger.error(
|
|
39
42
|
`❗`,
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
type,
|
|
44
|
+
familyKey,
|
|
42
45
|
`Overwriting an existing ${prettyPrintTokenType(
|
|
43
46
|
existing,
|
|
44
47
|
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
45
48
|
)
|
|
46
49
|
}
|
|
47
50
|
const subject = new Subject<
|
|
48
|
-
| StateCreation<
|
|
49
|
-
| StateDisposal<
|
|
51
|
+
| StateCreation<WritablePureSelectorToken<T>>
|
|
52
|
+
| StateDisposal<WritablePureSelectorToken<T>>
|
|
50
53
|
>()
|
|
51
54
|
|
|
52
|
-
const familyFunction = (key: K):
|
|
55
|
+
const familyFunction = (key: K): WritablePureSelectorToken<T> => {
|
|
53
56
|
const subKey = stringifyJson(key)
|
|
54
|
-
const family: FamilyMetadata = { key:
|
|
55
|
-
const fullKey = `${
|
|
57
|
+
const family: FamilyMetadata = { key: familyKey, subKey }
|
|
58
|
+
const fullKey = `${familyKey}(${subKey})`
|
|
56
59
|
const target = newest(store)
|
|
57
60
|
|
|
58
|
-
const token =
|
|
61
|
+
const token = createWritablePureSelector(
|
|
59
62
|
target,
|
|
60
63
|
{
|
|
61
64
|
key: fullKey,
|
|
@@ -72,7 +75,7 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
72
75
|
const selectorFamily = Object.assign(familyFunction, familyToken, {
|
|
73
76
|
internalRoles,
|
|
74
77
|
subject,
|
|
75
|
-
install: (s: Store) =>
|
|
78
|
+
install: (s: Store) => createWritablePureSelectorFamily(s, options),
|
|
76
79
|
default: (key: K) => {
|
|
77
80
|
const getFn = options.get(key)
|
|
78
81
|
return getFn({
|
|
@@ -83,8 +86,8 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
83
86
|
json: (token) => getJsonToken(store, token),
|
|
84
87
|
})
|
|
85
88
|
},
|
|
86
|
-
}) satisfies
|
|
89
|
+
}) satisfies WritablePureSelectorFamily<T, K>
|
|
87
90
|
|
|
88
|
-
store.families.set(
|
|
91
|
+
store.families.set(familyKey, selectorFamily)
|
|
89
92
|
return familyToken
|
|
90
93
|
}
|
|
@@ -45,8 +45,10 @@ export function disposeFromStore(
|
|
|
45
45
|
case `mutable_atom`:
|
|
46
46
|
disposeAtom(store, token)
|
|
47
47
|
break
|
|
48
|
-
case `
|
|
49
|
-
case `
|
|
48
|
+
case `writable_pure_selector`:
|
|
49
|
+
case `readonly_pure_selector`:
|
|
50
|
+
case `writable_held_selector`:
|
|
51
|
+
case `readonly_held_selector`:
|
|
50
52
|
disposeSelector(store, token)
|
|
51
53
|
break
|
|
52
54
|
}
|
|
@@ -5,15 +5,15 @@ import type {
|
|
|
5
5
|
MutableAtomToken,
|
|
6
6
|
ReadableFamilyToken,
|
|
7
7
|
ReadableToken,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
ReadonlyPureSelectorFamilyToken,
|
|
9
|
+
ReadonlyPureSelectorToken,
|
|
10
10
|
RegularAtomFamilyToken,
|
|
11
11
|
RegularAtomToken,
|
|
12
12
|
SelectorFamilyToken,
|
|
13
13
|
SelectorToken,
|
|
14
14
|
WritableFamilyToken,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
WritablePureSelectorFamilyToken,
|
|
16
|
+
WritablePureSelectorToken,
|
|
17
17
|
WritableToken,
|
|
18
18
|
} from "atom.io"
|
|
19
19
|
import { type Canonical, type Json, stringifyJson } from "atom.io/json"
|
|
@@ -49,15 +49,15 @@ export function findInStore<T, K extends Canonical, Key extends K>(
|
|
|
49
49
|
|
|
50
50
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
51
51
|
store: Store,
|
|
52
|
-
token:
|
|
52
|
+
token: WritablePureSelectorFamilyToken<T, K>,
|
|
53
53
|
key: Key,
|
|
54
|
-
):
|
|
54
|
+
): WritablePureSelectorToken<T, K>
|
|
55
55
|
|
|
56
56
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
57
57
|
store: Store,
|
|
58
|
-
token:
|
|
58
|
+
token: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
59
59
|
key: Key,
|
|
60
|
-
):
|
|
60
|
+
): ReadonlyPureSelectorToken<T, K>
|
|
61
61
|
|
|
62
62
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
63
63
|
store: Store,
|
|
@@ -3,13 +3,13 @@ import type {
|
|
|
3
3
|
MutableAtomToken,
|
|
4
4
|
ReadableFamilyToken,
|
|
5
5
|
ReadableToken,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
ReadonlyPureSelectorFamilyToken,
|
|
7
|
+
ReadonlyPureSelectorToken,
|
|
8
8
|
RegularAtomFamilyToken,
|
|
9
9
|
RegularAtomToken,
|
|
10
10
|
WritableFamilyToken,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
WritablePureSelectorFamilyToken,
|
|
12
|
+
WritablePureSelectorToken,
|
|
13
13
|
WritableToken,
|
|
14
14
|
} from "atom.io"
|
|
15
15
|
import type { Canonical, Json } from "atom.io/json"
|
|
@@ -33,13 +33,13 @@ export function getFamilyOfToken<T, K extends Canonical>(
|
|
|
33
33
|
|
|
34
34
|
export function getFamilyOfToken<T, K extends Canonical>(
|
|
35
35
|
store: Store,
|
|
36
|
-
token:
|
|
37
|
-
):
|
|
36
|
+
token: WritablePureSelectorToken<T, K>,
|
|
37
|
+
): WritablePureSelectorFamilyToken<T, K> | undefined
|
|
38
38
|
|
|
39
39
|
export function getFamilyOfToken<T, K extends Canonical>(
|
|
40
40
|
store: Store,
|
|
41
|
-
token:
|
|
42
|
-
):
|
|
41
|
+
token: ReadonlyPureSelectorToken<T, K>,
|
|
42
|
+
): ReadonlyPureSelectorFamilyToken<T, K> | undefined
|
|
43
43
|
|
|
44
44
|
export function getFamilyOfToken<T, K extends Canonical>(
|
|
45
45
|
store: Store,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export * from "./create-atom-family"
|
|
2
|
-
export * from "./create-readonly-selector-family"
|
|
3
|
-
export * from "./create-readonly-selector-family"
|
|
2
|
+
export * from "./create-readonly-pure-selector-family"
|
|
3
|
+
export * from "./create-readonly-pure-selector-family"
|
|
4
4
|
export * from "./create-regular-atom-family"
|
|
5
5
|
export * from "./create-selector-family"
|
|
6
|
-
export * from "./create-writable-selector-family"
|
|
6
|
+
export * from "./create-writable-pure-selector-family"
|
|
7
7
|
export * from "./dispose-from-store"
|
|
8
8
|
export * from "./find-in-store"
|
|
9
9
|
export * from "./init-family-member"
|
|
@@ -5,15 +5,15 @@ import type {
|
|
|
5
5
|
MutableAtomToken,
|
|
6
6
|
ReadableFamilyToken,
|
|
7
7
|
ReadableToken,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
ReadonlyPureSelectorFamilyToken,
|
|
9
|
+
ReadonlyPureSelectorToken,
|
|
10
10
|
RegularAtomFamilyToken,
|
|
11
11
|
RegularAtomToken,
|
|
12
12
|
SelectorFamilyToken,
|
|
13
13
|
SelectorToken,
|
|
14
14
|
WritableFamilyToken,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
WritablePureSelectorFamilyToken,
|
|
16
|
+
WritablePureSelectorToken,
|
|
17
17
|
WritableToken,
|
|
18
18
|
} from "atom.io"
|
|
19
19
|
import type { Canonical, Json } from "atom.io/json"
|
|
@@ -49,15 +49,15 @@ export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
|
49
49
|
|
|
50
50
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
51
51
|
store: Store,
|
|
52
|
-
token:
|
|
52
|
+
token: WritablePureSelectorFamilyToken<T, K>,
|
|
53
53
|
key: Key,
|
|
54
|
-
):
|
|
54
|
+
): WritablePureSelectorToken<T, K>
|
|
55
55
|
|
|
56
56
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
57
57
|
store: Store,
|
|
58
|
-
token:
|
|
58
|
+
token: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
59
59
|
key: Key,
|
|
60
|
-
):
|
|
60
|
+
): ReadonlyPureSelectorToken<T, K>
|
|
61
61
|
|
|
62
62
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
63
63
|
store: Store,
|
|
@@ -95,8 +95,10 @@ export function initFamilyMemberInStore(
|
|
|
95
95
|
case `mutable_atom`:
|
|
96
96
|
store.on.atomCreation.next(state)
|
|
97
97
|
break
|
|
98
|
-
case `
|
|
99
|
-
case `
|
|
98
|
+
case `writable_pure_selector`:
|
|
99
|
+
case `readonly_pure_selector`:
|
|
100
|
+
case `writable_held_selector`:
|
|
101
|
+
case `readonly_held_selector`:
|
|
100
102
|
store.on.selectorCreation.next(state)
|
|
101
103
|
break
|
|
102
104
|
}
|
|
@@ -5,15 +5,15 @@ import type {
|
|
|
5
5
|
MutableAtomToken,
|
|
6
6
|
ReadableFamilyToken,
|
|
7
7
|
ReadableToken,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
ReadonlyPureSelectorFamilyToken,
|
|
9
|
+
ReadonlyPureSelectorToken,
|
|
10
10
|
RegularAtomFamilyToken,
|
|
11
11
|
RegularAtomToken,
|
|
12
12
|
SelectorFamilyToken,
|
|
13
13
|
SelectorToken,
|
|
14
14
|
WritableFamilyToken,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
WritablePureSelectorFamilyToken,
|
|
16
|
+
WritablePureSelectorToken,
|
|
17
17
|
WritableToken,
|
|
18
18
|
} from "atom.io"
|
|
19
19
|
import type { Canonical, Json } from "atom.io/json"
|
|
@@ -49,15 +49,15 @@ export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
|
49
49
|
|
|
50
50
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
51
51
|
store: Store,
|
|
52
|
-
token:
|
|
52
|
+
token: WritablePureSelectorFamilyToken<T, K>,
|
|
53
53
|
key: Key,
|
|
54
|
-
):
|
|
54
|
+
): WritablePureSelectorToken<T, K> | undefined
|
|
55
55
|
|
|
56
56
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
57
57
|
store: Store,
|
|
58
|
-
token:
|
|
58
|
+
token: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
59
59
|
key: Key,
|
|
60
|
-
):
|
|
60
|
+
): ReadonlyPureSelectorToken<T, K> | undefined
|
|
61
61
|
|
|
62
62
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
63
63
|
store: Store,
|
|
@@ -91,10 +91,12 @@ export function seekInStore(
|
|
|
91
91
|
case `mutable_atom_family`:
|
|
92
92
|
state = target.atoms.get(fullKey)
|
|
93
93
|
break
|
|
94
|
-
case `
|
|
95
|
-
|
|
94
|
+
case `writable_held_selector_family`:
|
|
95
|
+
case `writable_pure_selector_family`:
|
|
96
|
+
state = target.writableSelectors.get(fullKey)
|
|
96
97
|
break
|
|
97
|
-
case `
|
|
98
|
+
case `readonly_held_selector_family`:
|
|
99
|
+
case `readonly_pure_selector_family`:
|
|
98
100
|
state = target.readonlySelectors.get(fullKey)
|
|
99
101
|
break
|
|
100
102
|
}
|
|
@@ -50,11 +50,14 @@ export function getFromStore(
|
|
|
50
50
|
case `atom_family`:
|
|
51
51
|
case `mutable_atom_family`:
|
|
52
52
|
return store.defaults.get(family.key)
|
|
53
|
-
case `
|
|
54
|
-
case `
|
|
53
|
+
case `readonly_pure_selector_family`:
|
|
54
|
+
case `writable_pure_selector_family`:
|
|
55
|
+
case `readonly_held_selector_family`:
|
|
56
|
+
case `writable_held_selector_family`: {
|
|
55
57
|
if (store.defaults.has(family.key)) {
|
|
56
58
|
return store.defaults.get(token.family.key)
|
|
57
59
|
}
|
|
60
|
+
3
|
|
58
61
|
const defaultValue = withdraw(store, family).default(subKey)
|
|
59
62
|
store.defaults.set(family.key, defaultValue)
|
|
60
63
|
return defaultValue
|