atom.io 0.14.1 → 0.14.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/data/dist/index.cjs +12 -64
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.cts +2 -0
- package/data/dist/index.d.ts +459 -0
- package/data/dist/index.js +1 -1
- package/dist/{chunk-KW7RA7IM.js → chunk-C4YZZNRH.js} +4 -4
- package/dist/{chunk-LFXB7Y6M.js → chunk-CWKKQKVQ.js} +2 -2
- package/dist/{chunk-CK7GNCU5.js → chunk-GMN5KH6A.js} +2 -2
- package/dist/{chunk-5VJ77LZE.js → chunk-N7ADBQJG.js} +2 -2
- package/dist/{chunk-TE3ZSTQ6.js → chunk-PURABO5G.js} +92 -27
- package/dist/chunk-PURABO5G.js.map +1 -0
- package/dist/index.cjs +106 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +493 -0
- package/dist/index.js +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -0
- package/internal/dist/index.cjs +93 -29
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.cts +6 -4
- package/internal/dist/index.d.ts +622 -0
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-atom.ts +3 -1
- package/internal/src/families/create-atom-family.ts +3 -4
- package/internal/src/mutable/get-update-family.ts +23 -0
- package/internal/src/mutable/index.ts +1 -4
- package/internal/src/mutable/is-mutable.ts +44 -0
- package/internal/src/mutable/tracker.ts +9 -2
- package/internal/src/subject.ts +2 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +10 -1
- package/internal/src/timeline/create-timeline.ts +44 -16
- package/introspection/dist/index.cjs +12 -64
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.cts +2 -0
- package/introspection/dist/index.d.ts +396 -0
- package/introspection/dist/index.js +2 -2
- package/json/dist/index.cjs +9 -64
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.cts +2 -0
- package/json/dist/index.d.ts +417 -0
- package/json/dist/index.js +1 -1
- package/package.json +3 -2
- package/react/dist/index.cjs +9 -64
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.cts +2 -0
- package/react/dist/index.d.ts +396 -0
- package/react/dist/index.js +2 -2
- package/react-devtools/dist/index.cjs +12 -64
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.cts +2 -0
- package/react-devtools/dist/index.d.ts +467 -0
- package/react-devtools/dist/index.js +3 -3
- package/realtime-client/dist/index.cjs +9 -64
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.cts +2 -0
- package/realtime-client/dist/index.d.ts +394 -0
- package/realtime-client/dist/index.js +2 -2
- package/realtime-react/dist/index.cjs +9 -64
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +67 -0
- package/realtime-react/dist/index.js +4 -4
- package/realtime-server/dist/index.cjs +9 -64
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.cts +4 -1
- package/realtime-server/dist/index.d.ts +408 -0
- package/realtime-server/dist/index.js +1 -1
- package/realtime-testing/dist/index.cjs +104 -79
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.cts +4 -1
- package/realtime-testing/dist/index.d.ts +535 -0
- package/realtime-testing/dist/index.js +4 -4
- package/src/atom.ts +3 -1
- package/transceivers/set-rtx/dist/index.cjs +2 -1
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.d.ts +66 -0
- package/transceivers/set-rtx/dist/index.js +1 -1
- package/dist/chunk-TE3ZSTQ6.js.map +0 -1
- package/internal/src/mutable/is-atom-token-mutable.ts +0 -7
- /package/dist/{chunk-KW7RA7IM.js.map → chunk-C4YZZNRH.js.map} +0 -0
- /package/dist/{chunk-LFXB7Y6M.js.map → chunk-CWKKQKVQ.js.map} +0 -0
- /package/dist/{chunk-CK7GNCU5.js.map → chunk-GMN5KH6A.js.map} +0 -0
- /package/dist/{chunk-5VJ77LZE.js.map → chunk-N7ADBQJG.js.map} +0 -0
package/react/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,7 @@ type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomTok
|
|
|
11
11
|
key: string;
|
|
12
12
|
type: `atom_family`;
|
|
13
13
|
subject: Subject<AtomToken<T>>;
|
|
14
|
+
mutable?: boolean;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
declare const LoggerIconDictionary: {
|
|
@@ -364,6 +365,7 @@ declare class Store implements Lineage {
|
|
|
364
365
|
type Atom<T> = {
|
|
365
366
|
key: string;
|
|
366
367
|
type: `atom`;
|
|
368
|
+
mutable?: boolean;
|
|
367
369
|
family?: FamilyMetadata;
|
|
368
370
|
install: (store: Store) => void;
|
|
369
371
|
subject: Subject<{
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type primitive = boolean | number | string | null;
|
|
4
|
+
|
|
5
|
+
type Serializable = primitive | Readonly<{
|
|
6
|
+
[key: string]: Serializable;
|
|
7
|
+
}> | ReadonlyArray<Serializable>;
|
|
8
|
+
type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
9
|
+
|
|
10
|
+
type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomToken<T>) & {
|
|
11
|
+
key: string;
|
|
12
|
+
type: `atom_family`;
|
|
13
|
+
subject: Subject<AtomToken<T>>;
|
|
14
|
+
mutable?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
declare const LoggerIconDictionary: {
|
|
18
|
+
readonly "\u231B": "Timeline event fully captured";
|
|
19
|
+
readonly "\u23E9": "Timeline redo";
|
|
20
|
+
readonly "\u23EA": "Timeline undo";
|
|
21
|
+
readonly "\u23ED\uFE0F": "Transaction redo";
|
|
22
|
+
readonly "\u23EE\uFE0F": "Transaction undo";
|
|
23
|
+
readonly "\u23F3": "Timeline event partially captured";
|
|
24
|
+
readonly "\u23F9\uFE0F": "Time-travel complete";
|
|
25
|
+
readonly "\uD83D\uDC81": "Notice";
|
|
26
|
+
readonly "\uD83D\uDD04": "Realtime transaction synchronized";
|
|
27
|
+
readonly "\u2705": "Realtime transaction success";
|
|
28
|
+
readonly "\u2728": "Computation complete";
|
|
29
|
+
readonly "\u274C": "Conflict prevents attempted action";
|
|
30
|
+
readonly "\u2B55": "Operation start";
|
|
31
|
+
readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
|
|
32
|
+
readonly "\uD83D\uDC40": "Subscription added";
|
|
33
|
+
readonly "\uD83D\uDC6A": "Family member added";
|
|
34
|
+
readonly "\uD83D\uDCC1": "Stow update";
|
|
35
|
+
readonly "\uD83D\uDCC3": "Copy mutable";
|
|
36
|
+
readonly "\uD83D\uDCD6": "Read state";
|
|
37
|
+
readonly "\uD83D\uDCDD": "Write state";
|
|
38
|
+
readonly "\uD83D\uDCE2": "Notify subscribers";
|
|
39
|
+
readonly "\uD83D\uDD0C": "Register dependency";
|
|
40
|
+
readonly "\uD83D\uDD0D": "Discover root";
|
|
41
|
+
readonly "\uD83D\uDD25": "Delete state";
|
|
42
|
+
readonly "\uD83D\uDD27": "Create mutable atom";
|
|
43
|
+
readonly "\uD83D\uDD28": "Create immutable atom";
|
|
44
|
+
readonly "\uD83D\uDD34": "Operation complete";
|
|
45
|
+
readonly "\uD83D\uDDD1": "Evict cached value";
|
|
46
|
+
readonly "\uD83D\uDCA5": "Caught";
|
|
47
|
+
readonly "\uD83D\uDE48": "Subscription canceled";
|
|
48
|
+
readonly "\uD83D\uDEC4": "Apply transaction";
|
|
49
|
+
readonly "\uD83D\uDEE0\uFE0F": "Install atom into store";
|
|
50
|
+
readonly "\uD83D\uDEEB": "Begin transaction";
|
|
51
|
+
readonly "\uD83D\uDEEC": "Complete transaction";
|
|
52
|
+
readonly "\uD83E\uDDEE": "Computing selector";
|
|
53
|
+
readonly "\uD83E\uDDF9": "Prepare to evict";
|
|
54
|
+
readonly "\uD83E\uDE82": "Abort transaction";
|
|
55
|
+
};
|
|
56
|
+
type LoggerIcon = keyof typeof LoggerIconDictionary;
|
|
57
|
+
declare const LOG_LEVELS: readonly ["info", "warn", "error"];
|
|
58
|
+
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
59
|
+
type LogFn = (icon: LoggerIcon, tokenType: `atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`, tokenKey: string, message: string, ...rest: unknown[]) => void;
|
|
60
|
+
type LogFilter = (...params: Parameters<LogFn>) => boolean;
|
|
61
|
+
type Logger = Record<LogLevel, LogFn>;
|
|
62
|
+
declare class AtomIOLogger implements Logger {
|
|
63
|
+
logLevel: `error` | `info` | `warn` | null;
|
|
64
|
+
private readonly filter?;
|
|
65
|
+
private readonly logger;
|
|
66
|
+
constructor(logLevel: `error` | `info` | `warn` | null, filter?: LogFilter | undefined, logger?: Logger);
|
|
67
|
+
error: LogFn;
|
|
68
|
+
info: LogFn;
|
|
69
|
+
warn: LogFn;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type TransactionToken<_> = {
|
|
73
|
+
key: string;
|
|
74
|
+
type: `transaction`;
|
|
75
|
+
__brand?: _;
|
|
76
|
+
};
|
|
77
|
+
type TransactionUpdate<ƒ extends ƒn> = {
|
|
78
|
+
key: string;
|
|
79
|
+
updates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[];
|
|
80
|
+
params: Parameters<ƒ>;
|
|
81
|
+
output: ReturnType<ƒ>;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
type SelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => SelectorToken<T>) & {
|
|
85
|
+
key: string;
|
|
86
|
+
type: `selector_family`;
|
|
87
|
+
subject: Subject<SelectorToken<T>>;
|
|
88
|
+
};
|
|
89
|
+
type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
|
|
90
|
+
key: string;
|
|
91
|
+
type: `readonly_selector_family`;
|
|
92
|
+
subject: Subject<ReadonlySelectorToken<T>>;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
type StateUpdate<T> = {
|
|
96
|
+
newValue: T;
|
|
97
|
+
oldValue: T;
|
|
98
|
+
};
|
|
99
|
+
type KeyedStateUpdate<T> = StateUpdate<T> & {
|
|
100
|
+
key: string;
|
|
101
|
+
family?: FamilyMetadata;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
type TimelineToken = {
|
|
105
|
+
key: string;
|
|
106
|
+
type: `timeline`;
|
|
107
|
+
};
|
|
108
|
+
type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
|
|
109
|
+
|
|
110
|
+
type ƒn = (...parameters: any[]) => any;
|
|
111
|
+
type AtomToken<_> = {
|
|
112
|
+
key: string;
|
|
113
|
+
type: `atom`;
|
|
114
|
+
family?: FamilyMetadata;
|
|
115
|
+
__brand?: _;
|
|
116
|
+
};
|
|
117
|
+
interface MutableAtomToken<T extends Transceiver<any>, J extends Serializable> extends AtomToken<T> {
|
|
118
|
+
__asJSON?: J;
|
|
119
|
+
__update?: T extends Transceiver<infer Update> ? Update : never;
|
|
120
|
+
}
|
|
121
|
+
type SelectorToken<_> = {
|
|
122
|
+
key: string;
|
|
123
|
+
type: `selector`;
|
|
124
|
+
family?: FamilyMetadata;
|
|
125
|
+
__brand?: _;
|
|
126
|
+
};
|
|
127
|
+
type StateToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
128
|
+
type ReadonlySelectorToken<_> = {
|
|
129
|
+
key: string;
|
|
130
|
+
type: `readonly_selector`;
|
|
131
|
+
family?: FamilyMetadata;
|
|
132
|
+
__brand?: _;
|
|
133
|
+
};
|
|
134
|
+
type FamilyMetadata = {
|
|
135
|
+
key: string;
|
|
136
|
+
subKey: string;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
declare class Subject<T> {
|
|
140
|
+
Subscriber: (value: T) => void;
|
|
141
|
+
subscribers: Map<string, this[`Subscriber`]>;
|
|
142
|
+
subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
|
|
143
|
+
private unsubscribe;
|
|
144
|
+
next(value: T): void;
|
|
145
|
+
}
|
|
146
|
+
declare class StatefulSubject<T> extends Subject<T> {
|
|
147
|
+
state: T;
|
|
148
|
+
constructor(initialState: T);
|
|
149
|
+
next(value: T): void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type Selector<T> = {
|
|
153
|
+
key: string;
|
|
154
|
+
type: `selector`;
|
|
155
|
+
family?: FamilyMetadata;
|
|
156
|
+
install: (store: Store) => void;
|
|
157
|
+
subject: Subject<{
|
|
158
|
+
newValue: T;
|
|
159
|
+
oldValue: T;
|
|
160
|
+
}>;
|
|
161
|
+
get: () => T;
|
|
162
|
+
set: (newValue: T | ((oldValue: T) => T)) => void;
|
|
163
|
+
};
|
|
164
|
+
type ReadonlySelector<T> = {
|
|
165
|
+
key: string;
|
|
166
|
+
type: `readonly_selector`;
|
|
167
|
+
family?: FamilyMetadata;
|
|
168
|
+
install: (store: Store) => void;
|
|
169
|
+
subject: Subject<{
|
|
170
|
+
newValue: T;
|
|
171
|
+
oldValue: T;
|
|
172
|
+
}>;
|
|
173
|
+
get: () => T;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
type Transaction<ƒ extends ƒn> = {
|
|
177
|
+
key: string;
|
|
178
|
+
type: `transaction`;
|
|
179
|
+
install: (store: Store) => void;
|
|
180
|
+
subject: Subject<TransactionUpdate<ƒ>>;
|
|
181
|
+
run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
type TransactionMeta<ƒ extends ƒn> = {
|
|
185
|
+
phase: `applying` | `building`;
|
|
186
|
+
time: number;
|
|
187
|
+
update: TransactionUpdate<ƒ>;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
|
|
191
|
+
type Cardinality = `1:1` | `1:n` | `n:n`;
|
|
192
|
+
|
|
193
|
+
interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
|
|
194
|
+
readonly relations: [string, string[]][];
|
|
195
|
+
readonly contents: [string, Content][];
|
|
196
|
+
}
|
|
197
|
+
interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
|
|
198
|
+
readonly between: [a: ASide, b: BSide];
|
|
199
|
+
readonly cardinality: Cardinality;
|
|
200
|
+
}
|
|
201
|
+
type BaseExternalStoreConfiguration = {
|
|
202
|
+
addRelation: (a: string, b: string) => void;
|
|
203
|
+
deleteRelation: (a: string, b: string) => void;
|
|
204
|
+
replaceRelationsSafely: (a: string, bs: string[]) => void;
|
|
205
|
+
replaceRelationsUnsafely: (a: string, bs: string[]) => void;
|
|
206
|
+
getRelatedKeys: (key: string) => Set<string> | undefined;
|
|
207
|
+
has: (a: string, b?: string) => boolean;
|
|
208
|
+
};
|
|
209
|
+
type ExternalStoreWithContentConfiguration<Content extends Object$1> = {
|
|
210
|
+
getContent: (contentKey: string) => Content | undefined;
|
|
211
|
+
setContent: (contentKey: string, content: Content) => void;
|
|
212
|
+
deleteContent: (contentKey: string) => void;
|
|
213
|
+
};
|
|
214
|
+
type Empty<Obj extends object> = {
|
|
215
|
+
[Key in keyof Obj]?: undefined;
|
|
216
|
+
};
|
|
217
|
+
type ExternalStoreConfiguration<Content extends Object$1 | null> = Content extends Object$1 ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Object$1>>;
|
|
218
|
+
type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
|
|
219
|
+
externalStore?: ExternalStoreConfiguration<Content>;
|
|
220
|
+
isContent?: Refinement<unknown, Content>;
|
|
221
|
+
makeContentKey?: (a: string, b: string) => string;
|
|
222
|
+
};
|
|
223
|
+
type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
|
|
224
|
+
declare class Junction<const ASide extends string, const BSide extends string, const Content extends Object$1 | null = null> {
|
|
225
|
+
readonly a: ASide;
|
|
226
|
+
readonly b: BSide;
|
|
227
|
+
readonly cardinality: Cardinality;
|
|
228
|
+
readonly relations: Map<string, Set<string>>;
|
|
229
|
+
readonly contents: Map<string, Content>;
|
|
230
|
+
isContent: Refinement<unknown, Content> | null;
|
|
231
|
+
makeContentKey: (a: string, b: string) => string;
|
|
232
|
+
getRelatedKeys(key: string): Set<string> | undefined;
|
|
233
|
+
protected addRelation(a: string, b: string): void;
|
|
234
|
+
protected deleteRelation(a: string, b: string): void;
|
|
235
|
+
protected replaceRelationsUnsafely(a: string, bs: string[]): void;
|
|
236
|
+
protected replaceRelationsSafely(a: string, bs: string[]): void;
|
|
237
|
+
protected getContentInternal(contentKey: string): Content | undefined;
|
|
238
|
+
protected setContent(contentKey: string, content: Content): void;
|
|
239
|
+
protected deleteContent(contentKey: string): void;
|
|
240
|
+
constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
|
|
241
|
+
toJSON(): JunctionJSON<ASide, BSide, Content>;
|
|
242
|
+
set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
|
|
243
|
+
set(relation: {
|
|
244
|
+
[Key in ASide | BSide]: string;
|
|
245
|
+
}, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
|
|
246
|
+
delete(a: string, b?: string): this;
|
|
247
|
+
delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
|
|
248
|
+
getRelatedKey(key: string): string | undefined;
|
|
249
|
+
replaceRelations(a: string, relations: Content extends null ? string[] : Record<string, Content>, config?: {
|
|
250
|
+
reckless: boolean;
|
|
251
|
+
}): this;
|
|
252
|
+
getContent(a: string, b: string): Content | undefined;
|
|
253
|
+
getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
|
|
254
|
+
has(a: string, b?: string): boolean;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
interface Lineage {
|
|
258
|
+
parent: typeof this | null;
|
|
259
|
+
child: typeof this | null;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
interface Transceiver<Signal extends Serializable> {
|
|
263
|
+
do: (update: Signal) => void;
|
|
264
|
+
undo: (update: Signal) => void;
|
|
265
|
+
subscribe: (key: string, fn: (update: Signal) => void) => () => void;
|
|
266
|
+
cacheUpdateNumber: number;
|
|
267
|
+
getUpdateNumber: (update: Signal) => number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @internal Give the tracker a transceiver state and a store, and it will
|
|
272
|
+
* subscribe to the transceiver's inner value. When the inner value changes,
|
|
273
|
+
* the tracker will update its own state to reflect the change.
|
|
274
|
+
*/
|
|
275
|
+
declare class Tracker<Mutable extends Transceiver<any>> {
|
|
276
|
+
private Update;
|
|
277
|
+
private initializeState;
|
|
278
|
+
private unsubscribeFromInnerValue;
|
|
279
|
+
private observeCore;
|
|
280
|
+
private updateCore;
|
|
281
|
+
mutableState: MutableAtomToken<Mutable, Serializable>;
|
|
282
|
+
latestUpdateState: AtomToken<typeof this.Update | null>;
|
|
283
|
+
constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
interface MutableAtom<T> extends Atom<T> {
|
|
287
|
+
mutable: true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type OperationProgress = {
|
|
291
|
+
open: false;
|
|
292
|
+
} | {
|
|
293
|
+
open: true;
|
|
294
|
+
done: Set<string>;
|
|
295
|
+
prev: Map<string, any>;
|
|
296
|
+
time: number;
|
|
297
|
+
token: StateToken<any>;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
type TimelineAtomUpdate = StateUpdate<unknown> & {
|
|
301
|
+
key: string;
|
|
302
|
+
type: `atom_update`;
|
|
303
|
+
timestamp: number;
|
|
304
|
+
family?: FamilyMetadata;
|
|
305
|
+
};
|
|
306
|
+
type TimelineSelectorUpdate = {
|
|
307
|
+
key: string;
|
|
308
|
+
type: `selector_update`;
|
|
309
|
+
timestamp: number;
|
|
310
|
+
atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
|
|
311
|
+
};
|
|
312
|
+
type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
|
|
313
|
+
key: string;
|
|
314
|
+
type: `transaction_update`;
|
|
315
|
+
timestamp: number;
|
|
316
|
+
};
|
|
317
|
+
type Timeline = {
|
|
318
|
+
type: `timeline`;
|
|
319
|
+
key: string;
|
|
320
|
+
at: number;
|
|
321
|
+
shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
|
|
322
|
+
timeTraveling: `into_future` | `into_past` | null;
|
|
323
|
+
history: TimelineUpdate[];
|
|
324
|
+
selectorTime: number | null;
|
|
325
|
+
transactionKey: string | null;
|
|
326
|
+
install: (store: Store) => void;
|
|
327
|
+
subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
declare class Store implements Lineage {
|
|
331
|
+
parent: Store | null;
|
|
332
|
+
child: Store | null;
|
|
333
|
+
valueMap: Map<string, any>;
|
|
334
|
+
atoms: Map<string, Atom<any> | MutableAtom<any>>;
|
|
335
|
+
selectors: Map<string, Selector<any>>;
|
|
336
|
+
readonlySelectors: Map<string, ReadonlySelector<any>>;
|
|
337
|
+
trackers: Map<string, Tracker<Transceiver<any>>>;
|
|
338
|
+
families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
|
|
339
|
+
timelines: Map<string, Timeline>;
|
|
340
|
+
transactions: Map<string, Transaction<ƒn>>;
|
|
341
|
+
atomsThatAreDefault: Set<string>;
|
|
342
|
+
timelineAtoms: Junction<"timelineKey", "atomKey", null>;
|
|
343
|
+
selectorAtoms: Junction<"selectorKey", "atomKey", null>;
|
|
344
|
+
selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
|
|
345
|
+
source: string;
|
|
346
|
+
}>;
|
|
347
|
+
subject: {
|
|
348
|
+
atomCreation: Subject<AtomToken<unknown>>;
|
|
349
|
+
selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
|
|
350
|
+
transactionCreation: Subject<TransactionToken<ƒn>>;
|
|
351
|
+
timelineCreation: Subject<TimelineToken>;
|
|
352
|
+
transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
|
|
353
|
+
operationStatus: Subject<OperationProgress>;
|
|
354
|
+
};
|
|
355
|
+
operation: OperationProgress;
|
|
356
|
+
transactionMeta: TransactionMeta<ƒn> | null;
|
|
357
|
+
config: {
|
|
358
|
+
name: string;
|
|
359
|
+
};
|
|
360
|
+
loggers: AtomIOLogger[];
|
|
361
|
+
logger: Logger;
|
|
362
|
+
constructor(name: string, store?: Store | null);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
type Atom<T> = {
|
|
366
|
+
key: string;
|
|
367
|
+
type: `atom`;
|
|
368
|
+
mutable?: boolean;
|
|
369
|
+
family?: FamilyMetadata;
|
|
370
|
+
install: (store: Store) => void;
|
|
371
|
+
subject: Subject<{
|
|
372
|
+
newValue: T;
|
|
373
|
+
oldValue: T;
|
|
374
|
+
}>;
|
|
375
|
+
default: T | (() => T);
|
|
376
|
+
cleanup?: () => void;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
declare const StoreContext: React.Context<Store>;
|
|
380
|
+
declare const StoreProvider: React.FC<{
|
|
381
|
+
children: React.ReactNode;
|
|
382
|
+
store?: Store;
|
|
383
|
+
}>;
|
|
384
|
+
|
|
385
|
+
declare function useI<T>(token: StateToken<T>): <New extends T>(next: New | ((old: T) => New)) => void;
|
|
386
|
+
declare function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T;
|
|
387
|
+
declare function useJSON<Serializable extends Serializable>(token: MutableAtomToken<any, Serializable>): Serializable;
|
|
388
|
+
type TimelineMeta = {
|
|
389
|
+
at: number;
|
|
390
|
+
length: number;
|
|
391
|
+
undo: () => void;
|
|
392
|
+
redo: () => void;
|
|
393
|
+
};
|
|
394
|
+
declare function useTL(token: TimelineToken): TimelineMeta;
|
|
395
|
+
|
|
396
|
+
export { StoreContext, StoreProvider, type TimelineMeta, useI, useJSON, useO, useTL };
|
package/react/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { StoreContext, StoreProvider, useI, useJSON, useO, useTL } from '../../dist/chunk-
|
|
2
|
-
import '../../dist/chunk-
|
|
1
|
+
export { StoreContext, StoreProvider, useI, useJSON, useO, useTL } from '../../dist/chunk-CWKKQKVQ.js';
|
|
2
|
+
import '../../dist/chunk-PURABO5G.js';
|
|
3
3
|
//# sourceMappingURL=out.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -301,7 +301,8 @@ var Subject = class {
|
|
|
301
301
|
this.subscribers.delete(key);
|
|
302
302
|
}
|
|
303
303
|
next(value) {
|
|
304
|
-
|
|
304
|
+
const subscribers = this.subscribers.values();
|
|
305
|
+
for (const subscriber of subscribers) {
|
|
305
306
|
subscriber(value);
|
|
306
307
|
}
|
|
307
308
|
}
|
|
@@ -1108,35 +1109,6 @@ function createSelector(options, family, store) {
|
|
|
1108
1109
|
return createReadonlySelector(options, family, store);
|
|
1109
1110
|
}
|
|
1110
1111
|
|
|
1111
|
-
// internal/src/selector/delete-selector.ts
|
|
1112
|
-
function deleteSelector(selectorToken, store) {
|
|
1113
|
-
const target = newest(store);
|
|
1114
|
-
const { key } = selectorToken;
|
|
1115
|
-
switch (selectorToken.type) {
|
|
1116
|
-
case `selector`:
|
|
1117
|
-
target.selectors.delete(key);
|
|
1118
|
-
break;
|
|
1119
|
-
case `readonly_selector`:
|
|
1120
|
-
target.readonlySelectors.delete(key);
|
|
1121
|
-
break;
|
|
1122
|
-
}
|
|
1123
|
-
target.valueMap.delete(key);
|
|
1124
|
-
target.selectorAtoms.delete(key);
|
|
1125
|
-
const downstreamTokens = target.selectorGraph.getRelationEntries({ upstreamSelectorKey: key }).filter(([_, { source }]) => source === key).map(
|
|
1126
|
-
([downstreamSelectorKey]) => {
|
|
1127
|
-
var _a2;
|
|
1128
|
-
return (_a2 = target.selectors.get(downstreamSelectorKey)) != null ? _a2 : target.readonlySelectors.get(downstreamSelectorKey);
|
|
1129
|
-
}
|
|
1130
|
-
);
|
|
1131
|
-
for (const downstreamToken of downstreamTokens) {
|
|
1132
|
-
if (downstreamToken) {
|
|
1133
|
-
deleteSelector(downstreamToken, store);
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
target.selectorGraph.delete(key);
|
|
1137
|
-
store.logger.info(`\u{1F525}`, selectorToken.type, `${key}`, `deleted`);
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
1112
|
// internal/src/subscribe/recall-state.ts
|
|
1141
1113
|
var recallState = (state, store) => {
|
|
1142
1114
|
const target = newest(store);
|
|
@@ -1255,7 +1227,8 @@ var Tracker = class {
|
|
|
1255
1227
|
}
|
|
1256
1228
|
initializeState(mutableState, store) {
|
|
1257
1229
|
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
1258
|
-
|
|
1230
|
+
store.atoms.delete(latestUpdateStateKey);
|
|
1231
|
+
store.valueMap.delete(latestUpdateStateKey);
|
|
1259
1232
|
const familyMetaData = mutableState.family ? {
|
|
1260
1233
|
key: `*${mutableState.family.key}`,
|
|
1261
1234
|
subKey: mutableState.family.subKey
|
|
@@ -1268,6 +1241,10 @@ var Tracker = class {
|
|
|
1268
1241
|
familyMetaData,
|
|
1269
1242
|
store
|
|
1270
1243
|
);
|
|
1244
|
+
if (store.parent) {
|
|
1245
|
+
const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
|
|
1246
|
+
store.valueMap.set(latestUpdateStateKey, parentValue);
|
|
1247
|
+
}
|
|
1271
1248
|
return latestUpdateState;
|
|
1272
1249
|
}
|
|
1273
1250
|
observeCore(mutableState, latestUpdateState, store) {
|
|
@@ -1348,7 +1325,7 @@ var Tracker = class {
|
|
|
1348
1325
|
() => {
|
|
1349
1326
|
unsubscribe();
|
|
1350
1327
|
const mutable = getState(mutableState, store);
|
|
1351
|
-
const updateNumber = mutable.getUpdateNumber(newValue);
|
|
1328
|
+
const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
|
|
1352
1329
|
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
1353
1330
|
if (newValue && eventOffset === 1) {
|
|
1354
1331
|
setState(
|
|
@@ -1423,6 +1400,9 @@ function createAtomFamily(options, store) {
|
|
|
1423
1400
|
subject
|
|
1424
1401
|
}
|
|
1425
1402
|
);
|
|
1403
|
+
if (`mutable` in options && typeof options.mutable === `boolean`) {
|
|
1404
|
+
Object.assign(atomFamily2, { mutable: options.mutable });
|
|
1405
|
+
}
|
|
1426
1406
|
const target = newest(store);
|
|
1427
1407
|
target.families.set(options.key, atomFamily2);
|
|
1428
1408
|
return atomFamily2;
|
|
@@ -1626,38 +1606,6 @@ function createAtom(options, family, store) {
|
|
|
1626
1606
|
return token;
|
|
1627
1607
|
}
|
|
1628
1608
|
|
|
1629
|
-
// internal/src/atom/delete-atom.ts
|
|
1630
|
-
function deleteAtom(atomToken, store) {
|
|
1631
|
-
var _a2, _b;
|
|
1632
|
-
const target = newest(store);
|
|
1633
|
-
const { key } = atomToken;
|
|
1634
|
-
const atom2 = target.atoms.get(key);
|
|
1635
|
-
if (!atom2) {
|
|
1636
|
-
store.logger.error(
|
|
1637
|
-
`\u274C`,
|
|
1638
|
-
`atom`,
|
|
1639
|
-
`${key}`,
|
|
1640
|
-
`Tried to delete atom, but it does not exist in the store.`
|
|
1641
|
-
);
|
|
1642
|
-
}
|
|
1643
|
-
(_a2 = atom2 == null ? void 0 : atom2.cleanup) == null ? void 0 : _a2.call(atom2);
|
|
1644
|
-
target.atoms.delete(key);
|
|
1645
|
-
target.valueMap.delete(key);
|
|
1646
|
-
const selectorKeys = target.selectorAtoms.getRelatedKeys(key);
|
|
1647
|
-
if (selectorKeys) {
|
|
1648
|
-
for (const selectorKey of selectorKeys) {
|
|
1649
|
-
const token = (_b = target.selectors.get(selectorKey)) != null ? _b : target.readonlySelectors.get(selectorKey);
|
|
1650
|
-
if (token) {
|
|
1651
|
-
deleteSelector(token, store);
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
target.selectorAtoms.delete(key);
|
|
1656
|
-
target.atomsThatAreDefault.delete(key);
|
|
1657
|
-
target.timelineAtoms.delete(key);
|
|
1658
|
-
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
1609
|
// internal/src/not-found-error.ts
|
|
1662
1610
|
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
1663
1611
|
function prettyPrintTokenType(token) {
|