atom.io 0.6.6 → 0.6.7
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/index.d.mts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +66 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -83
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +273 -0
- package/introspection/dist/index.d.ts +273 -0
- package/introspection/dist/index.js +41 -3
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +41 -3
- package/introspection/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/react-devtools/dist/index.d.mts +8 -10
- package/react-devtools/dist/index.d.ts +8 -10
- package/react-devtools/dist/index.js +104 -105
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +105 -106
- package/react-devtools/dist/index.mjs.map +1 -1
- package/src/internal/atom-internal.ts +5 -6
- package/src/internal/get.ts +7 -9
- package/src/internal/operation.ts +14 -21
- package/src/internal/selector/create-read-write-selector.ts +8 -4
- package/src/internal/selector/create-readonly-selector.ts +1 -7
- package/src/internal/selector-internal.ts +1 -3
- package/src/internal/set.ts +1 -4
- package/src/internal/store.ts +19 -22
- package/src/internal/subscribe-internal.ts +7 -1
- package/src/internal/timeline-internal.ts +1 -3
- package/src/internal/transaction/apply-transaction.ts +9 -6
- package/src/internal/transaction/build-transaction.ts +6 -6
- package/src/internal/transaction-internal.ts +1 -7
- package/src/introspection/attach-timeline-family.ts +14 -4
- package/src/introspection/attach-transaction-logs.ts +1 -1
- package/src/react-devtools/AtomIODevtools.tsx +1 -2
- package/src/react-explorer/AtomIOExplorer.tsx +3 -3
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { AtomToken as AtomToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, SelectorToken as SelectorToken$1, __INTERNAL__, TransactionToken as TransactionToken$1, ReadonlySelectorFamily, TransactionUpdate as TransactionUpdate$1, TimelineToken as TimelineToken$1 } from 'atom.io';
|
|
2
|
+
import { Refinement } from 'fp-ts/Refinement';
|
|
3
|
+
|
|
4
|
+
type ƒn = (...parameters: any[]) => any;
|
|
5
|
+
|
|
6
|
+
type AtomTokenIndex = StateTokenIndex<AtomToken$1<unknown>>;
|
|
7
|
+
|
|
8
|
+
type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>>;
|
|
9
|
+
|
|
10
|
+
type JsonInterface<T, J extends Json = Json> = {
|
|
11
|
+
toJson: (t: T) => J;
|
|
12
|
+
fromJson: (json: J) => T;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type Primitive = boolean | number | string | null;
|
|
16
|
+
type Serializable = Primitive | Readonly<{
|
|
17
|
+
[key: string]: Serializable;
|
|
18
|
+
}> | ReadonlyArray<Serializable>;
|
|
19
|
+
type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
20
|
+
type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
21
|
+
type Json = JsonArr | JsonObj | Primitive;
|
|
22
|
+
|
|
23
|
+
type Identified = {
|
|
24
|
+
id: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
|
|
28
|
+
type RelationType = typeof RELATION_TYPES[number];
|
|
29
|
+
type RelationData<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> = {
|
|
30
|
+
contents: JsonObj<string, CONTENT>;
|
|
31
|
+
relations: JsonObj<string, string[]>;
|
|
32
|
+
relationType: RelationType;
|
|
33
|
+
a: A;
|
|
34
|
+
b: B;
|
|
35
|
+
};
|
|
36
|
+
type IsRelationDataOptions<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> = {
|
|
37
|
+
from?: A;
|
|
38
|
+
to?: B;
|
|
39
|
+
isContent?: (json: Json) => json is CONTENT;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
|
|
43
|
+
type NullSafeRest<MaybeArg> = MaybeArg extends null ? [] | [undefined] : [MaybeArg];
|
|
44
|
+
|
|
45
|
+
declare class Join<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> implements RelationData<CONTENT, A, B> {
|
|
46
|
+
readonly relationType: `1:1` | `1:n` | `n:n`;
|
|
47
|
+
readonly a: A;
|
|
48
|
+
readonly b: B;
|
|
49
|
+
readonly relations: Record<string, string[]>;
|
|
50
|
+
readonly contents: Record<string, CONTENT>;
|
|
51
|
+
constructor(json?: Partial<RelationData<CONTENT, A, B>>);
|
|
52
|
+
toJSON(): RelationData<CONTENT, A, B>;
|
|
53
|
+
static fromJSON<CONTENT extends JsonObj | null, A extends string, B extends string>(json: Json, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
|
|
54
|
+
from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
|
|
55
|
+
to<BB extends string>(newB: BB): Join<CONTENT, A, BB>;
|
|
56
|
+
makeJsonInterface: (...params: CONTENT extends null ? [
|
|
57
|
+
] : [Refinement<unknown, CONTENT>]) => JsonInterface<Join<CONTENT, A, B>, RelationData<CONTENT, A, B>>;
|
|
58
|
+
getRelatedId(id: string): string | undefined;
|
|
59
|
+
getRelatedIds(id: string): string[];
|
|
60
|
+
getContent(idA: string, idB: string): CONTENT | undefined;
|
|
61
|
+
getRelationEntries(id: string): [string, CONTENT][];
|
|
62
|
+
getRelationRecord(id: string): Record<string, CONTENT>;
|
|
63
|
+
getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
|
|
64
|
+
getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
|
|
65
|
+
setRelations(subject: {
|
|
66
|
+
[from in A]: string;
|
|
67
|
+
} | {
|
|
68
|
+
[to in B]: string;
|
|
69
|
+
}, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT, A, B>;
|
|
70
|
+
set(relation: {
|
|
71
|
+
[key in A | B]: string;
|
|
72
|
+
}, ...rest: NullSafeRest<CONTENT>): Join<CONTENT, A, B>;
|
|
73
|
+
remove(relation: Partial<Record<A | B, string>>): Join<CONTENT, A, B>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type Logger = Pick<Console, `error` | `info` | `warn`>;
|
|
77
|
+
|
|
78
|
+
type TransactionToken<_> = {
|
|
79
|
+
key: string;
|
|
80
|
+
type: `transaction`;
|
|
81
|
+
__brand?: _;
|
|
82
|
+
};
|
|
83
|
+
type TransactionUpdate<ƒ extends ƒn> = {
|
|
84
|
+
key: string;
|
|
85
|
+
atomUpdates: KeyedStateUpdate<unknown>[];
|
|
86
|
+
params: Parameters<ƒ>;
|
|
87
|
+
output: ReturnType<ƒ>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type StateUpdate<T> = {
|
|
91
|
+
newValue: T;
|
|
92
|
+
oldValue: T;
|
|
93
|
+
};
|
|
94
|
+
type KeyedStateUpdate<T> = StateUpdate<T> & {
|
|
95
|
+
key: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
type TimelineToken = {
|
|
99
|
+
key: string;
|
|
100
|
+
type: `timeline`;
|
|
101
|
+
};
|
|
102
|
+
type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
|
|
103
|
+
|
|
104
|
+
type AtomToken<_> = {
|
|
105
|
+
key: string;
|
|
106
|
+
type: `atom`;
|
|
107
|
+
family?: FamilyMetadata;
|
|
108
|
+
__brand?: _;
|
|
109
|
+
};
|
|
110
|
+
type SelectorToken<_> = {
|
|
111
|
+
key: string;
|
|
112
|
+
type: `selector`;
|
|
113
|
+
family?: FamilyMetadata;
|
|
114
|
+
__brand?: _;
|
|
115
|
+
};
|
|
116
|
+
type StateToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
117
|
+
type ReadonlySelectorToken<_> = {
|
|
118
|
+
key: string;
|
|
119
|
+
type: `readonly_selector`;
|
|
120
|
+
family?: FamilyMetadata;
|
|
121
|
+
__brand?: _;
|
|
122
|
+
};
|
|
123
|
+
type FamilyMetadata = {
|
|
124
|
+
key: string;
|
|
125
|
+
subKey: string;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
|
|
129
|
+
interface Store {
|
|
130
|
+
atoms: Map<string, Atom<any>>;
|
|
131
|
+
atomsThatAreDefault: Set<string>;
|
|
132
|
+
readonlySelectors: Map<string, ReadonlySelector<any>>;
|
|
133
|
+
selectorAtoms: Join<null, `selectorKey`, `atomKey`>;
|
|
134
|
+
selectorGraph: Join<{
|
|
135
|
+
source: string;
|
|
136
|
+
}>;
|
|
137
|
+
selectors: Map<string, Selector<any>>;
|
|
138
|
+
timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
|
|
139
|
+
timelines: Map<string, Timeline>;
|
|
140
|
+
transactions: Map<string, Transaction<any>>;
|
|
141
|
+
valueMap: Map<string, any>;
|
|
142
|
+
subject: {
|
|
143
|
+
atomCreation: Subject<AtomToken<unknown>>;
|
|
144
|
+
selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
|
|
145
|
+
transactionCreation: Subject<TransactionToken<ƒn>>;
|
|
146
|
+
timelineCreation: Subject<TimelineToken>;
|
|
147
|
+
operationStatus: Subject<OperationProgress>;
|
|
148
|
+
};
|
|
149
|
+
operation: OperationProgress;
|
|
150
|
+
transactionStatus: TransactionStatus<ƒn>;
|
|
151
|
+
config: {
|
|
152
|
+
name: string;
|
|
153
|
+
logger: Logger | null;
|
|
154
|
+
logger__INTERNAL: Logger;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type Atom<T> = {
|
|
159
|
+
key: string;
|
|
160
|
+
type: `atom`;
|
|
161
|
+
family?: FamilyMetadata;
|
|
162
|
+
subject: Subject<{
|
|
163
|
+
newValue: T;
|
|
164
|
+
oldValue: T;
|
|
165
|
+
}>;
|
|
166
|
+
default: T;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
type OperationProgress = {
|
|
170
|
+
open: false;
|
|
171
|
+
} | {
|
|
172
|
+
open: true;
|
|
173
|
+
done: Set<string>;
|
|
174
|
+
prev: Map<string, any>;
|
|
175
|
+
time: number;
|
|
176
|
+
token: StateToken<any>;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
type Selector<T> = {
|
|
180
|
+
key: string;
|
|
181
|
+
type: `selector`;
|
|
182
|
+
family?: FamilyMetadata;
|
|
183
|
+
install: (store: Store) => void;
|
|
184
|
+
subject: Subject<{
|
|
185
|
+
newValue: T;
|
|
186
|
+
oldValue: T;
|
|
187
|
+
}>;
|
|
188
|
+
get: () => T;
|
|
189
|
+
set: (newValue: T | ((oldValue: T) => T)) => void;
|
|
190
|
+
};
|
|
191
|
+
type ReadonlySelector<T> = {
|
|
192
|
+
key: string;
|
|
193
|
+
type: `readonly_selector`;
|
|
194
|
+
family?: FamilyMetadata;
|
|
195
|
+
install: (store: Store) => void;
|
|
196
|
+
subject: Subject<{
|
|
197
|
+
newValue: T;
|
|
198
|
+
oldValue: T;
|
|
199
|
+
}>;
|
|
200
|
+
get: () => T;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
type Subscriber<T> = (value: T) => void;
|
|
204
|
+
declare class Subject<T> {
|
|
205
|
+
subscribers: Subscriber<T>[];
|
|
206
|
+
subscribe(subscriber: Subscriber<T>): {
|
|
207
|
+
unsubscribe: () => void;
|
|
208
|
+
};
|
|
209
|
+
private unsubscribe;
|
|
210
|
+
next(value: T): void;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
type TimelineAtomUpdate = StateUpdate<unknown> & {
|
|
214
|
+
key: string;
|
|
215
|
+
type: `atom_update`;
|
|
216
|
+
timestamp: number;
|
|
217
|
+
};
|
|
218
|
+
type TimelineSelectorUpdate = {
|
|
219
|
+
key: string;
|
|
220
|
+
type: `selector_update`;
|
|
221
|
+
timestamp: number;
|
|
222
|
+
atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
|
|
223
|
+
};
|
|
224
|
+
type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
|
|
225
|
+
key: string;
|
|
226
|
+
type: `transaction_update`;
|
|
227
|
+
timestamp: number;
|
|
228
|
+
};
|
|
229
|
+
type Timeline = {
|
|
230
|
+
key: string;
|
|
231
|
+
at: number;
|
|
232
|
+
timeTraveling: boolean;
|
|
233
|
+
history: TimelineUpdate[];
|
|
234
|
+
selectorTime: number | null;
|
|
235
|
+
transactionKey: string | null;
|
|
236
|
+
install: (store: Store) => void;
|
|
237
|
+
subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
type Transaction<ƒ extends ƒn> = {
|
|
241
|
+
key: string;
|
|
242
|
+
type: `transaction`;
|
|
243
|
+
install: (store: Store) => void;
|
|
244
|
+
subject: Subject<TransactionUpdate<ƒ>>;
|
|
245
|
+
run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
|
|
249
|
+
phase: `applying` | `building`;
|
|
250
|
+
time: number;
|
|
251
|
+
core: StoreCore;
|
|
252
|
+
};
|
|
253
|
+
type TransactionIdle = {
|
|
254
|
+
phase: `idle`;
|
|
255
|
+
};
|
|
256
|
+
type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
|
|
257
|
+
|
|
258
|
+
declare const attachIntrospectionStates: (store?: __INTERNAL__.Store) => {
|
|
259
|
+
atomIndex: ReadonlySelectorToken$1<AtomTokenIndex>;
|
|
260
|
+
selectorIndex: ReadonlySelectorToken$1<SelectorTokenIndex>;
|
|
261
|
+
transactionIndex: ReadonlySelectorToken$1<TransactionToken$1<ƒn>[]>;
|
|
262
|
+
findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate$1<ƒn>[]>;
|
|
263
|
+
timelineIndex: ReadonlySelectorToken$1<TimelineToken$1[]>;
|
|
264
|
+
findTimelineState: ReadonlySelectorFamily<Timeline>;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
type FamilyNode<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = {
|
|
268
|
+
key: string;
|
|
269
|
+
familyMembers: Record<string, Token>;
|
|
270
|
+
};
|
|
271
|
+
type StateTokenIndex<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = Record<string, FamilyNode<Token> | Token>;
|
|
272
|
+
|
|
273
|
+
export { FamilyNode, StateTokenIndex, attachIntrospectionStates };
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { AtomToken as AtomToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, SelectorToken as SelectorToken$1, __INTERNAL__, TransactionToken as TransactionToken$1, ReadonlySelectorFamily, TransactionUpdate as TransactionUpdate$1, TimelineToken as TimelineToken$1 } from 'atom.io';
|
|
2
|
+
import { Refinement } from 'fp-ts/Refinement';
|
|
3
|
+
|
|
4
|
+
type ƒn = (...parameters: any[]) => any;
|
|
5
|
+
|
|
6
|
+
type AtomTokenIndex = StateTokenIndex<AtomToken$1<unknown>>;
|
|
7
|
+
|
|
8
|
+
type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>>;
|
|
9
|
+
|
|
10
|
+
type JsonInterface<T, J extends Json = Json> = {
|
|
11
|
+
toJson: (t: T) => J;
|
|
12
|
+
fromJson: (json: J) => T;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type Primitive = boolean | number | string | null;
|
|
16
|
+
type Serializable = Primitive | Readonly<{
|
|
17
|
+
[key: string]: Serializable;
|
|
18
|
+
}> | ReadonlyArray<Serializable>;
|
|
19
|
+
type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
20
|
+
type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
21
|
+
type Json = JsonArr | JsonObj | Primitive;
|
|
22
|
+
|
|
23
|
+
type Identified = {
|
|
24
|
+
id: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
|
|
28
|
+
type RelationType = typeof RELATION_TYPES[number];
|
|
29
|
+
type RelationData<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> = {
|
|
30
|
+
contents: JsonObj<string, CONTENT>;
|
|
31
|
+
relations: JsonObj<string, string[]>;
|
|
32
|
+
relationType: RelationType;
|
|
33
|
+
a: A;
|
|
34
|
+
b: B;
|
|
35
|
+
};
|
|
36
|
+
type IsRelationDataOptions<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> = {
|
|
37
|
+
from?: A;
|
|
38
|
+
to?: B;
|
|
39
|
+
isContent?: (json: Json) => json is CONTENT;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
|
|
43
|
+
type NullSafeRest<MaybeArg> = MaybeArg extends null ? [] | [undefined] : [MaybeArg];
|
|
44
|
+
|
|
45
|
+
declare class Join<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> implements RelationData<CONTENT, A, B> {
|
|
46
|
+
readonly relationType: `1:1` | `1:n` | `n:n`;
|
|
47
|
+
readonly a: A;
|
|
48
|
+
readonly b: B;
|
|
49
|
+
readonly relations: Record<string, string[]>;
|
|
50
|
+
readonly contents: Record<string, CONTENT>;
|
|
51
|
+
constructor(json?: Partial<RelationData<CONTENT, A, B>>);
|
|
52
|
+
toJSON(): RelationData<CONTENT, A, B>;
|
|
53
|
+
static fromJSON<CONTENT extends JsonObj | null, A extends string, B extends string>(json: Json, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
|
|
54
|
+
from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
|
|
55
|
+
to<BB extends string>(newB: BB): Join<CONTENT, A, BB>;
|
|
56
|
+
makeJsonInterface: (...params: CONTENT extends null ? [
|
|
57
|
+
] : [Refinement<unknown, CONTENT>]) => JsonInterface<Join<CONTENT, A, B>, RelationData<CONTENT, A, B>>;
|
|
58
|
+
getRelatedId(id: string): string | undefined;
|
|
59
|
+
getRelatedIds(id: string): string[];
|
|
60
|
+
getContent(idA: string, idB: string): CONTENT | undefined;
|
|
61
|
+
getRelationEntries(id: string): [string, CONTENT][];
|
|
62
|
+
getRelationRecord(id: string): Record<string, CONTENT>;
|
|
63
|
+
getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
|
|
64
|
+
getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
|
|
65
|
+
setRelations(subject: {
|
|
66
|
+
[from in A]: string;
|
|
67
|
+
} | {
|
|
68
|
+
[to in B]: string;
|
|
69
|
+
}, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT, A, B>;
|
|
70
|
+
set(relation: {
|
|
71
|
+
[key in A | B]: string;
|
|
72
|
+
}, ...rest: NullSafeRest<CONTENT>): Join<CONTENT, A, B>;
|
|
73
|
+
remove(relation: Partial<Record<A | B, string>>): Join<CONTENT, A, B>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type Logger = Pick<Console, `error` | `info` | `warn`>;
|
|
77
|
+
|
|
78
|
+
type TransactionToken<_> = {
|
|
79
|
+
key: string;
|
|
80
|
+
type: `transaction`;
|
|
81
|
+
__brand?: _;
|
|
82
|
+
};
|
|
83
|
+
type TransactionUpdate<ƒ extends ƒn> = {
|
|
84
|
+
key: string;
|
|
85
|
+
atomUpdates: KeyedStateUpdate<unknown>[];
|
|
86
|
+
params: Parameters<ƒ>;
|
|
87
|
+
output: ReturnType<ƒ>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type StateUpdate<T> = {
|
|
91
|
+
newValue: T;
|
|
92
|
+
oldValue: T;
|
|
93
|
+
};
|
|
94
|
+
type KeyedStateUpdate<T> = StateUpdate<T> & {
|
|
95
|
+
key: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
type TimelineToken = {
|
|
99
|
+
key: string;
|
|
100
|
+
type: `timeline`;
|
|
101
|
+
};
|
|
102
|
+
type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
|
|
103
|
+
|
|
104
|
+
type AtomToken<_> = {
|
|
105
|
+
key: string;
|
|
106
|
+
type: `atom`;
|
|
107
|
+
family?: FamilyMetadata;
|
|
108
|
+
__brand?: _;
|
|
109
|
+
};
|
|
110
|
+
type SelectorToken<_> = {
|
|
111
|
+
key: string;
|
|
112
|
+
type: `selector`;
|
|
113
|
+
family?: FamilyMetadata;
|
|
114
|
+
__brand?: _;
|
|
115
|
+
};
|
|
116
|
+
type StateToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
117
|
+
type ReadonlySelectorToken<_> = {
|
|
118
|
+
key: string;
|
|
119
|
+
type: `readonly_selector`;
|
|
120
|
+
family?: FamilyMetadata;
|
|
121
|
+
__brand?: _;
|
|
122
|
+
};
|
|
123
|
+
type FamilyMetadata = {
|
|
124
|
+
key: string;
|
|
125
|
+
subKey: string;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
|
|
129
|
+
interface Store {
|
|
130
|
+
atoms: Map<string, Atom<any>>;
|
|
131
|
+
atomsThatAreDefault: Set<string>;
|
|
132
|
+
readonlySelectors: Map<string, ReadonlySelector<any>>;
|
|
133
|
+
selectorAtoms: Join<null, `selectorKey`, `atomKey`>;
|
|
134
|
+
selectorGraph: Join<{
|
|
135
|
+
source: string;
|
|
136
|
+
}>;
|
|
137
|
+
selectors: Map<string, Selector<any>>;
|
|
138
|
+
timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
|
|
139
|
+
timelines: Map<string, Timeline>;
|
|
140
|
+
transactions: Map<string, Transaction<any>>;
|
|
141
|
+
valueMap: Map<string, any>;
|
|
142
|
+
subject: {
|
|
143
|
+
atomCreation: Subject<AtomToken<unknown>>;
|
|
144
|
+
selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
|
|
145
|
+
transactionCreation: Subject<TransactionToken<ƒn>>;
|
|
146
|
+
timelineCreation: Subject<TimelineToken>;
|
|
147
|
+
operationStatus: Subject<OperationProgress>;
|
|
148
|
+
};
|
|
149
|
+
operation: OperationProgress;
|
|
150
|
+
transactionStatus: TransactionStatus<ƒn>;
|
|
151
|
+
config: {
|
|
152
|
+
name: string;
|
|
153
|
+
logger: Logger | null;
|
|
154
|
+
logger__INTERNAL: Logger;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type Atom<T> = {
|
|
159
|
+
key: string;
|
|
160
|
+
type: `atom`;
|
|
161
|
+
family?: FamilyMetadata;
|
|
162
|
+
subject: Subject<{
|
|
163
|
+
newValue: T;
|
|
164
|
+
oldValue: T;
|
|
165
|
+
}>;
|
|
166
|
+
default: T;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
type OperationProgress = {
|
|
170
|
+
open: false;
|
|
171
|
+
} | {
|
|
172
|
+
open: true;
|
|
173
|
+
done: Set<string>;
|
|
174
|
+
prev: Map<string, any>;
|
|
175
|
+
time: number;
|
|
176
|
+
token: StateToken<any>;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
type Selector<T> = {
|
|
180
|
+
key: string;
|
|
181
|
+
type: `selector`;
|
|
182
|
+
family?: FamilyMetadata;
|
|
183
|
+
install: (store: Store) => void;
|
|
184
|
+
subject: Subject<{
|
|
185
|
+
newValue: T;
|
|
186
|
+
oldValue: T;
|
|
187
|
+
}>;
|
|
188
|
+
get: () => T;
|
|
189
|
+
set: (newValue: T | ((oldValue: T) => T)) => void;
|
|
190
|
+
};
|
|
191
|
+
type ReadonlySelector<T> = {
|
|
192
|
+
key: string;
|
|
193
|
+
type: `readonly_selector`;
|
|
194
|
+
family?: FamilyMetadata;
|
|
195
|
+
install: (store: Store) => void;
|
|
196
|
+
subject: Subject<{
|
|
197
|
+
newValue: T;
|
|
198
|
+
oldValue: T;
|
|
199
|
+
}>;
|
|
200
|
+
get: () => T;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
type Subscriber<T> = (value: T) => void;
|
|
204
|
+
declare class Subject<T> {
|
|
205
|
+
subscribers: Subscriber<T>[];
|
|
206
|
+
subscribe(subscriber: Subscriber<T>): {
|
|
207
|
+
unsubscribe: () => void;
|
|
208
|
+
};
|
|
209
|
+
private unsubscribe;
|
|
210
|
+
next(value: T): void;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
type TimelineAtomUpdate = StateUpdate<unknown> & {
|
|
214
|
+
key: string;
|
|
215
|
+
type: `atom_update`;
|
|
216
|
+
timestamp: number;
|
|
217
|
+
};
|
|
218
|
+
type TimelineSelectorUpdate = {
|
|
219
|
+
key: string;
|
|
220
|
+
type: `selector_update`;
|
|
221
|
+
timestamp: number;
|
|
222
|
+
atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
|
|
223
|
+
};
|
|
224
|
+
type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
|
|
225
|
+
key: string;
|
|
226
|
+
type: `transaction_update`;
|
|
227
|
+
timestamp: number;
|
|
228
|
+
};
|
|
229
|
+
type Timeline = {
|
|
230
|
+
key: string;
|
|
231
|
+
at: number;
|
|
232
|
+
timeTraveling: boolean;
|
|
233
|
+
history: TimelineUpdate[];
|
|
234
|
+
selectorTime: number | null;
|
|
235
|
+
transactionKey: string | null;
|
|
236
|
+
install: (store: Store) => void;
|
|
237
|
+
subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
type Transaction<ƒ extends ƒn> = {
|
|
241
|
+
key: string;
|
|
242
|
+
type: `transaction`;
|
|
243
|
+
install: (store: Store) => void;
|
|
244
|
+
subject: Subject<TransactionUpdate<ƒ>>;
|
|
245
|
+
run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
|
|
249
|
+
phase: `applying` | `building`;
|
|
250
|
+
time: number;
|
|
251
|
+
core: StoreCore;
|
|
252
|
+
};
|
|
253
|
+
type TransactionIdle = {
|
|
254
|
+
phase: `idle`;
|
|
255
|
+
};
|
|
256
|
+
type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
|
|
257
|
+
|
|
258
|
+
declare const attachIntrospectionStates: (store?: __INTERNAL__.Store) => {
|
|
259
|
+
atomIndex: ReadonlySelectorToken$1<AtomTokenIndex>;
|
|
260
|
+
selectorIndex: ReadonlySelectorToken$1<SelectorTokenIndex>;
|
|
261
|
+
transactionIndex: ReadonlySelectorToken$1<TransactionToken$1<ƒn>[]>;
|
|
262
|
+
findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate$1<ƒn>[]>;
|
|
263
|
+
timelineIndex: ReadonlySelectorToken$1<TimelineToken$1[]>;
|
|
264
|
+
findTimelineState: ReadonlySelectorFamily<Timeline>;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
type FamilyNode<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = {
|
|
268
|
+
key: string;
|
|
269
|
+
familyMembers: Record<string, Token>;
|
|
270
|
+
};
|
|
271
|
+
type StateTokenIndex<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = Record<string, FamilyNode<Token> | Token>;
|
|
272
|
+
|
|
273
|
+
export { FamilyNode, StateTokenIndex, attachIntrospectionStates };
|
|
@@ -165,15 +165,53 @@ var attachSelectorIndex = (store = import_atom2.__INTERNAL__.IMPLICIT.STORE) =>
|
|
|
165
165
|
|
|
166
166
|
// ../src/introspection/attach-timeline-family.ts
|
|
167
167
|
var import_atom3 = require("atom.io");
|
|
168
|
+
|
|
169
|
+
// ../src/internal/subject.ts
|
|
170
|
+
var Subject = class {
|
|
171
|
+
constructor() {
|
|
172
|
+
this.subscribers = [];
|
|
173
|
+
}
|
|
174
|
+
subscribe(subscriber) {
|
|
175
|
+
this.subscribers.push(subscriber);
|
|
176
|
+
const unsubscribe = () => this.unsubscribe(subscriber);
|
|
177
|
+
return { unsubscribe };
|
|
178
|
+
}
|
|
179
|
+
unsubscribe(subscriber) {
|
|
180
|
+
const subscriberIndex = this.subscribers.indexOf(subscriber);
|
|
181
|
+
if (subscriberIndex !== -1) {
|
|
182
|
+
this.subscribers.splice(subscriberIndex, 1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
next(value) {
|
|
186
|
+
for (const subscriber of this.subscribers) {
|
|
187
|
+
subscriber(value);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// ../src/introspection/attach-timeline-family.ts
|
|
168
193
|
var attachTimelineFamily = (store = import_atom3.__INTERNAL__.IMPLICIT.STORE) => {
|
|
169
194
|
const findTimelineLogState__INTERNAL = import_atom3.__INTERNAL__.atomFamily__INTERNAL(
|
|
170
195
|
{
|
|
171
196
|
key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log (Internal)`,
|
|
172
|
-
default: (key) =>
|
|
197
|
+
default: (key) => {
|
|
198
|
+
var _a;
|
|
199
|
+
return (_a = store.timelines.get(key)) != null ? _a : {
|
|
200
|
+
key: ``,
|
|
201
|
+
at: 0,
|
|
202
|
+
timeTraveling: false,
|
|
203
|
+
history: [],
|
|
204
|
+
selectorTime: null,
|
|
205
|
+
transactionKey: null,
|
|
206
|
+
install: () => {
|
|
207
|
+
},
|
|
208
|
+
subject: new Subject()
|
|
209
|
+
};
|
|
210
|
+
},
|
|
173
211
|
effects: (key) => [
|
|
174
212
|
({ setSelf }) => {
|
|
175
213
|
const tl = store.timelines.get(key);
|
|
176
|
-
tl.subject.subscribe((_) => {
|
|
214
|
+
tl == null ? void 0 : tl.subject.subscribe((_) => {
|
|
177
215
|
if (store.operation.open === true) {
|
|
178
216
|
const subscription = store.subject.operationStatus.subscribe(
|
|
179
217
|
(operationStatus) => {
|
|
@@ -274,7 +312,7 @@ var attachTransactionLogs = (store = import_atom6.__INTERNAL__.IMPLICIT.STORE) =
|
|
|
274
312
|
effects: (key) => [
|
|
275
313
|
({ setSelf }) => {
|
|
276
314
|
const tx = store.transactions.get(key);
|
|
277
|
-
tx.subject.subscribe((transactionUpdate) => {
|
|
315
|
+
tx == null ? void 0 : tx.subject.subscribe((transactionUpdate) => {
|
|
278
316
|
if (transactionUpdate.key === key) {
|
|
279
317
|
setSelf((state) => [...state, transactionUpdate]);
|
|
280
318
|
}
|