atom.io 0.14.4 → 0.14.5
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 +47 -1416
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.cts +8 -134
- package/data/dist/index.d.ts +8 -134
- package/data/dist/index.js +4 -6
- package/data/dist/index.js.map +1 -1
- package/dist/chunk-NYTGCPHB.js +261 -0
- package/dist/chunk-NYTGCPHB.js.map +1 -0
- package/dist/chunk-PZLG2HP3.js +36 -0
- package/dist/chunk-PZLG2HP3.js.map +1 -0
- package/dist/chunk-XACXFU3B.js +46 -0
- package/dist/chunk-XACXFU3B.js.map +1 -0
- package/dist/index.cjs +55 -2330
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +152 -1
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +30 -159
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.cts +8 -211
- package/internal/dist/index.d.ts +8 -211
- package/internal/dist/index.js +2027 -1
- package/internal/dist/index.js.map +1 -1
- package/introspection/dist/index.cjs +45 -1565
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.cts +2 -129
- package/introspection/dist/index.d.ts +2 -129
- package/introspection/dist/index.js +298 -2
- package/introspection/dist/index.js.map +1 -1
- package/json/dist/index.cjs +5 -1502
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.cts +5 -131
- package/json/dist/index.d.ts +5 -131
- package/json/dist/index.js +37 -1
- package/json/dist/index.js.map +1 -1
- package/package.json +1 -2
- package/react/dist/index.cjs +14 -1549
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.cts +8 -136
- package/react/dist/index.d.ts +8 -136
- package/react/dist/index.js +62 -2
- package/react/dist/index.js.map +1 -1
- package/react-devtools/dist/index.cjs +135 -2153
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.cts +20 -146
- package/react-devtools/dist/index.d.ts +20 -146
- package/react-devtools/dist/index.js +5 -3
- package/react-devtools/dist/index.js.map +1 -1
- package/realtime-client/dist/index.cjs +34 -1529
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.cts +11 -138
- package/realtime-client/dist/index.d.ts +11 -138
- package/realtime-client/dist/index.js +165 -2
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-react/dist/index.cjs +35 -1727
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.cts +7 -35
- package/realtime-react/dist/index.d.ts +7 -35
- package/realtime-react/dist/index.js +66 -4
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-server/dist/index.cjs +57 -1548
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.cts +15 -153
- package/realtime-server/dist/index.d.ts +15 -153
- package/realtime-server/dist/index.js +21 -27
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-testing/dist/index.cjs +15 -2376
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.cts +3 -489
- package/realtime-testing/dist/index.d.ts +3 -489
- package/realtime-testing/dist/index.js +10 -9
- package/realtime-testing/dist/index.js.map +1 -1
- package/transceivers/set-rtx/dist/index.cjs +9 -31
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.d.cts +7 -7
- package/transceivers/set-rtx/dist/index.d.ts +7 -7
- package/transceivers/set-rtx/dist/index.js +3 -2
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/dist/chunk-GMN5KH6A.js +0 -309
- package/dist/chunk-GMN5KH6A.js.map +0 -1
- package/dist/chunk-HQWWV67P.js +0 -62
- package/dist/chunk-HQWWV67P.js.map +0 -1
- package/dist/chunk-MK4OJD24.js +0 -67
- package/dist/chunk-MK4OJD24.js.map +0 -1
- package/dist/chunk-N7ADBQJG.js +0 -176
- package/dist/chunk-N7ADBQJG.js.map +0 -1
- package/dist/chunk-PURABO5G.js +0 -2581
- package/dist/chunk-PURABO5G.js.map +0 -1
- package/dist/index.d.cts +0 -493
- package/dist/index.d.ts +0 -493
- package/dist/metafile-cjs.json +0 -1
- package/dist/metafile-esm.json +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,154 @@
|
|
|
1
|
-
|
|
1
|
+
import './chunk-PZLG2HP3.js';
|
|
2
|
+
import * as Internal3 from 'atom.io/internal';
|
|
3
|
+
import { createMutableAtom, IMPLICIT, createAtom, createMutableAtomFamily, createAtomFamily, createSelector, createSelectorFamily, Store, createTransaction, createTimeline, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, withdraw } from 'atom.io/internal';
|
|
4
|
+
|
|
5
|
+
function atom(options) {
|
|
6
|
+
if (`mutable` in options) {
|
|
7
|
+
return createMutableAtom(options, IMPLICIT.STORE);
|
|
8
|
+
}
|
|
9
|
+
return createAtom(options, void 0, IMPLICIT.STORE);
|
|
10
|
+
}
|
|
11
|
+
function atomFamily(options) {
|
|
12
|
+
if (`mutable` in options) {
|
|
13
|
+
return createMutableAtomFamily(options, IMPLICIT.STORE);
|
|
14
|
+
}
|
|
15
|
+
return createAtomFamily(options, IMPLICIT.STORE);
|
|
16
|
+
}
|
|
17
|
+
function dispose(token, store = Internal3.IMPLICIT.STORE) {
|
|
18
|
+
switch (token.type) {
|
|
19
|
+
case `atom`:
|
|
20
|
+
Internal3.deleteAtom(token, store);
|
|
21
|
+
break;
|
|
22
|
+
case `selector`:
|
|
23
|
+
case `readonly_selector`:
|
|
24
|
+
Internal3.deleteSelector(token, store);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getState(token, store = Internal3.IMPLICIT.STORE) {
|
|
29
|
+
var _a;
|
|
30
|
+
const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
|
|
31
|
+
if (state === void 0) {
|
|
32
|
+
throw new Internal3.NotFoundError(token, store);
|
|
33
|
+
}
|
|
34
|
+
return Internal3.readOrComputeValue(state, store);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/logger.ts
|
|
38
|
+
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
39
|
+
var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
|
|
40
|
+
console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
|
|
41
|
+
};
|
|
42
|
+
var simpleLogger = {
|
|
43
|
+
error: simpleLog(`error`),
|
|
44
|
+
info: simpleLog(`info`),
|
|
45
|
+
warn: simpleLog(`warn`)
|
|
46
|
+
};
|
|
47
|
+
var AtomIOLogger = class {
|
|
48
|
+
constructor(logLevel, filter, logger = simpleLogger) {
|
|
49
|
+
this.logLevel = logLevel;
|
|
50
|
+
this.filter = filter;
|
|
51
|
+
this.logger = logger;
|
|
52
|
+
this.error = (...args) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
|
|
55
|
+
this.logger.error(...args);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this.info = (...args) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
|
|
61
|
+
this.logger.info(...args);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.warn = (...args) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
67
|
+
this.logger.warn(...args);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function selector(options) {
|
|
73
|
+
return createSelector(options, void 0, IMPLICIT.STORE);
|
|
74
|
+
}
|
|
75
|
+
function selectorFamily(options) {
|
|
76
|
+
return createSelectorFamily(options, IMPLICIT.STORE);
|
|
77
|
+
}
|
|
78
|
+
function setState(token, value, store = Internal3.IMPLICIT.STORE) {
|
|
79
|
+
var _a;
|
|
80
|
+
const rejection = Internal3.openOperation(token, store);
|
|
81
|
+
if (rejection) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
|
|
85
|
+
if (state === void 0) {
|
|
86
|
+
throw new Internal3.NotFoundError(token, store);
|
|
87
|
+
}
|
|
88
|
+
Internal3.setAtomOrSelector(state, value, store);
|
|
89
|
+
Internal3.closeOperation(store);
|
|
90
|
+
}
|
|
91
|
+
var Silo = class {
|
|
92
|
+
constructor(name, fromStore = null) {
|
|
93
|
+
const s = new Store(name, fromStore);
|
|
94
|
+
this.store = s;
|
|
95
|
+
this.atom = (options) => {
|
|
96
|
+
if (`mutable` in options) {
|
|
97
|
+
return createMutableAtom(options, s);
|
|
98
|
+
}
|
|
99
|
+
return createAtom(options, void 0, s);
|
|
100
|
+
};
|
|
101
|
+
this.atomFamily = (options) => {
|
|
102
|
+
if (`mutable` in options) {
|
|
103
|
+
return createMutableAtomFamily(options, s);
|
|
104
|
+
}
|
|
105
|
+
return createAtomFamily(options, s);
|
|
106
|
+
};
|
|
107
|
+
this.selector = (options) => createSelector(options, void 0, s);
|
|
108
|
+
this.selectorFamily = (options) => createSelectorFamily(options, s);
|
|
109
|
+
this.transaction = (options) => createTransaction(options, s);
|
|
110
|
+
this.timeline = (options) => createTimeline(options, s);
|
|
111
|
+
this.getState = (token) => getState(token, s);
|
|
112
|
+
this.setState = (token, newValue) => setState(token, newValue, s);
|
|
113
|
+
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
|
|
114
|
+
this.undo = (token) => timeTravel(`backward`, token, s);
|
|
115
|
+
this.redo = (token) => timeTravel(`forward`, token, s);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
|
|
119
|
+
switch (token.type) {
|
|
120
|
+
case `atom`:
|
|
121
|
+
case `readonly_selector`:
|
|
122
|
+
case `selector`:
|
|
123
|
+
return subscribeToState(token, handleUpdate, key, store);
|
|
124
|
+
case `transaction`:
|
|
125
|
+
return subscribeToTransaction(token, handleUpdate, key, store);
|
|
126
|
+
case `timeline`:
|
|
127
|
+
return subscribeToTimeline(token, handleUpdate, key, store);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
var timeline = (options) => {
|
|
131
|
+
return createTimeline(options, IMPLICIT.STORE);
|
|
132
|
+
};
|
|
133
|
+
var redo = (timeline2) => {
|
|
134
|
+
timeTravel(`forward`, timeline2, IMPLICIT.STORE);
|
|
135
|
+
};
|
|
136
|
+
var undo = (timeline2) => {
|
|
137
|
+
timeTravel(`backward`, timeline2, IMPLICIT.STORE);
|
|
138
|
+
};
|
|
139
|
+
function transaction(options) {
|
|
140
|
+
return createTransaction(options, IMPLICIT.STORE);
|
|
141
|
+
}
|
|
142
|
+
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
143
|
+
const tx = withdraw(token, store);
|
|
144
|
+
if (tx) {
|
|
145
|
+
return tx.run(...parameters);
|
|
146
|
+
}
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
2
153
|
//# sourceMappingURL=out.js.map
|
|
3
154
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,SAAS,SAAS,KAAK;AAAA,EACjD;AACA,SAAO,WAAc,SAAS,QAAW,SAAS,KAAK;AACxD;AAiDO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,SAAS,SAAS,KAAK;AAAA,EACvD;AACA,SAAO,iBAAuB,SAAS,SAAS,KAAK;AACtD;;;ACpGA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACjBA,YAAYA,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AAPL;AAQC,QAAM,SACL,KAAS,mBAAS,OAAO,KAAK,MAA9B,YACS,kCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAa,wBAAc,OAAO,KAAK;AAAA,EAC9C;AACA,SAAgB,6BAAmB,OAAO,KAAK;AAChD;;;AC0BO,IAAM,aAAa,CAAC,QAAQ,QAAQ,OAAO;AAqB3C,IAAM,YACZ,CAAC,aACD,CAAC,MAAM,WAAW,UAAU,YAAY,SAAS;AAChD,UAAQ,QAAQ,EAAE,GAAG,IAAI,IAAI,SAAS,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,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options, IMPLICIT.STORE)\n\t}\n\treturn createAtom<T>(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options, IMPLICIT.STORE)\n\t}\n\treturn createAtomFamily<T, K>(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken:\n\t\t| ReadonlySelectorToken<any>\n\t\t| StateToken<any>\n\t\t| TimelineToken\n\t\t| TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Act<ƒ extends ƒn> = (\n\ttransactors: Transactors & { run: typeof runTransaction },\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Act<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
|
package/internal/dist/index.cjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var atom_io = require('atom.io');
|
|
4
|
+
var json = require('atom.io/json');
|
|
5
|
+
var internal = require('atom.io/internal');
|
|
6
|
+
|
|
3
7
|
var __defProp = Object.defineProperty;
|
|
4
8
|
var __defProps = Object.defineProperties;
|
|
5
9
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -20,77 +24,6 @@ var __spreadValues = (a, b) => {
|
|
|
20
24
|
};
|
|
21
25
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
26
|
|
|
23
|
-
// src/get-state.ts
|
|
24
|
-
function getState(token, store = IMPLICIT.STORE) {
|
|
25
|
-
var _a;
|
|
26
|
-
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
27
|
-
if (state === void 0) {
|
|
28
|
-
throw new NotFoundError(token, store);
|
|
29
|
-
}
|
|
30
|
-
return readOrComputeValue(state, store);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/logger.ts
|
|
34
|
-
var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
|
|
35
|
-
console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
|
|
36
|
-
};
|
|
37
|
-
var simpleLogger = {
|
|
38
|
-
error: simpleLog(`error`),
|
|
39
|
-
info: simpleLog(`info`),
|
|
40
|
-
warn: simpleLog(`warn`)
|
|
41
|
-
};
|
|
42
|
-
var AtomIOLogger = class {
|
|
43
|
-
constructor(logLevel, filter, logger = simpleLogger) {
|
|
44
|
-
this.logLevel = logLevel;
|
|
45
|
-
this.filter = filter;
|
|
46
|
-
this.logger = logger;
|
|
47
|
-
this.error = (...args) => {
|
|
48
|
-
var _a, _b;
|
|
49
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
|
|
50
|
-
this.logger.error(...args);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
this.info = (...args) => {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
|
|
56
|
-
this.logger.info(...args);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
this.warn = (...args) => {
|
|
60
|
-
var _a, _b;
|
|
61
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
62
|
-
this.logger.warn(...args);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// src/set-state.ts
|
|
69
|
-
function setState(token, value, store = IMPLICIT.STORE) {
|
|
70
|
-
var _a;
|
|
71
|
-
const rejection = openOperation(token, store);
|
|
72
|
-
if (rejection) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
76
|
-
if (state === void 0) {
|
|
77
|
-
throw new NotFoundError(token, store);
|
|
78
|
-
}
|
|
79
|
-
setAtomOrSelector(state, value, store);
|
|
80
|
-
closeOperation(store);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/transaction.ts
|
|
84
|
-
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
85
|
-
const tx = withdraw(token, store);
|
|
86
|
-
if (tx) {
|
|
87
|
-
return tx.run(...parameters);
|
|
88
|
-
}
|
|
89
|
-
throw new Error(
|
|
90
|
-
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
27
|
// internal/src/future.ts
|
|
95
28
|
var Future = class extends Promise {
|
|
96
29
|
constructor(executor) {
|
|
@@ -169,44 +102,6 @@ var evictCachedValue = (key, store) => {
|
|
|
169
102
|
store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
170
103
|
};
|
|
171
104
|
|
|
172
|
-
// ../anvl/src/json/index.ts
|
|
173
|
-
var parseJson = (str) => JSON.parse(str);
|
|
174
|
-
var stringifyJson = (json) => JSON.stringify(json);
|
|
175
|
-
|
|
176
|
-
// json/src/select-json.ts
|
|
177
|
-
var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
|
|
178
|
-
return createSelector(
|
|
179
|
-
{
|
|
180
|
-
key: `${atom.key}:JSON`,
|
|
181
|
-
get: ({ get }) => transform.toJson(get(atom)),
|
|
182
|
-
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
|
|
183
|
-
},
|
|
184
|
-
void 0,
|
|
185
|
-
store
|
|
186
|
-
);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// json/src/select-json-family.ts
|
|
190
|
-
var selectJsonFamily = (atomFamily, transform, store = IMPLICIT.STORE) => {
|
|
191
|
-
const jsonFamily = createSelectorFamily(
|
|
192
|
-
{
|
|
193
|
-
key: `${atomFamily.key}:JSON`,
|
|
194
|
-
get: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),
|
|
195
|
-
set: (key) => ({ set }, newValue) => set(atomFamily(key), transform.fromJson(newValue))
|
|
196
|
-
},
|
|
197
|
-
store
|
|
198
|
-
);
|
|
199
|
-
atomFamily.subject.subscribe(
|
|
200
|
-
`store=${store.config.name}::json-selector-family`,
|
|
201
|
-
(token) => {
|
|
202
|
-
if (token.family) {
|
|
203
|
-
jsonFamily(parseJson(token.family.subKey));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
return jsonFamily;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
105
|
// internal/src/read-or-compute-value.ts
|
|
211
106
|
var readOrComputeValue = (state, store) => {
|
|
212
107
|
if (isValueCached(state.key, store)) {
|
|
@@ -813,7 +708,7 @@ var Store = class {
|
|
|
813
708
|
name: `IMPLICIT_STORE`
|
|
814
709
|
};
|
|
815
710
|
this.loggers = [
|
|
816
|
-
new AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
|
|
711
|
+
new atom_io.AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
|
|
817
712
|
];
|
|
818
713
|
this.logger = {
|
|
819
714
|
error: (...messages) => {
|
|
@@ -1204,10 +1099,8 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1204
1099
|
});
|
|
1205
1100
|
return dependencySubscriptions;
|
|
1206
1101
|
};
|
|
1207
|
-
|
|
1208
|
-
// internal/src/subscribe/subscribe-to-state.ts
|
|
1209
1102
|
function subscribeToState(token, handleUpdate, key, store) {
|
|
1210
|
-
const state = withdraw(token, store);
|
|
1103
|
+
const state = internal.withdraw(token, store);
|
|
1211
1104
|
if (state === void 0) {
|
|
1212
1105
|
throw new Error(
|
|
1213
1106
|
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
@@ -1215,7 +1108,7 @@ function subscribeToState(token, handleUpdate, key, store) {
|
|
|
1215
1108
|
}
|
|
1216
1109
|
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
1217
1110
|
store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
|
|
1218
|
-
const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
|
|
1111
|
+
const dependencyUnsubFunctions = state.type !== `atom` ? internal.subscribeToRootAtoms(state, store) : null;
|
|
1219
1112
|
const unsubscribe = dependencyUnsubFunctions === null ? () => {
|
|
1220
1113
|
store.logger.info(
|
|
1221
1114
|
`\u{1F648}`,
|
|
@@ -1238,10 +1131,8 @@ function subscribeToState(token, handleUpdate, key, store) {
|
|
|
1238
1131
|
};
|
|
1239
1132
|
return unsubscribe;
|
|
1240
1133
|
}
|
|
1241
|
-
|
|
1242
|
-
// internal/src/subscribe/subscribe-to-timeline.ts
|
|
1243
1134
|
var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
1244
|
-
const tl = withdraw(token, store);
|
|
1135
|
+
const tl = internal.withdraw(token, store);
|
|
1245
1136
|
if (tl === void 0) {
|
|
1246
1137
|
throw new Error(
|
|
1247
1138
|
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
@@ -1259,10 +1150,8 @@ var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
|
1259
1150
|
unsubscribe();
|
|
1260
1151
|
};
|
|
1261
1152
|
};
|
|
1262
|
-
|
|
1263
|
-
// internal/src/subscribe/subscribe-to-transaction.ts
|
|
1264
1153
|
var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
1265
|
-
const tx = withdraw(token, store);
|
|
1154
|
+
const tx = internal.withdraw(token, store);
|
|
1266
1155
|
if (tx === void 0) {
|
|
1267
1156
|
throw new Error(
|
|
1268
1157
|
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
@@ -1285,8 +1174,6 @@ var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
|
1285
1174
|
unsubscribe();
|
|
1286
1175
|
};
|
|
1287
1176
|
};
|
|
1288
|
-
|
|
1289
|
-
// internal/src/mutable/tracker.ts
|
|
1290
1177
|
var Tracker = class {
|
|
1291
1178
|
constructor(mutableState, store) {
|
|
1292
1179
|
this.unsubscribeFromInnerValue = null;
|
|
@@ -1320,7 +1207,7 @@ var Tracker = class {
|
|
|
1320
1207
|
return latestUpdateState;
|
|
1321
1208
|
}
|
|
1322
1209
|
observeCore(mutableState, latestUpdateState, store) {
|
|
1323
|
-
const originalInnerValue = getState(mutableState, store);
|
|
1210
|
+
const originalInnerValue = atom_io.getState(mutableState, store);
|
|
1324
1211
|
const target = newest(store);
|
|
1325
1212
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
1326
1213
|
`tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
|
|
@@ -1329,7 +1216,7 @@ var Tracker = class {
|
|
|
1329
1216
|
mutableState.key,
|
|
1330
1217
|
() => {
|
|
1331
1218
|
unsubscribe();
|
|
1332
|
-
setState(latestUpdateState, update, store);
|
|
1219
|
+
atom_io.setState(latestUpdateState, update, store);
|
|
1333
1220
|
}
|
|
1334
1221
|
);
|
|
1335
1222
|
}
|
|
@@ -1348,7 +1235,7 @@ var Tracker = class {
|
|
|
1348
1235
|
mutableState.key,
|
|
1349
1236
|
() => {
|
|
1350
1237
|
unsubscribe();
|
|
1351
|
-
setState(latestUpdateState, update2, store);
|
|
1238
|
+
atom_io.setState(latestUpdateState, update2, store);
|
|
1352
1239
|
}
|
|
1353
1240
|
);
|
|
1354
1241
|
}
|
|
@@ -1373,7 +1260,7 @@ var Tracker = class {
|
|
|
1373
1260
|
{ key: timelineId, type: `timeline` },
|
|
1374
1261
|
(update) => {
|
|
1375
1262
|
unsubscribe2();
|
|
1376
|
-
setState(
|
|
1263
|
+
atom_io.setState(
|
|
1377
1264
|
mutableState,
|
|
1378
1265
|
(transceiver) => {
|
|
1379
1266
|
if (update === `redo` && newValue) {
|
|
@@ -1396,11 +1283,11 @@ var Tracker = class {
|
|
|
1396
1283
|
latestUpdateState.key,
|
|
1397
1284
|
() => {
|
|
1398
1285
|
unsubscribe();
|
|
1399
|
-
const mutable = getState(mutableState, store);
|
|
1286
|
+
const mutable = atom_io.getState(mutableState, store);
|
|
1400
1287
|
const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
|
|
1401
1288
|
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
1402
1289
|
if (newValue && eventOffset === 1) {
|
|
1403
|
-
setState(
|
|
1290
|
+
atom_io.setState(
|
|
1404
1291
|
mutableState,
|
|
1405
1292
|
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
1406
1293
|
store
|
|
@@ -1425,7 +1312,7 @@ function createMutableAtom(options, store) {
|
|
|
1425
1312
|
);
|
|
1426
1313
|
const coreState = createAtom(options, void 0, store);
|
|
1427
1314
|
new Tracker(coreState, store);
|
|
1428
|
-
const jsonState = selectJson(coreState, options, store);
|
|
1315
|
+
const jsonState = json.selectJson(coreState, options, store);
|
|
1429
1316
|
const target = newest(store);
|
|
1430
1317
|
subscribeToState(
|
|
1431
1318
|
jsonState,
|
|
@@ -1440,13 +1327,11 @@ function createMutableAtom(options, store) {
|
|
|
1440
1327
|
);
|
|
1441
1328
|
return coreState;
|
|
1442
1329
|
}
|
|
1443
|
-
|
|
1444
|
-
// internal/src/families/create-atom-family.ts
|
|
1445
1330
|
function createAtomFamily(options, store) {
|
|
1446
1331
|
const subject = new Subject();
|
|
1447
1332
|
const atomFamily = Object.assign(
|
|
1448
1333
|
(key) => {
|
|
1449
|
-
const subKey = stringifyJson(key);
|
|
1334
|
+
const subKey = json.stringifyJson(key);
|
|
1450
1335
|
const family = { key: options.key, subKey };
|
|
1451
1336
|
const fullKey = `${options.key}(${subKey})`;
|
|
1452
1337
|
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
@@ -1479,14 +1364,12 @@ function createAtomFamily(options, store) {
|
|
|
1479
1364
|
target.families.set(options.key, atomFamily);
|
|
1480
1365
|
return atomFamily;
|
|
1481
1366
|
}
|
|
1482
|
-
|
|
1483
|
-
// internal/src/families/create-readonly-selector-family.ts
|
|
1484
1367
|
function createReadonlySelectorFamily(options, store) {
|
|
1485
1368
|
const subject = new Subject();
|
|
1486
1369
|
return Object.assign(
|
|
1487
1370
|
(key) => {
|
|
1488
1371
|
const target = newest(store);
|
|
1489
|
-
const subKey = stringifyJson(key);
|
|
1372
|
+
const subKey = json.stringifyJson(key);
|
|
1490
1373
|
const family = { key: options.key, subKey };
|
|
1491
1374
|
const fullKey = `${options.key}(${subKey})`;
|
|
1492
1375
|
const existing = target.readonlySelectors.get(fullKey);
|
|
@@ -1509,8 +1392,6 @@ function createReadonlySelectorFamily(options, store) {
|
|
|
1509
1392
|
}
|
|
1510
1393
|
);
|
|
1511
1394
|
}
|
|
1512
|
-
|
|
1513
|
-
// internal/src/families/create-selector-family.ts
|
|
1514
1395
|
function createSelectorFamily(options, store) {
|
|
1515
1396
|
const isReadonly = !(`set` in options);
|
|
1516
1397
|
if (isReadonly) {
|
|
@@ -1520,7 +1401,7 @@ function createSelectorFamily(options, store) {
|
|
|
1520
1401
|
const subject = new Subject();
|
|
1521
1402
|
const selectorFamily = Object.assign(
|
|
1522
1403
|
(key) => {
|
|
1523
|
-
const subKey = stringifyJson(key);
|
|
1404
|
+
const subKey = json.stringifyJson(key);
|
|
1524
1405
|
const family = { key: options.key, subKey };
|
|
1525
1406
|
const fullKey = `${options.key}(${subKey})`;
|
|
1526
1407
|
const existing = target.selectors.get(fullKey);
|
|
@@ -1563,7 +1444,7 @@ var FamilyTracker = class {
|
|
|
1563
1444
|
`store=${store.config.name}::tracker-atom-family`,
|
|
1564
1445
|
(atomToken) => {
|
|
1565
1446
|
if (atomToken.family) {
|
|
1566
|
-
const key = parseJson(atomToken.family.subKey);
|
|
1447
|
+
const key = json.parseJson(atomToken.family.subKey);
|
|
1567
1448
|
this.findLatestUpdateState(key);
|
|
1568
1449
|
new Tracker(atomToken, store);
|
|
1569
1450
|
}
|
|
@@ -1573,7 +1454,7 @@ var FamilyTracker = class {
|
|
|
1573
1454
|
`store=${store.config.name}::tracker-atom-family`,
|
|
1574
1455
|
(atomToken) => {
|
|
1575
1456
|
if (atomToken.family) {
|
|
1576
|
-
const key = parseJson(atomToken.family.subKey);
|
|
1457
|
+
const key = json.parseJson(atomToken.family.subKey);
|
|
1577
1458
|
const mutableAtomToken = this.findMutableState(key);
|
|
1578
1459
|
new Tracker(mutableAtomToken, store);
|
|
1579
1460
|
}
|
|
@@ -1588,7 +1469,7 @@ function createMutableAtomFamily(options, store) {
|
|
|
1588
1469
|
createAtomFamily(options, store),
|
|
1589
1470
|
options
|
|
1590
1471
|
);
|
|
1591
|
-
selectJsonFamily(coreFamily, options);
|
|
1472
|
+
json.selectJsonFamily(coreFamily, options);
|
|
1592
1473
|
new FamilyTracker(coreFamily, store);
|
|
1593
1474
|
return coreFamily;
|
|
1594
1475
|
}
|
|
@@ -1708,7 +1589,7 @@ function createAtom(options, family, store) {
|
|
|
1708
1589
|
const cleanupFunctions = [];
|
|
1709
1590
|
for (const effect of options.effects) {
|
|
1710
1591
|
const cleanup = effect({
|
|
1711
|
-
setSelf: (next) => setState(token, next, store),
|
|
1592
|
+
setSelf: (next) => atom_io.setState(token, next, store),
|
|
1712
1593
|
onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
|
|
1713
1594
|
});
|
|
1714
1595
|
if (cleanup) {
|
|
@@ -2127,8 +2008,6 @@ function createTimeline(options, store, data) {
|
|
|
2127
2008
|
store.subject.timelineCreation.next(token);
|
|
2128
2009
|
return token;
|
|
2129
2010
|
}
|
|
2130
|
-
|
|
2131
|
-
// internal/src/timeline/time-travel.ts
|
|
2132
2011
|
var timeTravel = (direction, token, store) => {
|
|
2133
2012
|
const action = direction === `forward` ? `redo` : `undo`;
|
|
2134
2013
|
store.logger.info(
|
|
@@ -2164,7 +2043,7 @@ var timeTravel = (direction, token, store) => {
|
|
|
2164
2043
|
const updateValues = (atomUpdate) => {
|
|
2165
2044
|
const { key, newValue, oldValue } = atomUpdate;
|
|
2166
2045
|
const value = direction === `forward` ? newValue : oldValue;
|
|
2167
|
-
setState({ key, type: `atom` }, value, store);
|
|
2046
|
+
atom_io.setState({ key, type: `atom` }, value, store);
|
|
2168
2047
|
};
|
|
2169
2048
|
const updateValuesFromTransactionUpdate = (transactionUpdate) => {
|
|
2170
2049
|
const updates = direction === `forward` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
|
|
@@ -2226,8 +2105,6 @@ var abortTransaction = (store) => {
|
|
|
2226
2105
|
);
|
|
2227
2106
|
target.parent.child = null;
|
|
2228
2107
|
};
|
|
2229
|
-
|
|
2230
|
-
// internal/src/transaction/apply-transaction.ts
|
|
2231
2108
|
function ingestAtomUpdate(update, parent, child) {
|
|
2232
2109
|
var _a, _b, _c;
|
|
2233
2110
|
const { key, newValue } = update;
|
|
@@ -2255,7 +2132,7 @@ function ingestAtomUpdate(update, parent, child) {
|
|
|
2255
2132
|
);
|
|
2256
2133
|
}
|
|
2257
2134
|
}
|
|
2258
|
-
setState(token, newValue, parent);
|
|
2135
|
+
atom_io.setState(token, newValue, parent);
|
|
2259
2136
|
}
|
|
2260
2137
|
function ingestTransactionUpdate(transactionUpdate, parent, child) {
|
|
2261
2138
|
for (const update of transactionUpdate.updates) {
|
|
@@ -2355,8 +2232,6 @@ var buildTransaction = (key, params, store) => {
|
|
|
2355
2232
|
params
|
|
2356
2233
|
);
|
|
2357
2234
|
};
|
|
2358
|
-
|
|
2359
|
-
// internal/src/transaction/create-transaction.ts
|
|
2360
2235
|
function createTransaction(options, store) {
|
|
2361
2236
|
const newTransaction = {
|
|
2362
2237
|
key: options.key,
|
|
@@ -2366,9 +2241,9 @@ function createTransaction(options, store) {
|
|
|
2366
2241
|
try {
|
|
2367
2242
|
const output = options.do(
|
|
2368
2243
|
{
|
|
2369
|
-
get: (token2) => getState(token2, store),
|
|
2370
|
-
set: (token2, value) => setState(token2, value, store),
|
|
2371
|
-
run: (token2) => runTransaction(token2, store)
|
|
2244
|
+
get: (token2) => atom_io.getState(token2, store),
|
|
2245
|
+
set: (token2, value) => atom_io.setState(token2, value, store),
|
|
2246
|
+
run: (token2) => atom_io.runTransaction(token2, store)
|
|
2372
2247
|
},
|
|
2373
2248
|
...params
|
|
2374
2249
|
);
|
|
@@ -2389,8 +2264,6 @@ function createTransaction(options, store) {
|
|
|
2389
2264
|
store.subject.transactionCreation.next(token);
|
|
2390
2265
|
return token;
|
|
2391
2266
|
}
|
|
2392
|
-
|
|
2393
|
-
// internal/src/transaction/redo-transaction.ts
|
|
2394
2267
|
var redoTransactionUpdate = (transactionUpdate, store) => {
|
|
2395
2268
|
store.logger.info(`\u23ED\uFE0F`, `transaction`, transactionUpdate.key, `Redo`);
|
|
2396
2269
|
for (const update of transactionUpdate.updates) {
|
|
@@ -2403,14 +2276,12 @@ var redoTransactionUpdate = (transactionUpdate, store) => {
|
|
|
2403
2276
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
2404
2277
|
);
|
|
2405
2278
|
}
|
|
2406
|
-
setState(state, newValue, store);
|
|
2279
|
+
atom_io.setState(state, newValue, store);
|
|
2407
2280
|
} else {
|
|
2408
2281
|
redoTransactionUpdate(update, store);
|
|
2409
2282
|
}
|
|
2410
2283
|
}
|
|
2411
2284
|
};
|
|
2412
|
-
|
|
2413
|
-
// internal/src/transaction/undo-transaction.ts
|
|
2414
2285
|
var undoTransactionUpdate = (transactionUpdate, store) => {
|
|
2415
2286
|
store.logger.info(`\u23EE\uFE0F`, `transaction`, transactionUpdate.key, `Undo`);
|
|
2416
2287
|
for (const update of transactionUpdate.updates.reverse()) {
|
|
@@ -2423,7 +2294,7 @@ var undoTransactionUpdate = (transactionUpdate, store) => {
|
|
|
2423
2294
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
2424
2295
|
);
|
|
2425
2296
|
}
|
|
2426
|
-
setState(state, newValue, store);
|
|
2297
|
+
atom_io.setState(state, newValue, store);
|
|
2427
2298
|
} else {
|
|
2428
2299
|
undoTransactionUpdate(update, store);
|
|
2429
2300
|
}
|