atom.io 0.27.4 → 0.28.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.d.ts +31 -29
- package/data/dist/index.js +65 -81
- package/data/src/dict.ts +9 -12
- package/data/src/join.ts +30 -33
- package/data/src/struct-family.ts +17 -23
- package/data/src/struct.ts +9 -12
- package/dist/{chunk-JRENM6KL.js → chunk-BX3MTH2Z.js} +482 -385
- package/dist/chunk-D52JNVER.js +721 -0
- package/dist/chunk-EUVKUTW3.js +89 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +35 -53
- package/ephemeral/dist/index.js +1 -1
- package/ephemeral/src/find-state.ts +1 -1
- package/immortal/dist/index.js +2 -2
- package/immortal/src/seek-state.ts +2 -2
- package/internal/dist/index.d.ts +141 -87
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/create-standalone-atom.ts +7 -5
- package/internal/src/atom/dispose-atom.ts +2 -9
- package/internal/src/families/create-atom-family.ts +5 -5
- package/internal/src/families/create-readonly-selector-family.ts +20 -9
- package/internal/src/families/create-regular-atom-family.ts +15 -6
- package/internal/src/families/create-selector-family.ts +5 -5
- package/internal/src/families/create-writable-selector-family.ts +20 -10
- package/internal/src/families/dispose-from-store.ts +43 -29
- package/internal/src/families/find-in-store.ts +28 -18
- package/internal/src/families/init-family-member.ts +9 -9
- package/internal/src/families/seek-in-store.ts +10 -10
- package/internal/src/get-state/get-from-store.ts +70 -47
- package/internal/src/ingest-updates/ingest-atom-update.ts +1 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +15 -6
- package/internal/src/molecule/create-molecule-family.ts +1 -1
- package/internal/src/molecule/dispose-molecule.ts +7 -18
- package/internal/src/molecule/grow-molecule-in-store.ts +1 -1
- package/internal/src/molecule/make-molecule-in-store.ts +5 -5
- package/internal/src/mutable/create-mutable-atom-family.ts +15 -6
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +2 -2
- package/internal/src/mutable/tracker-family.ts +3 -3
- package/internal/src/mutable/tracker.ts +14 -18
- package/internal/src/pretty-print.ts +1 -16
- package/internal/src/selector/create-readonly-selector.ts +2 -2
- package/internal/src/selector/create-standalone-selector.ts +5 -5
- package/internal/src/selector/create-writable-selector.ts +2 -2
- package/internal/src/selector/dispose-selector.ts +2 -9
- package/internal/src/selector/register-selector.ts +9 -9
- package/internal/src/set-state/set-into-store.ts +23 -33
- package/internal/src/store/circular-buffer.ts +34 -0
- package/internal/src/store/counterfeit.ts +109 -0
- package/internal/src/store/deposit.ts +67 -13
- package/internal/src/store/index.ts +1 -0
- package/internal/src/store/store.ts +4 -1
- package/internal/src/store/withdraw.ts +15 -10
- package/internal/src/subscribe/index.ts +2 -0
- package/internal/src/subscribe/subscribe-in-store.ts +62 -0
- package/internal/src/timeline/time-travel.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +7 -6
- package/introspection/dist/index.d.ts +84 -4
- package/introspection/dist/index.js +1 -413
- package/introspection/src/attach-atom-index.ts +5 -8
- package/introspection/src/attach-introspection-states.ts +7 -4
- package/introspection/src/attach-selector-index.ts +6 -8
- package/introspection/src/attach-timeline-family.ts +25 -28
- package/introspection/src/attach-timeline-index.ts +5 -8
- package/introspection/src/attach-transaction-index.ts +5 -8
- package/introspection/src/attach-transaction-logs.ts +21 -27
- package/introspection/src/attach-type-selectors.ts +26 -0
- package/introspection/src/differ.ts +167 -0
- package/introspection/src/index.ts +2 -0
- package/introspection/src/refinery.ts +100 -0
- package/json/dist/index.d.ts +31 -30
- package/json/dist/index.js +2 -80
- package/json/src/entries.ts +6 -0
- package/json/src/index.ts +47 -6
- package/json/src/select-json-family.ts +4 -4
- package/json/src/select-json.ts +6 -9
- package/package.json +17 -8
- package/react/dist/index.js +7 -7
- package/react/src/parse-state-overloads.ts +2 -2
- package/react/src/use-i.ts +1 -1
- package/react/src/use-json.ts +2 -2
- package/react/src/use-o.ts +2 -2
- package/react-devtools/dist/index.d.ts +1 -91
- package/react-devtools/dist/index.js +285 -414
- package/react-devtools/src/AtomIODevtools.tsx +2 -2
- package/react-devtools/src/StateEditor.tsx +20 -12
- package/react-devtools/src/StateIndex.tsx +8 -26
- package/react-devtools/src/TimelineIndex.tsx +3 -3
- package/react-devtools/src/TransactionIndex.tsx +6 -6
- package/react-devtools/src/Updates.tsx +1 -4
- package/react-devtools/src/index.ts +0 -71
- package/react-devtools/src/store.ts +51 -0
- package/realtime/dist/index.d.ts +7 -7
- package/realtime/dist/index.js +18 -22
- package/realtime/src/realtime-continuity.ts +27 -35
- package/realtime-client/dist/index.js +59 -65
- package/realtime-client/src/pull-atom-family-member.ts +1 -1
- package/realtime-client/src/pull-atom.ts +1 -1
- package/realtime-client/src/pull-mutable-atom-family-member.ts +3 -3
- package/realtime-client/src/pull-mutable-atom.ts +3 -3
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +6 -6
- package/realtime-client/src/sync-continuity.ts +55 -53
- package/realtime-react/dist/index.js +3 -3
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-server/dist/index.js +72 -36
- package/realtime-server/src/realtime-continuity-synchronizer.ts +57 -93
- package/realtime-server/src/realtime-family-provider.ts +3 -3
- package/realtime-server/src/realtime-mutable-family-provider.ts +5 -5
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-state-provider.ts +1 -1
- package/realtime-server/src/realtime-state-receiver.ts +1 -1
- package/realtime-testing/dist/index.d.ts +2 -0
- package/realtime-testing/dist/index.js +57 -15
- package/realtime-testing/src/setup-realtime-test.tsx +66 -16
- package/src/atom.ts +2 -2
- package/src/dispose-state.ts +2 -2
- package/src/get-state.ts +9 -13
- package/src/molecule.ts +1 -1
- package/src/selector.ts +2 -2
- package/src/set-state.ts +10 -7
- package/src/silo.ts +29 -55
- package/src/subscribe.ts +3 -23
- package/src/timeline.ts +2 -2
- package/web/dist/index.d.ts +9 -0
- package/{dist/chunk-H6EDLPKH.js → web/dist/index.js} +5 -4
- package/web/package.json +13 -0
- package/web/src/index.ts +1 -0
- package/web/src/persist-sync.ts +25 -0
- package/dist/chunk-AK23DRMD.js +0 -21
- package/dist/chunk-IW6WYRS7.js +0 -140
- package/internal/src/families/throw-in-case-of-conflicting-family.ts +0 -18
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AtomFamilyToken,
|
|
3
|
+
AtomToken,
|
|
4
|
+
MoleculeConstructor,
|
|
5
|
+
MoleculeFamilyToken,
|
|
6
|
+
MoleculeKey,
|
|
7
|
+
MoleculeToken,
|
|
8
|
+
MutableAtomFamilyToken,
|
|
9
|
+
MutableAtomToken,
|
|
10
|
+
ReadableFamilyToken,
|
|
11
|
+
ReadableToken,
|
|
12
|
+
ReadonlySelectorFamilyToken,
|
|
13
|
+
ReadonlySelectorToken,
|
|
14
|
+
RegularAtomFamilyToken,
|
|
15
|
+
RegularAtomToken,
|
|
16
|
+
SelectorFamilyToken,
|
|
17
|
+
SelectorToken,
|
|
18
|
+
WritableFamilyToken,
|
|
19
|
+
WritableSelectorFamilyToken,
|
|
20
|
+
WritableSelectorToken,
|
|
21
|
+
WritableToken,
|
|
22
|
+
} from "atom.io"
|
|
23
|
+
import type { Canonical, Json } from "atom.io/json"
|
|
24
|
+
import { stringifyJson } from "atom.io/json"
|
|
25
|
+
|
|
26
|
+
import type { Transceiver } from "../mutable"
|
|
27
|
+
|
|
28
|
+
export const FAMILY_MEMBER_TOKEN_TYPES = {
|
|
29
|
+
atom_family: `atom`,
|
|
30
|
+
mutable_atom_family: `mutable_atom`,
|
|
31
|
+
selector_family: `selector`,
|
|
32
|
+
readonly_selector_family: `readonly_selector`,
|
|
33
|
+
molecule_family: `molecule`,
|
|
34
|
+
} as const
|
|
35
|
+
|
|
36
|
+
export function counterfeit<
|
|
37
|
+
T extends Transceiver<any>,
|
|
38
|
+
J extends Json.Serializable,
|
|
39
|
+
K extends Canonical,
|
|
40
|
+
Key extends K,
|
|
41
|
+
>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>
|
|
42
|
+
|
|
43
|
+
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
44
|
+
token: RegularAtomFamilyToken<T, K>,
|
|
45
|
+
key: Key,
|
|
46
|
+
): RegularAtomToken<T>
|
|
47
|
+
|
|
48
|
+
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
49
|
+
token: AtomFamilyToken<T, K>,
|
|
50
|
+
key: Key,
|
|
51
|
+
): AtomToken<T>
|
|
52
|
+
|
|
53
|
+
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
54
|
+
token: WritableSelectorFamilyToken<T, K>,
|
|
55
|
+
key: Key,
|
|
56
|
+
): WritableSelectorToken<T>
|
|
57
|
+
|
|
58
|
+
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
59
|
+
token: ReadonlySelectorFamilyToken<T, K>,
|
|
60
|
+
key: Key,
|
|
61
|
+
): ReadonlySelectorToken<T>
|
|
62
|
+
|
|
63
|
+
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
64
|
+
token: SelectorFamilyToken<T, K>,
|
|
65
|
+
key: Key,
|
|
66
|
+
): SelectorToken<T>
|
|
67
|
+
|
|
68
|
+
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
69
|
+
token: WritableFamilyToken<T, K>,
|
|
70
|
+
key: Key,
|
|
71
|
+
): WritableToken<T>
|
|
72
|
+
|
|
73
|
+
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
74
|
+
token: ReadableFamilyToken<T, K>,
|
|
75
|
+
key: Key,
|
|
76
|
+
): ReadableToken<T>
|
|
77
|
+
|
|
78
|
+
export function counterfeit<M extends MoleculeConstructor>(
|
|
79
|
+
token: MoleculeFamilyToken<M>,
|
|
80
|
+
key: MoleculeKey<M>,
|
|
81
|
+
): MoleculeKey<M>
|
|
82
|
+
|
|
83
|
+
export function counterfeit(
|
|
84
|
+
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
85
|
+
key: Canonical,
|
|
86
|
+
): MoleculeToken<any> | ReadableToken<any> {
|
|
87
|
+
const subKey = stringifyJson(key)
|
|
88
|
+
const fullKey = `${token.key}(${subKey})`
|
|
89
|
+
const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
|
|
90
|
+
const stateToken = {
|
|
91
|
+
key: fullKey,
|
|
92
|
+
type,
|
|
93
|
+
} satisfies MoleculeToken<any> | ReadableToken<any>
|
|
94
|
+
if (type === `molecule`) {
|
|
95
|
+
Object.assign(stateToken, {
|
|
96
|
+
key,
|
|
97
|
+
family: token,
|
|
98
|
+
})
|
|
99
|
+
} else {
|
|
100
|
+
Object.assign(stateToken, {
|
|
101
|
+
family: {
|
|
102
|
+
key: token.key,
|
|
103
|
+
subKey,
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
Object.assign(stateToken, { counterfeit: true })
|
|
108
|
+
return stateToken
|
|
109
|
+
}
|
|
@@ -1,31 +1,47 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AtomFamilyToken,
|
|
2
3
|
AtomToken,
|
|
3
4
|
MoleculeConstructor,
|
|
4
5
|
MoleculeFamily,
|
|
5
6
|
MoleculeFamilyToken,
|
|
6
7
|
MoleculeToken,
|
|
8
|
+
MutableAtomFamilyToken,
|
|
7
9
|
MutableAtomToken,
|
|
10
|
+
ReadableFamilyToken,
|
|
8
11
|
ReadableToken,
|
|
12
|
+
ReadonlySelectorFamilyToken,
|
|
9
13
|
ReadonlySelectorToken,
|
|
14
|
+
RegularAtomFamilyToken,
|
|
10
15
|
RegularAtomToken,
|
|
16
|
+
SelectorFamilyToken,
|
|
11
17
|
SelectorToken,
|
|
12
18
|
TransactionToken,
|
|
19
|
+
WritableFamilyToken,
|
|
20
|
+
WritableSelectorFamilyToken,
|
|
13
21
|
WritableSelectorToken,
|
|
14
22
|
WritableToken,
|
|
15
23
|
} from "atom.io"
|
|
16
|
-
import type { Canonical } from "atom.io/json"
|
|
24
|
+
import type { Canonical, Json } from "atom.io/json"
|
|
17
25
|
|
|
18
26
|
import type {
|
|
19
27
|
Atom,
|
|
28
|
+
AtomFamily,
|
|
20
29
|
Func,
|
|
21
30
|
Molecule,
|
|
22
31
|
MutableAtom,
|
|
32
|
+
MutableAtomFamily,
|
|
33
|
+
ReadableFamily,
|
|
23
34
|
ReadableState,
|
|
24
35
|
ReadonlySelector,
|
|
36
|
+
ReadonlySelectorFamily,
|
|
25
37
|
RegularAtom,
|
|
38
|
+
RegularAtomFamily,
|
|
26
39
|
Selector,
|
|
40
|
+
SelectorFamily,
|
|
27
41
|
Transceiver,
|
|
42
|
+
WritableFamily,
|
|
28
43
|
WritableSelector,
|
|
44
|
+
WritableSelectorFamily,
|
|
29
45
|
WritableState,
|
|
30
46
|
} from ".."
|
|
31
47
|
import type { Transaction } from "../transaction"
|
|
@@ -39,37 +55,75 @@ export function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>
|
|
|
39
55
|
export function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>
|
|
40
56
|
export function deposit<T>(state: Selector<T>): SelectorToken<T>
|
|
41
57
|
export function deposit<T>(state: WritableState<T>): WritableToken<T>
|
|
58
|
+
export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
|
|
59
|
+
|
|
60
|
+
export function deposit<T, K extends Canonical>(
|
|
61
|
+
state: RegularAtomFamily<T, K>,
|
|
62
|
+
): RegularAtomFamilyToken<T, K>
|
|
63
|
+
export function deposit<
|
|
64
|
+
T extends Transceiver<any>,
|
|
65
|
+
J extends Json.Serializable,
|
|
66
|
+
K extends Canonical,
|
|
67
|
+
>(state: MutableAtomFamily<T, J, K>): MutableAtomFamilyToken<T, J, K>
|
|
68
|
+
export function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>
|
|
69
|
+
export function deposit<T>(
|
|
70
|
+
state: WritableSelectorFamily<T, any>,
|
|
71
|
+
): WritableSelectorFamilyToken<T, any>
|
|
72
|
+
export function deposit<T>(
|
|
73
|
+
state: ReadonlySelectorFamily<T, any>,
|
|
74
|
+
): ReadonlySelectorFamilyToken<T, any>
|
|
75
|
+
export function deposit<T>(
|
|
76
|
+
state: SelectorFamily<T, any>,
|
|
77
|
+
): SelectorFamilyToken<T, any>
|
|
78
|
+
export function deposit<T>(
|
|
79
|
+
state: WritableFamily<T, any>,
|
|
80
|
+
): WritableFamilyToken<T, any>
|
|
81
|
+
export function deposit<T>(
|
|
82
|
+
state: ReadableFamily<T, any>,
|
|
83
|
+
): ReadableFamilyToken<T, any>
|
|
84
|
+
|
|
42
85
|
export function deposit<M extends MoleculeConstructor>(
|
|
43
86
|
state: MoleculeFamily<M>,
|
|
44
87
|
): MoleculeFamilyToken<M>
|
|
45
88
|
export function deposit<M extends MoleculeConstructor>(
|
|
46
89
|
state: Molecule<M>,
|
|
47
90
|
): MoleculeToken<M>
|
|
91
|
+
|
|
48
92
|
export function deposit<T extends Func>(
|
|
49
93
|
state: Transaction<T>,
|
|
50
94
|
): TransactionToken<T>
|
|
51
|
-
|
|
95
|
+
|
|
52
96
|
export function deposit(
|
|
53
97
|
state: Molecule<any> | ReadableState<any>,
|
|
54
98
|
): MoleculeToken<any> | ReadableToken<any>
|
|
55
99
|
|
|
56
|
-
export function deposit
|
|
100
|
+
export function deposit(
|
|
101
|
+
state:
|
|
102
|
+
| Molecule<any>
|
|
103
|
+
| MoleculeFamily<any>
|
|
104
|
+
| ReadableFamily<any, any>
|
|
105
|
+
| ReadableState<any>
|
|
106
|
+
| Transaction<Func>,
|
|
107
|
+
):
|
|
108
|
+
| MoleculeFamilyToken<any>
|
|
109
|
+
| MoleculeToken<any>
|
|
110
|
+
| ReadableFamilyToken<any, any>
|
|
111
|
+
| ReadableToken<any>
|
|
112
|
+
| TransactionToken<Func>
|
|
113
|
+
|
|
114
|
+
export function deposit(
|
|
57
115
|
state:
|
|
58
116
|
| Molecule<any>
|
|
59
117
|
| MoleculeFamily<any>
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
| Transaction<T extends Func ? T : never>
|
|
64
|
-
| WritableSelector<T>
|
|
65
|
-
| (T extends Transceiver<any> ? MutableAtom<T, any> : never),
|
|
118
|
+
| ReadableFamily<any, any>
|
|
119
|
+
| ReadableState<any>
|
|
120
|
+
| Transaction<Func>,
|
|
66
121
|
):
|
|
67
122
|
| MoleculeFamilyToken<any>
|
|
68
123
|
| MoleculeToken<any>
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
| TransactionToken<T extends Func ? T : never> {
|
|
124
|
+
| ReadableFamilyToken<any, any>
|
|
125
|
+
| ReadableToken<any>
|
|
126
|
+
| TransactionToken<Func> {
|
|
73
127
|
const token = {
|
|
74
128
|
key: state.key,
|
|
75
129
|
type: state.type,
|
|
@@ -36,6 +36,7 @@ import type {
|
|
|
36
36
|
TransactionProgress,
|
|
37
37
|
} from "../transaction"
|
|
38
38
|
import { isRootStore } from "../transaction"
|
|
39
|
+
import { CircularBuffer } from "./circular-buffer"
|
|
39
40
|
|
|
40
41
|
export class Store implements Lineage {
|
|
41
42
|
public parent: Store | null = null
|
|
@@ -94,6 +95,8 @@ export class Store implements Lineage {
|
|
|
94
95
|
cardinality: `1:n`,
|
|
95
96
|
})
|
|
96
97
|
|
|
98
|
+
public disposalTraces = new CircularBuffer<{ key: string; trace: string }>(100)
|
|
99
|
+
|
|
97
100
|
public molecules = new Map<string, Molecule<any>>()
|
|
98
101
|
public moleculeFamilies = new Map<string, MoleculeFamily<any>>()
|
|
99
102
|
public moleculeInProgress: string | null = null
|
|
@@ -176,7 +179,7 @@ export class Store implements Lineage {
|
|
|
176
179
|
}
|
|
177
180
|
atom.install(this)
|
|
178
181
|
if (atom.type === `mutable_atom`) {
|
|
179
|
-
const originalJsonToken = getJsonToken(
|
|
182
|
+
const originalJsonToken = getJsonToken(store, atom)
|
|
180
183
|
const originalUpdateToken = getUpdateToken(atom)
|
|
181
184
|
mutableHelpers.add(originalJsonToken.key)
|
|
182
185
|
mutableHelpers.add(originalUpdateToken.key)
|
|
@@ -155,19 +155,24 @@ export function withdraw<T>(
|
|
|
155
155
|
token: TimelineToken<T>,
|
|
156
156
|
store: Store,
|
|
157
157
|
): Timeline<T extends TimelineManageable ? T : never>
|
|
158
|
-
|
|
158
|
+
|
|
159
|
+
export function withdraw<T, M extends MoleculeConstructor>(
|
|
160
|
+
token: MoleculeToken<M> | ReadableToken<T>,
|
|
161
|
+
store: Store,
|
|
162
|
+
): Molecule<M> | ReadableState<T>
|
|
163
|
+
|
|
164
|
+
export function withdraw(
|
|
159
165
|
token:
|
|
160
166
|
| MoleculeFamilyToken<any>
|
|
161
167
|
| MoleculeToken<any>
|
|
162
|
-
|
|
|
163
|
-
|
|
|
164
|
-
|
|
|
165
|
-
|
|
|
166
|
-
|
|
|
167
|
-
|
|
|
168
|
-
|
|
|
169
|
-
|
|
170
|
-
: never),
|
|
168
|
+
| MutableAtomFamilyToken<any, any, any>
|
|
169
|
+
| MutableAtomToken<any, any>
|
|
170
|
+
| RegularAtomFamilyToken<any, any>
|
|
171
|
+
| RegularAtomToken<any>
|
|
172
|
+
| SelectorFamilyToken<any, any>
|
|
173
|
+
| SelectorToken<any>
|
|
174
|
+
| TimelineToken<any>
|
|
175
|
+
| TransactionToken<any>,
|
|
171
176
|
store: Store,
|
|
172
177
|
): Withdrawable {
|
|
173
178
|
let withdrawn: Withdrawable | undefined
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ReadableToken,
|
|
3
|
+
TimelineManageable,
|
|
4
|
+
TimelineToken,
|
|
5
|
+
TimelineUpdate,
|
|
6
|
+
TransactionToken,
|
|
7
|
+
TransactionUpdateHandler,
|
|
8
|
+
UpdateHandler,
|
|
9
|
+
} from "atom.io"
|
|
10
|
+
import type { Func, Store } from "atom.io/internal"
|
|
11
|
+
import {
|
|
12
|
+
arbitrary,
|
|
13
|
+
subscribeToState,
|
|
14
|
+
subscribeToTimeline,
|
|
15
|
+
subscribeToTransaction,
|
|
16
|
+
} from "atom.io/internal"
|
|
17
|
+
|
|
18
|
+
export function subscribeInStore<T>(
|
|
19
|
+
store: Store,
|
|
20
|
+
token: ReadableToken<T>,
|
|
21
|
+
handleUpdate: UpdateHandler<T>,
|
|
22
|
+
key?: string,
|
|
23
|
+
): () => void
|
|
24
|
+
export function subscribeInStore<F extends Func>(
|
|
25
|
+
store: Store,
|
|
26
|
+
token: TransactionToken<F>,
|
|
27
|
+
handleUpdate: TransactionUpdateHandler<F>,
|
|
28
|
+
key?: string,
|
|
29
|
+
): () => void
|
|
30
|
+
export function subscribeInStore<M extends TimelineManageable>(
|
|
31
|
+
store: Store,
|
|
32
|
+
token: TimelineToken<M>,
|
|
33
|
+
handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,
|
|
34
|
+
key?: string,
|
|
35
|
+
): () => void
|
|
36
|
+
export function subscribeInStore<M extends TimelineManageable>(
|
|
37
|
+
store: Store,
|
|
38
|
+
token: ReadableToken<any> | TimelineToken<M> | TransactionToken<any>,
|
|
39
|
+
handleUpdate:
|
|
40
|
+
| TransactionUpdateHandler<any>
|
|
41
|
+
| UpdateHandler<any>
|
|
42
|
+
| ((update: TimelineUpdate<M> | `redo` | `undo`) => void),
|
|
43
|
+
key?: string,
|
|
44
|
+
): () => void
|
|
45
|
+
export function subscribeInStore(
|
|
46
|
+
store: Store,
|
|
47
|
+
token: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,
|
|
48
|
+
handleUpdate: (update: any) => void,
|
|
49
|
+
key: string = arbitrary(),
|
|
50
|
+
): () => void {
|
|
51
|
+
switch (token.type) {
|
|
52
|
+
case `atom`:
|
|
53
|
+
case `mutable_atom`:
|
|
54
|
+
case `readonly_selector`:
|
|
55
|
+
case `selector`:
|
|
56
|
+
return subscribeToState(token, handleUpdate, key, store)
|
|
57
|
+
case `transaction`:
|
|
58
|
+
return subscribeToTransaction(token, handleUpdate, key, store)
|
|
59
|
+
case `timeline`:
|
|
60
|
+
return subscribeToTimeline(token, handleUpdate, key, store)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -49,6 +49,7 @@ export const buildTransaction = (
|
|
|
49
49
|
selectors: new LazyMap(parent.selectors),
|
|
50
50
|
valueMap: new LazyMap(parent.valueMap),
|
|
51
51
|
defaults: parent.defaults,
|
|
52
|
+
disposalTraces: store.disposalTraces.copy(),
|
|
52
53
|
molecules: new LazyMap(parent.molecules),
|
|
53
54
|
moleculeFamilies: new LazyMap(parent.moleculeFamilies),
|
|
54
55
|
moleculeInProgress: parent.moleculeInProgress,
|
|
@@ -68,19 +69,19 @@ export const buildTransaction = (
|
|
|
68
69
|
},
|
|
69
70
|
toolkit: {
|
|
70
71
|
get: ((...ps: Parameters<typeof getState>) =>
|
|
71
|
-
getFromStore(...ps
|
|
72
|
+
getFromStore(child, ...ps)) as typeof getState,
|
|
72
73
|
set: ((...ps: Parameters<typeof setState>) => {
|
|
73
|
-
setIntoStore(...ps
|
|
74
|
+
setIntoStore(child, ...ps)
|
|
74
75
|
}) as typeof setState,
|
|
75
76
|
run: (token, identifier = arbitrary()) =>
|
|
76
77
|
actUponStore(token, identifier, child),
|
|
77
|
-
find: ((token, k) => findInStore(token, k
|
|
78
|
-
seek: ((token, k) => seekInStore(token, k
|
|
79
|
-
json: (token) => getJsonToken(
|
|
78
|
+
find: ((token, k) => findInStore(child, token, k)) as typeof findState,
|
|
79
|
+
seek: ((token, k) => seekInStore(child, token, k)) as typeof seekState,
|
|
80
|
+
json: (token) => getJsonToken(child, token),
|
|
80
81
|
make: (context, family, k, ...args) =>
|
|
81
82
|
makeMoleculeInStore(child, context, family, k, ...args),
|
|
82
83
|
dispose: ((...ps: Parameters<typeof disposeState>) => {
|
|
83
|
-
disposeFromStore(...ps
|
|
84
|
+
disposeFromStore(child, ...ps)
|
|
84
85
|
}) as typeof disposeState,
|
|
85
86
|
env: () => getEnvironmentData(child),
|
|
86
87
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AtomToken, SelectorToken, ReadonlySelectorToken, TransactionToken, ReadonlySelectorFamilyToken, TransactionUpdate, TimelineToken, ReadableToken } from 'atom.io';
|
|
2
2
|
import * as Internal from 'atom.io/internal';
|
|
3
|
-
import { Func, Timeline } from 'atom.io/internal';
|
|
3
|
+
import { Func, Timeline, Flat } from 'atom.io/internal';
|
|
4
|
+
import { Json } from 'atom.io/json';
|
|
4
5
|
|
|
5
6
|
type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>;
|
|
6
7
|
|
|
@@ -10,9 +11,10 @@ declare const attachIntrospectionStates: (store?: Internal.Store) => {
|
|
|
10
11
|
atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
|
|
11
12
|
selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
|
|
12
13
|
transactionIndex: ReadonlySelectorToken<TransactionToken<Func>[]>;
|
|
13
|
-
|
|
14
|
+
transactionLogSelectors: ReadonlySelectorFamilyToken<TransactionUpdate<Func>[], string>;
|
|
14
15
|
timelineIndex: ReadonlySelectorToken<TimelineToken<any>[]>;
|
|
15
|
-
|
|
16
|
+
timelineSelectors: ReadonlySelectorFamilyToken<Timeline<any>, string>;
|
|
17
|
+
typeSelectors: ReadonlySelectorFamilyToken<string, string>;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
type ListResourcesParam = {
|
|
@@ -52,10 +54,88 @@ declare class Auditor {
|
|
|
52
54
|
[Symbol.dispose](): void;
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
type Refinement<A, B extends A> = (a: A) => a is B;
|
|
58
|
+
type ClassSignature = abstract new (...args: any) => any;
|
|
59
|
+
type RefinementStrategy = ClassSignature | Refinement<unknown, any>;
|
|
60
|
+
type Supported<Refine extends RefinementStrategy> = Refine extends Refinement<unknown, infer T> ? T : Refine extends ClassSignature ? InstanceType<Refine> : never;
|
|
61
|
+
type RefinementSupport = Record<string, RefinementStrategy>;
|
|
62
|
+
declare class Refinery<SupportedTypes extends RefinementSupport> {
|
|
63
|
+
supported: SupportedTypes;
|
|
64
|
+
constructor(supported: SupportedTypes);
|
|
65
|
+
refine<T>(input: T): Flat<{
|
|
66
|
+
[K in keyof SupportedTypes]: T extends Supported<SupportedTypes[K]> ? {
|
|
67
|
+
type: K;
|
|
68
|
+
data: Supported<SupportedTypes[K]>;
|
|
69
|
+
} : Supported<SupportedTypes[K]> extends T ? {
|
|
70
|
+
type: K;
|
|
71
|
+
data: Supported<SupportedTypes[K]>;
|
|
72
|
+
} : never;
|
|
73
|
+
}>[keyof SupportedTypes] | (T extends Supported<SupportedTypes[keyof SupportedTypes]> ? never : null);
|
|
74
|
+
}
|
|
75
|
+
declare const primitiveRefinery: Refinery<{
|
|
76
|
+
number: (input: unknown) => input is number;
|
|
77
|
+
string: (input: unknown) => input is string;
|
|
78
|
+
boolean: (input: unknown) => input is boolean;
|
|
79
|
+
null: (input: unknown) => input is null;
|
|
80
|
+
}>;
|
|
81
|
+
declare const jsonTreeRefinery: Refinery<{
|
|
82
|
+
object: (input: unknown) => input is Json.Tree.Object;
|
|
83
|
+
array: (input: unknown) => input is Json.Tree.Array;
|
|
84
|
+
}>;
|
|
85
|
+
declare const jsonRefinery: Refinery<{
|
|
86
|
+
object: (input: unknown) => input is Json.Tree.Object;
|
|
87
|
+
array: (input: unknown) => input is Json.Tree.Array;
|
|
88
|
+
number: (input: unknown) => input is number;
|
|
89
|
+
string: (input: unknown) => input is string;
|
|
90
|
+
boolean: (input: unknown) => input is boolean;
|
|
91
|
+
null: (input: unknown) => input is null;
|
|
92
|
+
}>;
|
|
93
|
+
type JsonType = keyof typeof jsonRefinery.supported;
|
|
94
|
+
declare const discoverType: (input: unknown) => JsonType | `Map` | `Set` | `undefined` | (string & {});
|
|
95
|
+
|
|
96
|
+
declare function diffNumber(a: number, b: number): Delta;
|
|
97
|
+
declare function diffString(a: string, b: string): Delta;
|
|
98
|
+
declare function diffBoolean(a: boolean, b: boolean): Delta;
|
|
99
|
+
declare function diffObject(a: Json.Tree.Object, b: Json.Tree.Object, recurse: Diff<unknown>): Delta;
|
|
100
|
+
declare function diffArray(a: Json.Tree.Array, b: Json.Tree.Array, recurse: Diff<unknown>): Delta;
|
|
101
|
+
type Delta = {
|
|
102
|
+
summary: string;
|
|
103
|
+
added?: [path: string, addedStringifiedValue: string][];
|
|
104
|
+
removed?: [path: string, removedStringifiedValue: string][];
|
|
105
|
+
changed?: [path: string, delta: Delta][];
|
|
106
|
+
};
|
|
107
|
+
type Diff<T> = (a: T, b: T) => Delta;
|
|
108
|
+
type DiffTree<T> = (a: T, b: T, recurse: Differ<any, any>[`diff`]) => Delta;
|
|
109
|
+
declare class Differ<Leaf extends Record<string, any>, Tree extends Record<string, any>> {
|
|
110
|
+
leafRefinery: Refinery<Leaf>;
|
|
111
|
+
treeRefinery: Refinery<Tree>;
|
|
112
|
+
leafDiffers: {
|
|
113
|
+
[KL in keyof Leaf]: Diff<Supported<Leaf[KL]>>;
|
|
114
|
+
};
|
|
115
|
+
treeDiffers: {
|
|
116
|
+
[KT in keyof Tree]: DiffTree<Supported<Tree[KT]>>;
|
|
117
|
+
};
|
|
118
|
+
constructor(leafRefinery: Refinery<Leaf>, treeRefinery: Refinery<Tree>, diffFunctions: {
|
|
119
|
+
[KT in keyof Tree]: DiffTree<Supported<Tree[KT]>>;
|
|
120
|
+
} & {
|
|
121
|
+
[KL in keyof Leaf]: Diff<Supported<Leaf[KL]>>;
|
|
122
|
+
});
|
|
123
|
+
diff(a: unknown, b: unknown): Delta;
|
|
124
|
+
}
|
|
125
|
+
declare const prettyJson: Differ<{
|
|
126
|
+
number: (input: unknown) => input is number;
|
|
127
|
+
string: (input: unknown) => input is string;
|
|
128
|
+
boolean: (input: unknown) => input is boolean;
|
|
129
|
+
null: (input: unknown) => input is null;
|
|
130
|
+
}, {
|
|
131
|
+
object: (input: unknown) => input is Json.Tree.Object;
|
|
132
|
+
array: (input: unknown) => input is Json.Tree.Array;
|
|
133
|
+
}>;
|
|
134
|
+
|
|
55
135
|
type FamilyNode<Token extends ReadableToken<unknown>> = {
|
|
56
136
|
key: string;
|
|
57
137
|
familyMembers: Map<string, Token>;
|
|
58
138
|
};
|
|
59
139
|
type WritableTokenIndex<Token extends ReadableToken<unknown>> = Map<string, FamilyNode<Token> | Token>;
|
|
60
140
|
|
|
61
|
-
export { Auditor, type FamilyNode, type ListResourcesParam, type WritableTokenIndex, attachIntrospectionStates };
|
|
141
|
+
export { Auditor, type ClassSignature, Differ, type FamilyNode, type JsonType, type ListResourcesParam, type Refinement, type RefinementStrategy, type RefinementSupport, Refinery, type Supported, type WritableTokenIndex, attachIntrospectionStates, diffArray, diffBoolean, diffNumber, diffObject, diffString, discoverType, jsonRefinery, jsonTreeRefinery, prettyJson, primitiveRefinery };
|