atom.io 0.15.6 → 0.16.0
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/data/dist/index.cjs +20 -22
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +6 -6
- package/data/dist/index.js +21 -23
- package/data/dist/index.js.map +1 -1
- package/data/src/dict.ts +6 -7
- package/data/src/join.ts +23 -23
- package/data/src/struct-family.ts +2 -2
- package/data/src/struct.ts +4 -5
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +67 -60
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +910 -887
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +157 -162
- package/internal/dist/index.js +482 -458
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-regular-atom.ts +9 -12
- package/internal/src/atom/create-standalone-atom.ts +33 -0
- package/internal/src/atom/delete-atom.ts +5 -2
- package/internal/src/atom/index.ts +1 -16
- package/internal/src/atom/is-default.ts +0 -1
- package/internal/src/caching.ts +6 -3
- package/internal/src/families/create-atom-family.ts +11 -7
- package/internal/src/families/create-readonly-selector-family.ts +4 -3
- package/internal/src/families/create-regular-atom-family.ts +12 -27
- package/internal/src/families/create-selector-family.ts +13 -49
- package/internal/src/families/create-writable-selector-family.ts +51 -0
- package/internal/src/index.ts +44 -3
- package/internal/src/lineage.ts +0 -7
- package/internal/src/mutable/create-mutable-atom-family.ts +61 -15
- package/internal/src/mutable/create-mutable-atom.ts +70 -25
- package/internal/src/mutable/get-json-family.ts +4 -5
- package/internal/src/mutable/get-json-token.ts +6 -3
- package/internal/src/mutable/get-update-token.ts +3 -3
- package/internal/src/mutable/index.ts +1 -7
- package/internal/src/mutable/is-mutable.ts +6 -7
- package/internal/src/mutable/tracker-family.ts +4 -4
- package/internal/src/mutable/tracker.ts +6 -6
- package/internal/src/read-or-compute-value.ts +6 -3
- package/internal/src/selector/create-readonly-selector.ts +2 -3
- package/internal/src/selector/create-standalone-selector.ts +32 -0
- package/internal/src/selector/{create-read-write-selector.ts → create-writable-selector.ts} +12 -9
- package/internal/src/selector/delete-selector.ts +2 -2
- package/internal/src/selector/index.ts +3 -1
- package/internal/src/selector/trace-selector-atoms.ts +3 -2
- package/internal/src/selector/update-selector-atoms.ts +1 -1
- package/internal/src/set-state/copy-mutable-if-needed.ts +5 -6
- package/internal/src/set-state/copy-mutable-in-transaction.ts +4 -36
- package/internal/src/set-state/emit-update.ts +2 -3
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +3 -3
- package/internal/src/set-state/set-atom.ts +1 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/deposit.ts +25 -13
- package/internal/src/store/store.ts +21 -21
- package/internal/src/store/withdraw-new-family-member.ts +16 -9
- package/internal/src/store/withdraw.ts +43 -19
- package/internal/src/subscribe/recall-state.ts +2 -6
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +39 -41
- package/internal/src/subscribe/subscribe-to-state.ts +3 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +5 -5
- package/internal/src/timeline/create-timeline.ts +19 -22
- package/introspection/dist/index.cjs +4 -8
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +5 -5
- package/introspection/dist/index.js +5 -9
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +4 -5
- package/introspection/src/attach-selector-index.ts +4 -5
- package/introspection/src/attach-timeline-index.ts +6 -3
- package/introspection/src/attach-transaction-index.ts +6 -3
- package/introspection/src/index.ts +9 -5
- package/json/dist/index.cjs +3 -4
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.ts +4 -3
- package/json/dist/index.js +4 -5
- package/json/dist/index.js.map +1 -1
- package/json/src/select-json-family.ts +24 -4
- package/json/src/select-json.ts +3 -4
- package/package.json +2 -2
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.ts +9 -9
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateIndex.tsx +18 -10
- package/react-devtools/src/TimelineIndex.tsx +6 -2
- package/react-devtools/src/TransactionIndex.tsx +2 -2
- package/realtime-client/dist/index.cjs +27 -13
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +6 -4
- package/realtime-client/dist/index.js +20 -7
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +4 -3
- package/realtime-client/src/server-action.ts +2 -55
- package/realtime-client/src/sync-server-action.ts +75 -0
- package/realtime-react/dist/index.cjs +22 -13
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +3 -1
- package/realtime-react/dist/index.js +20 -12
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +1 -0
- package/realtime-react/src/use-server-action.ts +2 -4
- package/realtime-react/src/use-sync-server-action.ts +19 -0
- package/realtime-server/dist/index.cjs +83 -81
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +8 -8
- package/realtime-server/dist/index.js +58 -56
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +15 -1
- package/realtime-server/src/{hook-composition/receive-transaction.ts → realtime-action-receiver.ts} +6 -2
- package/realtime-server/src/{hook-composition/sync-transaction.ts → realtime-action-synchronizer.ts} +10 -43
- package/realtime-server/src/{hook-composition/expose-family.ts → realtime-family-provider.ts} +9 -23
- package/realtime-server/src/{hook-composition/expose-mutable-family.ts → realtime-mutable-family-provider.ts} +4 -4
- package/realtime-server/src/{hook-composition/expose-mutable.ts → realtime-mutable-provider.ts} +4 -5
- package/realtime-server/src/realtime-server-store.ts +39 -0
- package/realtime-server/src/{hook-composition/expose-single.ts → realtime-state-provider.ts} +7 -8
- package/realtime-server/src/{hook-composition/receive-state.ts → realtime-state-receiver.ts} +7 -4
- package/src/atom.ts +39 -24
- package/src/find-state.ts +20 -19
- package/src/index.ts +41 -28
- package/src/logger.ts +1 -0
- package/src/selector.ts +31 -16
- package/src/silo.ts +45 -6
- package/src/subscribe.ts +1 -0
- package/src/validators.ts +35 -25
- package/internal/src/atom/create-atom.ts +0 -21
- package/internal/src/mutable/get-update-family.ts +0 -23
- package/internal/src/selector/create-selector.ts +0 -65
- package/realtime-server/src/hook-composition/index.ts +0 -15
- /package/realtime-client/src/{pull.ts → pull-state.ts} +0 -0
- /package/realtime-client/src/{push.ts → push-state.ts} +0 -0
- /package/realtime-client/src/{realtime-state.ts → realtime-client-store.ts} +0 -0
package/realtime-server/src/{hook-composition/expose-single.ts → realtime-state-provider.ts}
RENAMED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as AtomIO from "atom.io"
|
|
2
|
-
import
|
|
2
|
+
import { IMPLICIT, subscribeToState } from "atom.io/internal"
|
|
3
3
|
import type { Json } from "atom.io/json"
|
|
4
4
|
|
|
5
|
-
import type { ServerConfig } from "
|
|
5
|
+
import type { ServerConfig } from "."
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
export const useExposeSingle = ({
|
|
7
|
+
export function realtimeStateProvider({
|
|
9
8
|
socket,
|
|
10
|
-
store =
|
|
11
|
-
}: ServerConfig)
|
|
12
|
-
return function
|
|
9
|
+
store = IMPLICIT.STORE,
|
|
10
|
+
}: ServerConfig) {
|
|
11
|
+
return function stateProvider<J extends Json.Serializable>(
|
|
13
12
|
token: AtomIO.WritableToken<J>,
|
|
14
13
|
): () => void {
|
|
15
14
|
let unsubscribeFromStateUpdates: (() => void) | null = null
|
|
@@ -22,7 +21,7 @@ export const useExposeSingle = ({
|
|
|
22
21
|
|
|
23
22
|
const fillSubRequest = () => {
|
|
24
23
|
socket.emit(`serve:${token.key}`, AtomIO.getState(token, store))
|
|
25
|
-
unsubscribeFromStateUpdates =
|
|
24
|
+
unsubscribeFromStateUpdates = subscribeToState(
|
|
26
25
|
token,
|
|
27
26
|
({ newValue }) => {
|
|
28
27
|
socket.emit(`serve:${token.key}`, newValue)
|
package/realtime-server/src/{hook-composition/receive-state.ts → realtime-state-receiver.ts}
RENAMED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { setState } from "atom.io"
|
|
2
2
|
import type { WritableToken } from "atom.io"
|
|
3
|
+
import { IMPLICIT } from "atom.io/internal"
|
|
3
4
|
import type { Json } from "atom.io/json"
|
|
4
5
|
|
|
5
|
-
import type { ServerConfig } from "
|
|
6
|
+
import type { ServerConfig } from "."
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export function realtimeStateReceiver({
|
|
9
|
+
socket,
|
|
10
|
+
store = IMPLICIT.STORE,
|
|
11
|
+
}: ServerConfig) {
|
|
12
|
+
return function stateReceiver<J extends Json.Serializable>(
|
|
10
13
|
token: WritableToken<J>,
|
|
11
14
|
): () => void {
|
|
12
15
|
const publish = (newValue: J) => setState(token, newValue, store)
|
package/src/atom.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Store, Subject, Transceiver } from "atom.io/internal"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
IMPLICIT,
|
|
4
|
+
createAtomFamily,
|
|
5
|
+
createStandaloneAtom,
|
|
6
|
+
} from "atom.io/internal"
|
|
3
7
|
import type { Json, JsonInterface } from "atom.io/json"
|
|
4
8
|
|
|
5
|
-
import type { AtomToken, MutableAtomToken } from "."
|
|
9
|
+
import type { AtomToken, MutableAtomToken, RegularAtomToken } from "."
|
|
6
10
|
|
|
7
11
|
export type Effectors<T> = {
|
|
8
12
|
setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void
|
|
@@ -11,7 +15,7 @@ export type Effectors<T> = {
|
|
|
11
15
|
|
|
12
16
|
export type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void
|
|
13
17
|
|
|
14
|
-
export type
|
|
18
|
+
export type RegularAtomOptions<T> = {
|
|
15
19
|
key: string
|
|
16
20
|
default: T | (() => T)
|
|
17
21
|
effects?: AtomEffect<T>[]
|
|
@@ -19,7 +23,7 @@ export type AtomOptions<T> = {
|
|
|
19
23
|
// biome-ignore format: complex intersection
|
|
20
24
|
export type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> =
|
|
21
25
|
& JsonInterface<T, J>
|
|
22
|
-
& Omit<
|
|
26
|
+
& Omit<RegularAtomOptions<T>, `default`>
|
|
23
27
|
& {
|
|
24
28
|
default: () => T
|
|
25
29
|
mutable: true
|
|
@@ -28,31 +32,31 @@ export type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serial
|
|
|
28
32
|
export function atom<T extends Transceiver<any>, J extends Json.Serializable>(
|
|
29
33
|
options: MutableAtomOptions<T, J>,
|
|
30
34
|
): MutableAtomToken<T, J>
|
|
31
|
-
export function atom<T>(options:
|
|
35
|
+
export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
|
|
32
36
|
export function atom(
|
|
33
|
-
options:
|
|
37
|
+
options: MutableAtomOptions<any, any> | RegularAtomOptions<any>,
|
|
34
38
|
): AtomToken<any> {
|
|
35
|
-
return
|
|
39
|
+
return createStandaloneAtom(options, IMPLICIT.STORE)
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
export type
|
|
42
|
+
export type RegularAtomFamilyOptions<T, K extends Json.Serializable> = {
|
|
39
43
|
key: string
|
|
40
44
|
default: T | ((key: K) => T)
|
|
41
45
|
effects?: (key: K) => AtomEffect<T>[]
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
export type
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
export type RegularAtomFamily<
|
|
49
|
+
T,
|
|
50
|
+
K extends Json.Serializable = Json.Serializable,
|
|
51
|
+
> = ((key: K) => RegularAtomToken<T>) & {
|
|
47
52
|
key: string
|
|
48
53
|
type: `atom_family`
|
|
49
|
-
subject: Subject<
|
|
50
|
-
mutable?: boolean
|
|
54
|
+
subject: Subject<RegularAtomToken<T>>
|
|
51
55
|
install: (store: Store) => void
|
|
52
56
|
__T?: T
|
|
53
57
|
__K?: K
|
|
54
58
|
}
|
|
55
|
-
export type
|
|
59
|
+
export type RegularAtomFamilyToken<T, K extends Json.Serializable> = {
|
|
56
60
|
key: string
|
|
57
61
|
type: `atom_family`
|
|
58
62
|
__T?: T
|
|
@@ -65,9 +69,13 @@ export type MutableAtomFamilyOptions<
|
|
|
65
69
|
J extends Json.Serializable,
|
|
66
70
|
K extends Json.Serializable,
|
|
67
71
|
> =
|
|
68
|
-
& AtomFamilyOptions<T, K>
|
|
69
72
|
& JsonInterface<T, J>
|
|
70
|
-
& {
|
|
73
|
+
& {
|
|
74
|
+
key: string
|
|
75
|
+
default: (key: K) => T
|
|
76
|
+
effects?: (key: K) => AtomEffect<T>[]
|
|
77
|
+
mutable: true,
|
|
78
|
+
}
|
|
71
79
|
|
|
72
80
|
// biome-ignore format: intersection
|
|
73
81
|
export type MutableAtomFamily<
|
|
@@ -79,9 +87,8 @@ export type MutableAtomFamily<
|
|
|
79
87
|
& ((key: K) => MutableAtomToken<T, J>)
|
|
80
88
|
& {
|
|
81
89
|
key: string
|
|
82
|
-
type: `
|
|
90
|
+
type: `mutable_atom_family`
|
|
83
91
|
subject: Subject<MutableAtomToken<T, J>>
|
|
84
|
-
mutable: true
|
|
85
92
|
install: (store: Store) => void
|
|
86
93
|
__T?: T
|
|
87
94
|
__J?: J
|
|
@@ -93,23 +100,31 @@ export type MutableAtomFamilyToken<
|
|
|
93
100
|
K extends Json.Serializable,
|
|
94
101
|
> = {
|
|
95
102
|
key: string
|
|
96
|
-
type: `
|
|
97
|
-
mutable: true
|
|
103
|
+
type: `mutable_atom_family`
|
|
98
104
|
__T?: T
|
|
99
105
|
__J?: J
|
|
100
106
|
__K?: K
|
|
101
107
|
}
|
|
102
108
|
|
|
109
|
+
export type AtomFamily<T, K extends Json.Serializable = Json.Serializable> =
|
|
110
|
+
| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>
|
|
111
|
+
| RegularAtomFamily<T, K>
|
|
112
|
+
export type AtomFamilyToken<T, K extends Json.Serializable = Json.Serializable> =
|
|
113
|
+
| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>
|
|
114
|
+
| RegularAtomFamilyToken<T, K>
|
|
115
|
+
|
|
103
116
|
export function atomFamily<
|
|
104
117
|
T extends Transceiver<any>,
|
|
105
118
|
J extends Json.Serializable,
|
|
106
119
|
K extends Json.Serializable,
|
|
107
120
|
>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>
|
|
108
121
|
export function atomFamily<T, K extends Json.Serializable>(
|
|
109
|
-
options:
|
|
110
|
-
):
|
|
122
|
+
options: RegularAtomFamilyOptions<T, K>,
|
|
123
|
+
): RegularAtomFamily<T, K>
|
|
111
124
|
export function atomFamily<T, K extends Json.Serializable>(
|
|
112
|
-
options:
|
|
113
|
-
|
|
125
|
+
options:
|
|
126
|
+
| MutableAtomFamilyOptions<any, any, any>
|
|
127
|
+
| RegularAtomFamilyOptions<T, K>,
|
|
128
|
+
): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {
|
|
114
129
|
return createAtomFamily(options, IMPLICIT.STORE)
|
|
115
130
|
}
|
package/src/find-state.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
AtomFamilyToken,
|
|
3
|
-
AtomToken,
|
|
4
2
|
MutableAtomFamilyToken,
|
|
5
3
|
MutableAtomToken,
|
|
6
4
|
ReadableFamilyToken,
|
|
7
5
|
ReadableToken,
|
|
8
6
|
ReadonlySelectorFamilyToken,
|
|
9
7
|
ReadonlySelectorToken,
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
RegularAtomFamilyToken,
|
|
9
|
+
RegularAtomToken,
|
|
12
10
|
WritableFamilyToken,
|
|
11
|
+
WritableSelectorFamilyToken,
|
|
12
|
+
WritableSelectorToken,
|
|
13
13
|
WritableToken,
|
|
14
14
|
} from "atom.io"
|
|
15
15
|
import type { Store, Transceiver } from "atom.io/internal"
|
|
@@ -34,26 +34,27 @@ export function findState<
|
|
|
34
34
|
T extends Transceiver<any>,
|
|
35
35
|
J extends Json.Serializable,
|
|
36
36
|
K extends Json.Serializable,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
Key extends K,
|
|
38
|
+
>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>
|
|
39
|
+
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
40
|
+
token: RegularAtomFamilyToken<T, K>,
|
|
41
|
+
key: Key,
|
|
42
|
+
): RegularAtomToken<T>
|
|
43
|
+
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
44
|
+
token: WritableSelectorFamilyToken<T, K>,
|
|
45
|
+
key: Key,
|
|
46
|
+
): WritableSelectorToken<T>
|
|
47
|
+
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
47
48
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
48
|
-
key:
|
|
49
|
+
key: Key,
|
|
49
50
|
): ReadonlySelectorToken<T>
|
|
50
|
-
export function findState<T, K extends Json.Serializable>(
|
|
51
|
+
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
51
52
|
token: WritableFamilyToken<T, K>,
|
|
52
|
-
key:
|
|
53
|
+
key: Key,
|
|
53
54
|
): WritableToken<T>
|
|
54
|
-
export function findState<T, K extends Json.Serializable>(
|
|
55
|
+
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
55
56
|
token: ReadableFamilyToken<T, K>,
|
|
56
|
-
key:
|
|
57
|
+
key: Key,
|
|
57
58
|
): ReadableToken<T>
|
|
58
59
|
export function findState(
|
|
59
60
|
token: ReadableFamilyToken<any, any>,
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { Transceiver } from "atom.io/internal"
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
AtomFamily,
|
|
5
|
+
AtomFamilyToken,
|
|
6
|
+
RegularAtomFamily,
|
|
7
|
+
RegularAtomFamilyToken,
|
|
8
|
+
} from "./atom"
|
|
4
9
|
import type {
|
|
5
10
|
ReadonlySelectorFamily,
|
|
6
11
|
ReadonlySelectorFamilyToken,
|
|
7
12
|
SelectorFamily,
|
|
8
13
|
SelectorFamilyToken,
|
|
14
|
+
WritableSelectorFamily,
|
|
15
|
+
WritableSelectorFamilyToken,
|
|
9
16
|
} from "./selector"
|
|
10
17
|
|
|
11
18
|
export * from "./atom"
|
|
@@ -23,51 +30,57 @@ export * from "./validators"
|
|
|
23
30
|
|
|
24
31
|
export type ƒn = (...parameters: any[]) => any
|
|
25
32
|
|
|
26
|
-
export type
|
|
33
|
+
export type RegularAtomToken<T> = {
|
|
27
34
|
key: string
|
|
28
35
|
type: `atom`
|
|
29
36
|
family?: FamilyMetadata
|
|
30
|
-
|
|
37
|
+
__T?: T
|
|
31
38
|
}
|
|
32
|
-
export
|
|
39
|
+
export type MutableAtomToken<
|
|
33
40
|
T extends Transceiver<any>,
|
|
34
41
|
J extends Json.Serializable,
|
|
35
|
-
>
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
> = {
|
|
43
|
+
key: string
|
|
44
|
+
type: `mutable_atom`
|
|
45
|
+
family?: FamilyMetadata
|
|
46
|
+
__J?: J
|
|
47
|
+
__U?: T extends Transceiver<infer Update> ? Update : never
|
|
38
48
|
}
|
|
39
|
-
export type
|
|
49
|
+
export type AtomToken<T> =
|
|
50
|
+
| MutableAtomToken<T extends Transceiver<any> ? T : never, any>
|
|
51
|
+
| RegularAtomToken<T>
|
|
52
|
+
|
|
53
|
+
export type WritableSelectorToken<T> = {
|
|
40
54
|
key: string
|
|
41
55
|
type: `selector`
|
|
42
56
|
family?: FamilyMetadata
|
|
43
|
-
|
|
57
|
+
__T?: T
|
|
58
|
+
}
|
|
59
|
+
export type ReadonlySelectorToken<T> = {
|
|
60
|
+
key: string
|
|
61
|
+
type: `readonly_selector`
|
|
62
|
+
family?: FamilyMetadata
|
|
63
|
+
__T?: T
|
|
44
64
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export type WritableToken<T> = AtomToken<T> |
|
|
50
|
-
export type ReadableToken<T> =
|
|
65
|
+
export type SelectorToken<T> =
|
|
66
|
+
| ReadonlySelectorToken<T>
|
|
67
|
+
| WritableSelectorToken<T>
|
|
68
|
+
|
|
69
|
+
export type WritableToken<T> = AtomToken<T> | WritableSelectorToken<T>
|
|
70
|
+
export type ReadableToken<T> = AtomToken<T> | SelectorToken<T>
|
|
51
71
|
|
|
52
72
|
export type WritableFamily<T, K extends Json.Serializable> =
|
|
53
73
|
| AtomFamily<T, K>
|
|
54
|
-
|
|
|
74
|
+
| WritableSelectorFamily<T, K>
|
|
55
75
|
export type ReadableFamily<T, K extends Json.Serializable> =
|
|
56
|
-
|
|
|
57
|
-
|
|
|
76
|
+
| AtomFamily<T, K>
|
|
77
|
+
| SelectorFamily<T, K>
|
|
58
78
|
|
|
59
79
|
export type WritableFamilyToken<T, K extends Json.Serializable> =
|
|
60
80
|
| AtomFamilyToken<T, K>
|
|
61
|
-
|
|
|
81
|
+
| WritableSelectorFamilyToken<T, K>
|
|
62
82
|
export type ReadableFamilyToken<T, K extends Json.Serializable> =
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
66
|
-
export type ReadonlySelectorToken<_> = {
|
|
67
|
-
key: string
|
|
68
|
-
type: `readonly_selector`
|
|
69
|
-
family?: FamilyMetadata
|
|
70
|
-
__brand?: _
|
|
71
|
-
}
|
|
83
|
+
| AtomFamilyToken<T, K>
|
|
84
|
+
| SelectorFamilyToken<T, K>
|
|
72
85
|
|
|
73
86
|
export type FamilyMetadata = { key: string; subKey: string }
|
package/src/logger.ts
CHANGED
package/src/selector.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { Store, Subject } from "atom.io/internal"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
IMPLICIT,
|
|
4
|
+
createSelectorFamily,
|
|
5
|
+
createStandaloneSelector,
|
|
6
|
+
} from "atom.io/internal"
|
|
3
7
|
import type { Json } from "atom.io/json"
|
|
4
8
|
|
|
5
|
-
import type { ReadonlySelectorToken,
|
|
9
|
+
import type { ReadonlySelectorToken, WritableSelectorToken } from "."
|
|
6
10
|
import type { Read, Write } from "./transaction"
|
|
7
11
|
|
|
8
|
-
export type
|
|
12
|
+
export type WritableSelectorOptions<T> = {
|
|
9
13
|
key: string
|
|
10
14
|
get: Read<() => T>
|
|
11
15
|
set: Write<(newValue: T) => void>
|
|
@@ -15,17 +19,19 @@ export type ReadonlySelectorOptions<T> = {
|
|
|
15
19
|
get: Read<() => T>
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
export function selector<T>(
|
|
22
|
+
export function selector<T>(
|
|
23
|
+
options: WritableSelectorOptions<T>,
|
|
24
|
+
): WritableSelectorToken<T>
|
|
19
25
|
export function selector<T>(
|
|
20
26
|
options: ReadonlySelectorOptions<T>,
|
|
21
27
|
): ReadonlySelectorToken<T>
|
|
22
28
|
export function selector<T>(
|
|
23
|
-
options: ReadonlySelectorOptions<T> |
|
|
24
|
-
): ReadonlySelectorToken<T> |
|
|
25
|
-
return
|
|
29
|
+
options: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,
|
|
30
|
+
): ReadonlySelectorToken<T> | WritableSelectorToken<T> {
|
|
31
|
+
return createStandaloneSelector(options, IMPLICIT.STORE)
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
export type
|
|
34
|
+
export type WritableSelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
29
35
|
key: string
|
|
30
36
|
get: (key: K) => Read<() => T>
|
|
31
37
|
set: (key: K) => Write<(newValue: T) => void>
|
|
@@ -35,18 +41,18 @@ export type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
|
35
41
|
get: (key: K) => Read<() => T>
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
export type
|
|
44
|
+
export type WritableSelectorFamily<
|
|
39
45
|
T,
|
|
40
46
|
K extends Json.Serializable = Json.Serializable,
|
|
41
|
-
> = ((key: K) =>
|
|
47
|
+
> = ((key: K) => WritableSelectorToken<T>) & {
|
|
42
48
|
key: string
|
|
43
49
|
type: `selector_family`
|
|
44
|
-
subject: Subject<
|
|
50
|
+
subject: Subject<WritableSelectorToken<T>>
|
|
45
51
|
install: (store: Store) => void
|
|
46
52
|
__T?: T
|
|
47
53
|
__K?: K
|
|
48
54
|
}
|
|
49
|
-
export type
|
|
55
|
+
export type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {
|
|
50
56
|
key: string
|
|
51
57
|
type: `selector_family`
|
|
52
58
|
__T?: T
|
|
@@ -71,14 +77,23 @@ export type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {
|
|
|
71
77
|
__K?: K
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
export type SelectorFamily<T, K extends Json.Serializable> =
|
|
81
|
+
| ReadonlySelectorFamily<T, K>
|
|
82
|
+
| WritableSelectorFamily<T, K>
|
|
83
|
+
export type SelectorFamilyToken<T, K extends Json.Serializable> =
|
|
84
|
+
| ReadonlySelectorFamilyToken<T, K>
|
|
85
|
+
| WritableSelectorFamilyToken<T, K>
|
|
86
|
+
|
|
74
87
|
export function selectorFamily<T, K extends Json.Serializable>(
|
|
75
|
-
options:
|
|
76
|
-
):
|
|
88
|
+
options: WritableSelectorFamilyOptions<T, K>,
|
|
89
|
+
): WritableSelectorFamily<T, K>
|
|
77
90
|
export function selectorFamily<T, K extends Json.Serializable>(
|
|
78
91
|
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
79
92
|
): ReadonlySelectorFamily<T, K>
|
|
80
93
|
export function selectorFamily<T, K extends Json.Serializable>(
|
|
81
|
-
options:
|
|
82
|
-
|
|
94
|
+
options:
|
|
95
|
+
| ReadonlySelectorFamilyOptions<T, K>
|
|
96
|
+
| WritableSelectorFamilyOptions<T, K>,
|
|
97
|
+
): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {
|
|
83
98
|
return createSelectorFamily(options, IMPLICIT.STORE)
|
|
84
99
|
}
|
package/src/silo.ts
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
|
+
import type { Transceiver } from "atom.io/internal"
|
|
1
2
|
import {
|
|
2
3
|
Store,
|
|
3
|
-
createAtom,
|
|
4
4
|
createAtomFamily,
|
|
5
|
-
createSelector,
|
|
6
5
|
createSelectorFamily,
|
|
6
|
+
createStandaloneAtom,
|
|
7
|
+
createStandaloneSelector,
|
|
7
8
|
createTimeline,
|
|
8
9
|
createTransaction,
|
|
9
10
|
timeTravel,
|
|
10
11
|
} from "atom.io/internal"
|
|
12
|
+
import type { Json } from "atom.io/json"
|
|
11
13
|
|
|
12
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
AtomToken,
|
|
16
|
+
MutableAtomFamily,
|
|
17
|
+
MutableAtomFamilyOptions,
|
|
18
|
+
MutableAtomOptions,
|
|
19
|
+
MutableAtomToken,
|
|
20
|
+
RegularAtomFamily,
|
|
21
|
+
RegularAtomFamilyOptions,
|
|
22
|
+
RegularAtomOptions,
|
|
23
|
+
RegularAtomToken,
|
|
24
|
+
redo,
|
|
25
|
+
timeline,
|
|
26
|
+
undo,
|
|
27
|
+
} from "."
|
|
13
28
|
import { getState, setState, subscribe } from "."
|
|
14
29
|
import type { atom, atomFamily } from "./atom"
|
|
15
30
|
import type { selector, selectorFamily } from "./selector"
|
|
@@ -30,10 +45,34 @@ export class Silo {
|
|
|
30
45
|
public redo: typeof redo
|
|
31
46
|
public constructor(name: string, fromStore: Store | null = null) {
|
|
32
47
|
const s = new Store(name, fromStore)
|
|
48
|
+
function _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
|
|
49
|
+
function _atom<T extends Transceiver<any>, J extends Json.Serializable>(
|
|
50
|
+
options: MutableAtomOptions<T, J>,
|
|
51
|
+
): MutableAtomToken<T, J>
|
|
52
|
+
function _atom<T>(
|
|
53
|
+
options: MutableAtomOptions<any, any> | RegularAtomOptions<T>,
|
|
54
|
+
): AtomToken<T> {
|
|
55
|
+
return createStandaloneAtom(options, s)
|
|
56
|
+
}
|
|
57
|
+
function _atomFamily<
|
|
58
|
+
T extends Transceiver<any>,
|
|
59
|
+
J extends Json.Serializable,
|
|
60
|
+
K extends Json.Serializable,
|
|
61
|
+
>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>
|
|
62
|
+
function _atomFamily<T, K extends Json.Serializable>(
|
|
63
|
+
options: RegularAtomFamilyOptions<T, K>,
|
|
64
|
+
): RegularAtomFamily<T, K>
|
|
65
|
+
function _atomFamily<T, K extends Json.Serializable>(
|
|
66
|
+
options:
|
|
67
|
+
| MutableAtomFamilyOptions<any, any, any>
|
|
68
|
+
| RegularAtomFamilyOptions<T, K>,
|
|
69
|
+
): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {
|
|
70
|
+
return createAtomFamily(options, s)
|
|
71
|
+
}
|
|
33
72
|
this.store = s
|
|
34
|
-
this.atom =
|
|
35
|
-
this.atomFamily =
|
|
36
|
-
this.selector = (options) =>
|
|
73
|
+
this.atom = _atom
|
|
74
|
+
this.atomFamily = _atomFamily
|
|
75
|
+
this.selector = (options) => createStandaloneSelector(options, s) as any
|
|
37
76
|
this.selectorFamily = (options) => createSelectorFamily(options, s) as any
|
|
38
77
|
this.transaction = (options) => createTransaction(options, s)
|
|
39
78
|
this.timeline = (options) => createTimeline(options, s)
|
package/src/subscribe.ts
CHANGED
package/src/validators.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
MutableAtomFamily,
|
|
3
|
+
MutableAtomToken,
|
|
4
4
|
ReadableFamily,
|
|
5
5
|
ReadableToken,
|
|
6
6
|
ReadonlySelectorFamily,
|
|
7
7
|
ReadonlySelectorToken,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
RegularAtomFamily,
|
|
9
|
+
RegularAtomToken,
|
|
10
10
|
WritableFamily,
|
|
11
|
+
WritableSelectorFamily,
|
|
12
|
+
WritableSelectorToken,
|
|
11
13
|
WritableToken,
|
|
12
14
|
} from "atom.io"
|
|
13
15
|
|
|
@@ -19,56 +21,64 @@ export type TokenType<
|
|
|
19
21
|
? RepresentedValue
|
|
20
22
|
: never
|
|
21
23
|
|
|
22
|
-
export function isToken<KnownToken extends
|
|
24
|
+
export function isToken<KnownToken extends RegularAtomToken<any>>(
|
|
23
25
|
knownToken: KnownToken,
|
|
24
|
-
unknownToken: ReadableToken<
|
|
25
|
-
): unknownToken is
|
|
26
|
-
export function isToken<KnownToken extends
|
|
26
|
+
unknownToken: ReadableToken<any>,
|
|
27
|
+
): unknownToken is RegularAtomToken<TokenType<KnownToken>>
|
|
28
|
+
export function isToken<KnownToken extends MutableAtomToken<any, any>>(
|
|
27
29
|
knownToken: KnownToken,
|
|
28
|
-
unknownToken: ReadableToken<
|
|
29
|
-
): unknownToken is
|
|
30
|
+
unknownToken: ReadableToken<any>,
|
|
31
|
+
): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>
|
|
32
|
+
export function isToken<KnownToken extends WritableSelectorToken<any>>(
|
|
33
|
+
knownToken: KnownToken,
|
|
34
|
+
unknownToken: ReadableToken<any>,
|
|
35
|
+
): unknownToken is WritableSelectorToken<TokenType<KnownToken>>
|
|
30
36
|
export function isToken<KnownToken extends ReadonlySelectorToken<any>>(
|
|
31
37
|
knownToken: KnownToken,
|
|
32
|
-
unknownToken: ReadableToken<
|
|
38
|
+
unknownToken: ReadableToken<any>,
|
|
33
39
|
): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>
|
|
34
40
|
export function isToken<KnownToken extends WritableToken<any>>(
|
|
35
41
|
knownToken: KnownToken,
|
|
36
|
-
unknownToken: ReadableToken<
|
|
42
|
+
unknownToken: ReadableToken<any>,
|
|
37
43
|
): unknownToken is WritableToken<TokenType<KnownToken>>
|
|
38
|
-
export function isToken<KnownToken extends
|
|
44
|
+
export function isToken<KnownToken extends ReadableToken<any>>(
|
|
39
45
|
knownToken: KnownToken,
|
|
40
|
-
unknownToken: ReadableToken<
|
|
46
|
+
unknownToken: ReadableToken<any>,
|
|
41
47
|
): unknownToken is ReadableToken<TokenType<KnownToken>>
|
|
42
48
|
export function isToken<KnownToken extends ReadableToken<any>>(
|
|
43
49
|
knownToken: KnownToken,
|
|
44
|
-
unknownToken: ReadableToken<
|
|
50
|
+
unknownToken: ReadableToken<any>,
|
|
45
51
|
): unknownToken is ReadableToken<TokenType<KnownToken>> {
|
|
46
52
|
return knownToken.key === unknownToken.key
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
export function belongsTo<Family extends
|
|
55
|
+
export function belongsTo<Family extends RegularAtomFamily<any, any>>(
|
|
56
|
+
family: Family,
|
|
57
|
+
unknownToken: ReadableToken<any>,
|
|
58
|
+
): unknownToken is RegularAtomToken<TokenType<Family>>
|
|
59
|
+
export function belongsTo<Family extends MutableAtomFamily<any, any, any>>(
|
|
50
60
|
family: Family,
|
|
51
|
-
unknownToken: ReadableToken<
|
|
52
|
-
): unknownToken is
|
|
53
|
-
export function belongsTo<Family extends
|
|
61
|
+
unknownToken: ReadableToken<any>,
|
|
62
|
+
): unknownToken is MutableAtomToken<TokenType<Family>, any>
|
|
63
|
+
export function belongsTo<Family extends WritableSelectorFamily<any, any>>(
|
|
54
64
|
family: Family,
|
|
55
|
-
unknownToken: ReadableToken<
|
|
56
|
-
): unknownToken is
|
|
65
|
+
unknownToken: ReadableToken<any>,
|
|
66
|
+
): unknownToken is WritableSelectorToken<TokenType<Family>>
|
|
57
67
|
export function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(
|
|
58
68
|
family: Family,
|
|
59
|
-
unknownToken: ReadableToken<
|
|
69
|
+
unknownToken: ReadableToken<any>,
|
|
60
70
|
): unknownToken is ReadonlySelectorToken<TokenType<Family>>
|
|
61
71
|
export function belongsTo<Family extends WritableFamily<any, any>>(
|
|
62
72
|
family: Family,
|
|
63
|
-
unknownToken: ReadableToken<
|
|
73
|
+
unknownToken: ReadableToken<any>,
|
|
64
74
|
): unknownToken is WritableToken<TokenType<Family>>
|
|
65
75
|
export function belongsTo<Family extends ReadableFamily<any, any>>(
|
|
66
76
|
family: Family,
|
|
67
|
-
unknownToken: ReadableToken<
|
|
77
|
+
unknownToken: ReadableToken<any>,
|
|
68
78
|
): unknownToken is ReadableToken<TokenType<Family>>
|
|
69
79
|
export function belongsTo<Family extends ReadableFamily<any, any>>(
|
|
70
80
|
family: Family,
|
|
71
|
-
unknownToken: ReadableToken<
|
|
81
|
+
unknownToken: ReadableToken<any>,
|
|
72
82
|
): unknownToken is ReadableToken<TokenType<Family>> {
|
|
73
83
|
return family.key === unknownToken.family?.key
|
|
74
84
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AtomOptions,
|
|
3
|
-
AtomToken,
|
|
4
|
-
FamilyMetadata,
|
|
5
|
-
MutableAtomOptions,
|
|
6
|
-
} from "atom.io"
|
|
7
|
-
|
|
8
|
-
import { createMutableAtom } from "../mutable"
|
|
9
|
-
import type { Store } from "../store"
|
|
10
|
-
import { createRegularAtom } from "./create-regular-atom"
|
|
11
|
-
|
|
12
|
-
export function createAtom<T>(
|
|
13
|
-
options: AtomOptions<T> | MutableAtomOptions<any, any>,
|
|
14
|
-
family: FamilyMetadata | undefined,
|
|
15
|
-
store: Store,
|
|
16
|
-
): AtomToken<T> {
|
|
17
|
-
if (`mutable` in options) {
|
|
18
|
-
return createMutableAtom(options, family, store)
|
|
19
|
-
}
|
|
20
|
-
return createRegularAtom<T>(options, family, store)
|
|
21
|
-
}
|