atom.io 0.2.0 → 0.3.1
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/README.md +8 -15
- package/dist/index.d.ts +507 -4
- package/dist/index.js +924 -368
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +913 -364
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -6
- package/{dist/react → react/dist}/index.d.ts +2 -5
- package/react/dist/index.js +68 -0
- package/react/dist/index.js.map +1 -0
- package/react/dist/index.mjs +44 -0
- package/react/dist/index.mjs.map +1 -0
- package/react/package.json +12 -3
- package/src/atom.ts +18 -53
- package/src/index.ts +29 -37
- package/src/internal/atom-internal.ts +50 -0
- package/src/internal/families-internal.ts +142 -0
- package/src/internal/get.ts +41 -43
- package/src/internal/index.ts +5 -17
- package/src/internal/is-default.ts +20 -4
- package/src/internal/operation.ts +111 -16
- package/src/internal/selector-internal.ts +116 -15
- package/src/internal/set.ts +31 -17
- package/src/internal/store.ts +57 -45
- package/src/internal/subscribe-internal.ts +55 -11
- package/src/internal/timeline-internal.ts +293 -0
- package/src/internal/transaction-internal.ts +157 -16
- package/src/logger.ts +46 -0
- package/src/react/index.ts +5 -6
- package/src/selector.ts +34 -104
- package/src/subscribe.ts +55 -0
- package/src/timeline.ts +29 -0
- package/src/transaction.ts +29 -36
- package/dist/index-9d9f5a05.d.ts +0 -293
- package/dist/react/index.js +0 -909
- package/dist/react/index.js.map +0 -1
- package/dist/react/index.mjs +0 -880
- package/dist/react/index.mjs.map +0 -1
package/dist/react/index.js
DELETED
|
@@ -1,909 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
|
-
var __export = (target, all) => {
|
|
37
|
-
for (var name in all)
|
|
38
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
-
};
|
|
40
|
-
var __copyProps = (to, from, except, desc) => {
|
|
41
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
-
for (let key of __getOwnPropNames(from))
|
|
43
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
-
}
|
|
46
|
-
return to;
|
|
47
|
-
};
|
|
48
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
49
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
50
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
51
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
52
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
53
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
54
|
-
mod
|
|
55
|
-
));
|
|
56
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
57
|
-
|
|
58
|
-
// src/react/index.ts
|
|
59
|
-
var react_exports = {};
|
|
60
|
-
__export(react_exports, {
|
|
61
|
-
composeStoreHooks: () => composeStoreHooks
|
|
62
|
-
});
|
|
63
|
-
module.exports = __toCommonJS(react_exports);
|
|
64
|
-
|
|
65
|
-
// src/internal/index.ts
|
|
66
|
-
var internal_exports = {};
|
|
67
|
-
__export(internal_exports, {
|
|
68
|
-
IMPLICIT: () => IMPLICIT,
|
|
69
|
-
abortTransaction: () => abortTransaction,
|
|
70
|
-
clearStore: () => clearStore,
|
|
71
|
-
configure: () => configure,
|
|
72
|
-
createStore: () => createStore,
|
|
73
|
-
deposit: () => deposit,
|
|
74
|
-
evictDownStream: () => evictDownStream,
|
|
75
|
-
finishAction: () => finishAction,
|
|
76
|
-
finishTransaction: () => finishTransaction,
|
|
77
|
-
getCachedState: () => getCachedState,
|
|
78
|
-
getSelectorState: () => getSelectorState,
|
|
79
|
-
getState__INTERNAL: () => getState__INTERNAL,
|
|
80
|
-
isAtomDefault: () => isAtomDefault,
|
|
81
|
-
isDone: () => isDone,
|
|
82
|
-
isSelectorDefault: () => isSelectorDefault,
|
|
83
|
-
lookup: () => lookup,
|
|
84
|
-
lookupSelectorSources: () => lookupSelectorSources,
|
|
85
|
-
markDone: () => markDone,
|
|
86
|
-
recallState: () => recallState,
|
|
87
|
-
registerSelector: () => registerSelector,
|
|
88
|
-
setAtomState: () => setAtomState,
|
|
89
|
-
setSelectorState: () => setSelectorState,
|
|
90
|
-
setState__INTERNAL: () => setState__INTERNAL,
|
|
91
|
-
startAction: () => startAction,
|
|
92
|
-
startTransaction: () => startTransaction,
|
|
93
|
-
subscribeToRootAtoms: () => subscribeToRootAtoms,
|
|
94
|
-
traceAllSelectorAtoms: () => traceAllSelectorAtoms,
|
|
95
|
-
traceSelectorAtoms: () => traceSelectorAtoms,
|
|
96
|
-
updateSelectorAtoms: () => updateSelectorAtoms,
|
|
97
|
-
withdraw: () => withdraw
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// src/internal/get.ts
|
|
101
|
-
var import_function7 = require("fp-ts/function");
|
|
102
|
-
var import_hamt_plus2 = __toESM(require("hamt_plus"));
|
|
103
|
-
|
|
104
|
-
// src/internal/store.ts
|
|
105
|
-
var import_hamt_plus = __toESM(require("hamt_plus"));
|
|
106
|
-
|
|
107
|
-
// ../anvl/src/join/core-relation-data.ts
|
|
108
|
-
var import_string = require("fp-ts/string");
|
|
109
|
-
|
|
110
|
-
// ../anvl/src/array/venn.ts
|
|
111
|
-
var includesAll = (items) => (array) => {
|
|
112
|
-
for (const item of items) {
|
|
113
|
-
if (!array.includes(item))
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
return true;
|
|
117
|
-
};
|
|
118
|
-
var comprises = (items) => (array) => includesAll(items)(array) && includesAll(array)(items);
|
|
119
|
-
|
|
120
|
-
// ../anvl/src/array/index.ts
|
|
121
|
-
var isArray = (isType) => (input) => Array.isArray(input) && input.every((item) => isType(item));
|
|
122
|
-
var map = (f) => (a) => a.map(f);
|
|
123
|
-
var every = (f = Boolean) => (a) => a.every(f);
|
|
124
|
-
var allTrue = every((x) => x === true);
|
|
125
|
-
var addTo = (a) => (x) => a.includes(x) ? a : [...a, x];
|
|
126
|
-
var isEmptyArray = (input) => Array.isArray(input) && input.length === 0;
|
|
127
|
-
var isOneOf = (...args) => (input) => args.includes(input);
|
|
128
|
-
|
|
129
|
-
// ../anvl/src/object/refinement.ts
|
|
130
|
-
var import_function2 = require("fp-ts/function");
|
|
131
|
-
|
|
132
|
-
// ../anvl/src/object/access.ts
|
|
133
|
-
var access = (k) => Object.assign((obj) => obj[k], {
|
|
134
|
-
in: (obj) => obj[k]
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// ../anvl/src/object/entries.ts
|
|
138
|
-
var recordToEntries = (obj) => Object.entries(obj);
|
|
139
|
-
var entriesToRecord = (entries) => Object.fromEntries(entries);
|
|
140
|
-
|
|
141
|
-
// ../anvl/src/object/mapObject.ts
|
|
142
|
-
var import_function = require("fp-ts/lib/function");
|
|
143
|
-
var mapObject = (obj, fn) => (0, import_function.pipe)(
|
|
144
|
-
obj,
|
|
145
|
-
recordToEntries,
|
|
146
|
-
map(([key, val]) => [key, fn(val, key)]),
|
|
147
|
-
entriesToRecord
|
|
148
|
-
);
|
|
149
|
-
var mob = (fn) => (obj) => mapObject(obj, fn);
|
|
150
|
-
|
|
151
|
-
// ../anvl/src/function/index.ts
|
|
152
|
-
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
153
|
-
originalThing instanceof Function ? originalThing() : originalThing
|
|
154
|
-
) : nextVersionOfThing;
|
|
155
|
-
var pass = (...params) => (fn) => fn(...params);
|
|
156
|
-
|
|
157
|
-
// ../anvl/src/nullish/index.ts
|
|
158
|
-
var isUndefined = (input) => input === void 0;
|
|
159
|
-
var ifNullish = (alt) => (input) => input != null ? input : alt;
|
|
160
|
-
|
|
161
|
-
// ../anvl/src/object/refinement.ts
|
|
162
|
-
var isNonNullObject = (input) => typeof input === `object` && input !== null;
|
|
163
|
-
var isPlainObject = (input) => isNonNullObject(input) && Object.getPrototypeOf(input) === Object.prototype;
|
|
164
|
-
var isEmptyObject = (input) => isPlainObject(input) && Object.keys(input).length === 0;
|
|
165
|
-
var isRecord = (isKey, isValue) => (input) => isPlainObject(input) && Object.entries(input).every(([k, v]) => isKey(k) && isValue(v));
|
|
166
|
-
var hasProperties = (isValue, options = { allowExtraProperties: false }) => {
|
|
167
|
-
const name = `{${recordToEntries(
|
|
168
|
-
isValue
|
|
169
|
-
).map(([k, v]) => String(k) + `:` + v.name).join(`,`)}}`;
|
|
170
|
-
const _ = {
|
|
171
|
-
[name]: (input) => isPlainObject(input) && (0, import_function2.pipe)(
|
|
172
|
-
isValue,
|
|
173
|
-
Object.entries,
|
|
174
|
-
every(([key, val]) => key in input || val(void 0))
|
|
175
|
-
) && (0, import_function2.pipe)(
|
|
176
|
-
input,
|
|
177
|
-
mob(
|
|
178
|
-
(val, key) => (0, import_function2.pipe)(
|
|
179
|
-
isValue,
|
|
180
|
-
access(key),
|
|
181
|
-
ifNullish(() => options.allowExtraProperties),
|
|
182
|
-
pass(val)
|
|
183
|
-
)
|
|
184
|
-
),
|
|
185
|
-
Object.values,
|
|
186
|
-
allTrue
|
|
187
|
-
)
|
|
188
|
-
};
|
|
189
|
-
return _[name];
|
|
190
|
-
};
|
|
191
|
-
var hasExactProperties = (
|
|
192
|
-
/* alias for hasProperties without allowExtraProperties */
|
|
193
|
-
(isValue) => hasProperties(isValue, { allowExtraProperties: false })
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
// ../anvl/src/join/core-relation-data.ts
|
|
197
|
-
var RELATION_TYPES = [`1:1`, `1:n`, `n:n`];
|
|
198
|
-
var isRelationType = (x) => RELATION_TYPES.includes(x);
|
|
199
|
-
var EMPTY_RELATION_DATA = {
|
|
200
|
-
contents: {},
|
|
201
|
-
relations: {},
|
|
202
|
-
relationType: `n:n`
|
|
203
|
-
};
|
|
204
|
-
var isRelationData = (isContent) => (input) => hasExactProperties({
|
|
205
|
-
contents: isContent ? isRecord(import_string.isString, isContent) : hasExactProperties({}),
|
|
206
|
-
relations: isRecord(import_string.isString, isArray(import_string.isString)),
|
|
207
|
-
relationType: isRelationType
|
|
208
|
-
})(input);
|
|
209
|
-
|
|
210
|
-
// ../anvl/src/join/get-related-ids.ts
|
|
211
|
-
var getRelatedIds = (relationMap, id) => {
|
|
212
|
-
var _a;
|
|
213
|
-
return (_a = relationMap.relations[id]) != null ? _a : [];
|
|
214
|
-
};
|
|
215
|
-
var getRelatedId = (relationMap, id) => {
|
|
216
|
-
const relations = getRelatedIds(relationMap, id);
|
|
217
|
-
if (relations.length > 1) {
|
|
218
|
-
console.warn(
|
|
219
|
-
`entry with id ${id} was not expected to have multiple relations`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
return relations[0];
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// ../anvl/src/join/relation-contents.ts
|
|
226
|
-
var import_function6 = require("fp-ts/function");
|
|
227
|
-
|
|
228
|
-
// ../anvl/src/join/relation-record.ts
|
|
229
|
-
var getRelationEntries = (relationMap, idA) => getRelatedIds(relationMap, idA).map((idB) => [
|
|
230
|
-
idB,
|
|
231
|
-
getContent(relationMap, idA, idB)
|
|
232
|
-
]);
|
|
233
|
-
var getRelationRecord = (relationMap, id) => Object.fromEntries(getRelationEntries(relationMap, id));
|
|
234
|
-
|
|
235
|
-
// ../anvl/src/join/remove-relation.ts
|
|
236
|
-
var import_function5 = require("fp-ts/function");
|
|
237
|
-
var import_string2 = require("fp-ts/string");
|
|
238
|
-
|
|
239
|
-
// ../anvl/src/object/index.ts
|
|
240
|
-
var import_function4 = require("fp-ts/function");
|
|
241
|
-
var treeShake = (shouldDiscard = isUndefined) => (obj) => {
|
|
242
|
-
const newObj = {};
|
|
243
|
-
const entries = Object.entries(obj);
|
|
244
|
-
entries.forEach(
|
|
245
|
-
([key, val]) => !shouldDiscard(val, key) ? newObj[key] = val : null
|
|
246
|
-
);
|
|
247
|
-
return newObj;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
// ../anvl/src/string/split.ts
|
|
251
|
-
var split = (separator) => (str) => str.split(separator);
|
|
252
|
-
|
|
253
|
-
// ../anvl/src/join/remove-relation.ts
|
|
254
|
-
var removeSpecific = (current, idA, idB) => {
|
|
255
|
-
const isIdForRemoval = isOneOf(idA, idB);
|
|
256
|
-
return __spreadProps(__spreadValues({}, current), {
|
|
257
|
-
relations: (0, import_function5.pipe)(
|
|
258
|
-
current.relations,
|
|
259
|
-
recordToEntries,
|
|
260
|
-
map(([id, relations]) => [
|
|
261
|
-
id,
|
|
262
|
-
isIdForRemoval(id) ? relations.filter((relation) => !isIdForRemoval(relation)) : relations
|
|
263
|
-
]),
|
|
264
|
-
entriesToRecord,
|
|
265
|
-
treeShake(isEmptyArray)
|
|
266
|
-
),
|
|
267
|
-
contents: (0, import_function5.pipe)(
|
|
268
|
-
current.contents,
|
|
269
|
-
treeShake(
|
|
270
|
-
(_, key) => (0, import_string2.isString)(key) && (0, import_function5.pipe)(key, split(`/`), comprises([idA, idB]))
|
|
271
|
-
)
|
|
272
|
-
)
|
|
273
|
-
});
|
|
274
|
-
};
|
|
275
|
-
var removeAll = (current, idToRemove) => {
|
|
276
|
-
const next = __spreadProps(__spreadValues({}, current), {
|
|
277
|
-
relations: (0, import_function5.pipe)(
|
|
278
|
-
current.relations,
|
|
279
|
-
recordToEntries,
|
|
280
|
-
map(([id, relations]) => [
|
|
281
|
-
id,
|
|
282
|
-
relations.filter((relation) => relation !== idToRemove)
|
|
283
|
-
]),
|
|
284
|
-
entriesToRecord,
|
|
285
|
-
treeShake((val, key) => key === idToRemove || isEmptyArray(val))
|
|
286
|
-
),
|
|
287
|
-
contents: (0, import_function5.pipe)(
|
|
288
|
-
current.contents,
|
|
289
|
-
treeShake(
|
|
290
|
-
(_, key) => (0, import_string2.isString)(key) && key.split(`/`).includes(idToRemove)
|
|
291
|
-
)
|
|
292
|
-
)
|
|
293
|
-
});
|
|
294
|
-
return next;
|
|
295
|
-
};
|
|
296
|
-
var removeRelation = (current, idA, idB) => idB ? removeSpecific(current, idA, idB) : removeAll(current, idA);
|
|
297
|
-
|
|
298
|
-
// ../anvl/src/join/set-relation.ts
|
|
299
|
-
var setManyToMany = (map2, idA, idB, ...rest) => {
|
|
300
|
-
var _a, _b;
|
|
301
|
-
const next = __spreadProps(__spreadValues({}, map2), {
|
|
302
|
-
relations: __spreadProps(__spreadValues({}, map2.relations), {
|
|
303
|
-
[idA]: addTo((_a = map2.relations[idA]) != null ? _a : [])(idB),
|
|
304
|
-
[idB]: addTo((_b = map2.relations[idB]) != null ? _b : [])(idA)
|
|
305
|
-
})
|
|
306
|
-
});
|
|
307
|
-
const content = rest[0];
|
|
308
|
-
return content ? setContent(next, idA, idB, content) : next;
|
|
309
|
-
};
|
|
310
|
-
var removeEmpties = treeShake(isEmptyArray);
|
|
311
|
-
var set1ToMany = (current, leaderId, followerId, ...rest) => {
|
|
312
|
-
var _a;
|
|
313
|
-
const relations = __spreadValues({}, current.relations);
|
|
314
|
-
const prevLeaderId = getRelatedId(current, followerId);
|
|
315
|
-
const next = __spreadProps(__spreadValues({}, current), {
|
|
316
|
-
relations: removeEmpties(__spreadProps(__spreadValues(__spreadValues({}, relations), prevLeaderId && prevLeaderId !== leaderId && {
|
|
317
|
-
[prevLeaderId]: relations[prevLeaderId].filter(
|
|
318
|
-
(id) => id !== followerId
|
|
319
|
-
)
|
|
320
|
-
}), {
|
|
321
|
-
[followerId]: [leaderId],
|
|
322
|
-
[leaderId]: addTo((_a = relations[leaderId]) != null ? _a : [])(followerId)
|
|
323
|
-
}))
|
|
324
|
-
});
|
|
325
|
-
const content = rest[0];
|
|
326
|
-
return content ? setContent(next, leaderId, followerId, content) : next;
|
|
327
|
-
};
|
|
328
|
-
var set1To1 = (current, wifeId, husbandId, ...rest) => {
|
|
329
|
-
const prevWifeId = getRelatedId(current, husbandId);
|
|
330
|
-
const prevHusbandId = getRelatedId(current, wifeId);
|
|
331
|
-
const next = __spreadProps(__spreadValues({}, current), {
|
|
332
|
-
relations: removeEmpties(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, current.relations), prevWifeId && { [prevWifeId]: [] }), prevHusbandId && { [prevHusbandId]: [] }), {
|
|
333
|
-
[wifeId]: [husbandId],
|
|
334
|
-
[husbandId]: [wifeId]
|
|
335
|
-
}))
|
|
336
|
-
});
|
|
337
|
-
const content = rest[0];
|
|
338
|
-
return content ? setContent(next, wifeId, husbandId, content) : next;
|
|
339
|
-
};
|
|
340
|
-
var setRelationWithContent = (current, idA, idB, ...rest) => {
|
|
341
|
-
switch (current.relationType) {
|
|
342
|
-
case `1:1`:
|
|
343
|
-
return set1To1(current, idA, idB, ...rest);
|
|
344
|
-
case `1:n`:
|
|
345
|
-
return set1ToMany(current, idA, idB, ...rest);
|
|
346
|
-
case `n:n`:
|
|
347
|
-
return setManyToMany(current, idA, idB, ...rest);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
// ../anvl/src/join/relation-contents.ts
|
|
352
|
-
var makeContentId = (idA, idB) => [idA, idB].sort().join(`/`);
|
|
353
|
-
var getContent = (relationMap, idA, idB) => relationMap.contents[makeContentId(idA, idB)];
|
|
354
|
-
var setContent = (map2, idA, idB, content) => __spreadProps(__spreadValues({}, map2), {
|
|
355
|
-
contents: __spreadProps(__spreadValues({}, map2.contents), {
|
|
356
|
-
[makeContentId(idA, idB)]: content
|
|
357
|
-
})
|
|
358
|
-
});
|
|
359
|
-
var getRelations = (relationMap, id) => getRelationEntries(relationMap, id).map(
|
|
360
|
-
([id2, content]) => __spreadValues({
|
|
361
|
-
id: id2
|
|
362
|
-
}, content)
|
|
363
|
-
);
|
|
364
|
-
var setRelations = (current, idA, relations) => (0, import_function6.pipe)(
|
|
365
|
-
current,
|
|
366
|
-
(relationData) => {
|
|
367
|
-
const relatedIds = getRelatedIds(current, idA);
|
|
368
|
-
const removedIds = relatedIds.filter(
|
|
369
|
-
(id) => !relations.some((r) => r.id === id)
|
|
370
|
-
);
|
|
371
|
-
let step = relationData;
|
|
372
|
-
for (const idB of removedIds)
|
|
373
|
-
step = removeRelation(step, idA, idB);
|
|
374
|
-
return step;
|
|
375
|
-
},
|
|
376
|
-
(relationData) => {
|
|
377
|
-
let step = relationData;
|
|
378
|
-
for (const _a of relations) {
|
|
379
|
-
const _b = _a, { id: idB } = _b, rest = __objRest(_b, ["id"]);
|
|
380
|
-
const content = isEmptyObject(rest) ? void 0 : rest;
|
|
381
|
-
step = setRelationWithContent(step, idA, idB, content);
|
|
382
|
-
}
|
|
383
|
-
return step;
|
|
384
|
-
},
|
|
385
|
-
(relationData) => {
|
|
386
|
-
const newlyOrderedIds = relations.map((r) => r.id);
|
|
387
|
-
return __spreadProps(__spreadValues({}, relationData), {
|
|
388
|
-
relations: __spreadProps(__spreadValues({}, relationData.relations), {
|
|
389
|
-
[idA]: newlyOrderedIds
|
|
390
|
-
})
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
// ../anvl/src/refinement/index.ts
|
|
396
|
-
var canExist = (_) => true;
|
|
397
|
-
var cannotExist = (_) => false;
|
|
398
|
-
var couldBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
|
|
399
|
-
const name = `(${refinements.map((r) => r.name || `anon`).join(` | `)})`;
|
|
400
|
-
const _ = {
|
|
401
|
-
[name]: (input) => refinements.some(
|
|
402
|
-
(refinement) => {
|
|
403
|
-
var _a;
|
|
404
|
-
return logging && console.log(
|
|
405
|
-
refinements.map((r) => r.name || `anon`).join(` | `),
|
|
406
|
-
`>`,
|
|
407
|
-
(_a = refinement.name) != null ? _a : `anon`,
|
|
408
|
-
`:`,
|
|
409
|
-
refinement(input)
|
|
410
|
-
), refinement(input);
|
|
411
|
-
}
|
|
412
|
-
)
|
|
413
|
-
};
|
|
414
|
-
const checkTypes = Object.assign(_[name], {
|
|
415
|
-
or: (isTypeB) => couldBe(isTypeB, logging, [...refinements, isTypeB])
|
|
416
|
-
});
|
|
417
|
-
return checkTypes;
|
|
418
|
-
};
|
|
419
|
-
var isUnion = couldBe(cannotExist);
|
|
420
|
-
var mustBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
|
|
421
|
-
const name = `(${refinements.map((r) => r.name || `anon`).join(` & `)})`;
|
|
422
|
-
const _ = {
|
|
423
|
-
[name]: (input) => refinements.every(
|
|
424
|
-
(refinement) => (logging && console.log(
|
|
425
|
-
refinements.map((r) => r.name || `anon`).join(` & `),
|
|
426
|
-
`>`,
|
|
427
|
-
refinement.name || `anon`,
|
|
428
|
-
`:`,
|
|
429
|
-
refinement(input)
|
|
430
|
-
), refinement(input))
|
|
431
|
-
)
|
|
432
|
-
};
|
|
433
|
-
const checkTypes = Object.assign(_[name], {
|
|
434
|
-
and: (isTypeB) => mustBe(isTypeB, logging, [...refinements, isTypeB])
|
|
435
|
-
});
|
|
436
|
-
return checkTypes;
|
|
437
|
-
};
|
|
438
|
-
var isIntersection = mustBe(canExist);
|
|
439
|
-
|
|
440
|
-
// ../anvl/src/join/index.ts
|
|
441
|
-
var Join = class {
|
|
442
|
-
constructor(json) {
|
|
443
|
-
Object.assign(this, __spreadValues(__spreadValues({}, EMPTY_RELATION_DATA), json));
|
|
444
|
-
}
|
|
445
|
-
toJSON() {
|
|
446
|
-
return {
|
|
447
|
-
relationType: this.relationType,
|
|
448
|
-
relations: this.relations,
|
|
449
|
-
contents: this.contents
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
static fromJSON(json, isContent = cannotExist) {
|
|
453
|
-
const isValid = isRelationData(isContent)(json);
|
|
454
|
-
if (isValid) {
|
|
455
|
-
return new Join(json);
|
|
456
|
-
}
|
|
457
|
-
throw new Error(
|
|
458
|
-
`Saved JSON for this Join is invalid: ${JSON.stringify(json)}`
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
getRelatedId(id) {
|
|
462
|
-
return getRelatedId(this, id);
|
|
463
|
-
}
|
|
464
|
-
getRelatedIds(id) {
|
|
465
|
-
return getRelatedIds(this, id);
|
|
466
|
-
}
|
|
467
|
-
getContent(idA, idB) {
|
|
468
|
-
return getContent(this, idA, idB);
|
|
469
|
-
}
|
|
470
|
-
getRelationEntries(id) {
|
|
471
|
-
return getRelationEntries(this, id);
|
|
472
|
-
}
|
|
473
|
-
getRelationRecord(id) {
|
|
474
|
-
return getRelationRecord(this, id);
|
|
475
|
-
}
|
|
476
|
-
getRelation(id) {
|
|
477
|
-
return getRelations(this, id)[0];
|
|
478
|
-
}
|
|
479
|
-
getRelations(id) {
|
|
480
|
-
return getRelations(this, id);
|
|
481
|
-
}
|
|
482
|
-
setRelations(id, relations) {
|
|
483
|
-
return new Join(setRelations(this, id, relations));
|
|
484
|
-
}
|
|
485
|
-
set(idA, idB, ...rest) {
|
|
486
|
-
return new Join(setRelationWithContent(this, idA, idB, ...rest));
|
|
487
|
-
}
|
|
488
|
-
remove(idA, idB) {
|
|
489
|
-
return new Join(removeRelation(this, idA, idB));
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
// src/internal/store.ts
|
|
494
|
-
var createStore = (name) => ({
|
|
495
|
-
valueMap: import_hamt_plus.default.make(),
|
|
496
|
-
selectorGraph: new Join({ relationType: `n:n` }),
|
|
497
|
-
selectorAtoms: new Join({ relationType: `n:n` }),
|
|
498
|
-
atoms: import_hamt_plus.default.make(),
|
|
499
|
-
atomsAreDefault: import_hamt_plus.default.make(),
|
|
500
|
-
selectors: import_hamt_plus.default.make(),
|
|
501
|
-
readonlySelectors: import_hamt_plus.default.make(),
|
|
502
|
-
operation: {
|
|
503
|
-
open: false
|
|
504
|
-
},
|
|
505
|
-
transaction: {
|
|
506
|
-
open: false
|
|
507
|
-
},
|
|
508
|
-
config: {
|
|
509
|
-
name,
|
|
510
|
-
logger: null
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
var IMPLICIT = {
|
|
514
|
-
STORE_INTERNAL: void 0,
|
|
515
|
-
get STORE() {
|
|
516
|
-
var _a;
|
|
517
|
-
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = createStore(`DEFAULT`);
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
var configure = (config, store = IMPLICIT.STORE) => {
|
|
521
|
-
Object.assign(store.config, config);
|
|
522
|
-
};
|
|
523
|
-
var clearStore = (store = IMPLICIT.STORE) => {
|
|
524
|
-
const { config } = store;
|
|
525
|
-
Object.assign(store, createStore(config.name));
|
|
526
|
-
store.config = config;
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
// src/internal/get.ts
|
|
530
|
-
var getCachedState = (state, store = IMPLICIT.STORE) => {
|
|
531
|
-
const path = [];
|
|
532
|
-
if (`default` in state) {
|
|
533
|
-
const atomKey = state.key;
|
|
534
|
-
store.selectorAtoms = (0, import_function7.pipe)(store.selectorAtoms, (oldValue) => {
|
|
535
|
-
let newValue = oldValue;
|
|
536
|
-
for (const selectorKey of path) {
|
|
537
|
-
newValue = newValue.set(selectorKey, atomKey);
|
|
538
|
-
}
|
|
539
|
-
return newValue;
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
const value = import_hamt_plus2.default.get(state.key, store.valueMap);
|
|
543
|
-
return value;
|
|
544
|
-
};
|
|
545
|
-
var getSelectorState = (selector) => selector.get();
|
|
546
|
-
function lookup(key, store) {
|
|
547
|
-
const type = import_hamt_plus2.default.has(key, store.atoms) ? `atom` : import_hamt_plus2.default.has(key, store.selectors) ? `selector` : `readonly_selector`;
|
|
548
|
-
return { key, type };
|
|
549
|
-
}
|
|
550
|
-
function withdraw(token, store) {
|
|
551
|
-
var _a, _b;
|
|
552
|
-
return (_b = (_a = import_hamt_plus2.default.get(token.key, store.atoms)) != null ? _a : import_hamt_plus2.default.get(token.key, store.selectors)) != null ? _b : import_hamt_plus2.default.get(token.key, store.readonlySelectors);
|
|
553
|
-
}
|
|
554
|
-
function deposit(state) {
|
|
555
|
-
if (`get` in state) {
|
|
556
|
-
if (`set` in state) {
|
|
557
|
-
return { key: state.key, type: `selector` };
|
|
558
|
-
}
|
|
559
|
-
return { key: state.key, type: `readonly_selector` };
|
|
560
|
-
}
|
|
561
|
-
return { key: state.key, type: `atom` };
|
|
562
|
-
}
|
|
563
|
-
var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
564
|
-
var _a, _b, _c;
|
|
565
|
-
if (import_hamt_plus2.default.has(state.key, store.valueMap)) {
|
|
566
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`>> read "${state.key}"`);
|
|
567
|
-
return getCachedState(state, store);
|
|
568
|
-
}
|
|
569
|
-
if (`get` in state) {
|
|
570
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(`-> calc "${state.key}"`);
|
|
571
|
-
return getSelectorState(state);
|
|
572
|
-
}
|
|
573
|
-
(_c = store.config.logger) == null ? void 0 : _c.error(
|
|
574
|
-
`Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
|
|
575
|
-
);
|
|
576
|
-
return state.default;
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
// src/internal/set.ts
|
|
580
|
-
var import_hamt_plus4 = __toESM(require("hamt_plus"));
|
|
581
|
-
|
|
582
|
-
// src/internal/operation.ts
|
|
583
|
-
var import_hamt_plus3 = __toESM(require("hamt_plus"));
|
|
584
|
-
var startAction = (store) => {
|
|
585
|
-
var _a;
|
|
586
|
-
store.operation = {
|
|
587
|
-
open: true,
|
|
588
|
-
done: /* @__PURE__ */ new Set(),
|
|
589
|
-
prev: store.valueMap
|
|
590
|
-
};
|
|
591
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u2B55`, `operation start`);
|
|
592
|
-
};
|
|
593
|
-
var finishAction = (store) => {
|
|
594
|
-
var _a;
|
|
595
|
-
store.operation = { open: false };
|
|
596
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F534}`, `operation done`);
|
|
597
|
-
};
|
|
598
|
-
var isDone = (key, store = IMPLICIT.STORE) => {
|
|
599
|
-
var _a;
|
|
600
|
-
if (!store.operation.open) {
|
|
601
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
602
|
-
`isDone called outside of an action. This is probably a bug.`
|
|
603
|
-
);
|
|
604
|
-
return true;
|
|
605
|
-
}
|
|
606
|
-
return store.operation.done.has(key);
|
|
607
|
-
};
|
|
608
|
-
var markDone = (key, store = IMPLICIT.STORE) => {
|
|
609
|
-
var _a;
|
|
610
|
-
if (!store.operation.open) {
|
|
611
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
612
|
-
`markDone called outside of an action. This is probably a bug.`
|
|
613
|
-
);
|
|
614
|
-
return;
|
|
615
|
-
}
|
|
616
|
-
store.operation.done.add(key);
|
|
617
|
-
};
|
|
618
|
-
var recallState = (state, store = IMPLICIT.STORE) => {
|
|
619
|
-
var _a;
|
|
620
|
-
if (!store.operation.open) {
|
|
621
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
622
|
-
`recall called outside of an action. This is probably a bug.`
|
|
623
|
-
);
|
|
624
|
-
return import_hamt_plus3.default.get(state.key, store.valueMap);
|
|
625
|
-
}
|
|
626
|
-
return import_hamt_plus3.default.get(state.key, store.operation.prev);
|
|
627
|
-
};
|
|
628
|
-
|
|
629
|
-
// src/internal/set.ts
|
|
630
|
-
var evictDownStream = (state, store = IMPLICIT.STORE) => {
|
|
631
|
-
var _a, _b;
|
|
632
|
-
const downstream = store.selectorAtoms.getRelations(state.key);
|
|
633
|
-
const downstreamKeys = downstream.map(({ id }) => id);
|
|
634
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
635
|
-
` || ${downstreamKeys.length} downstream:`,
|
|
636
|
-
downstreamKeys
|
|
637
|
-
);
|
|
638
|
-
if (store.operation.open) {
|
|
639
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` ||`, [...store.operation.done], `already done`);
|
|
640
|
-
}
|
|
641
|
-
downstream.forEach(({ id: stateKey }) => {
|
|
642
|
-
var _a2, _b2, _c, _d;
|
|
643
|
-
if (isDone(stateKey, store)) {
|
|
644
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(` || ${stateKey} already done`);
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
const state2 = (_b2 = import_hamt_plus4.default.get(stateKey, store.selectors)) != null ? _b2 : import_hamt_plus4.default.get(stateKey, store.readonlySelectors);
|
|
648
|
-
if (!state2) {
|
|
649
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(
|
|
650
|
-
` || ${stateKey} is an atom, and can't be downstream`
|
|
651
|
-
);
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
store.valueMap = import_hamt_plus4.default.remove(stateKey, store.valueMap);
|
|
655
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(` xx evicted "${stateKey}"`);
|
|
656
|
-
markDone(stateKey, store);
|
|
657
|
-
});
|
|
658
|
-
};
|
|
659
|
-
var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
|
|
660
|
-
var _a, _b;
|
|
661
|
-
const oldValue = getState__INTERNAL(atom, store);
|
|
662
|
-
const newValue = become(next)(oldValue);
|
|
663
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`-> setting atom "${atom.key}" to`, newValue);
|
|
664
|
-
store.valueMap = import_hamt_plus4.default.set(atom.key, newValue, store.valueMap);
|
|
665
|
-
if (isAtomDefault(atom.key)) {
|
|
666
|
-
store.atomsAreDefault = import_hamt_plus4.default.set(atom.key, false, store.atomsAreDefault);
|
|
667
|
-
}
|
|
668
|
-
markDone(atom.key, store);
|
|
669
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
670
|
-
` || evicting caches downstream from "${atom.key}"`
|
|
671
|
-
);
|
|
672
|
-
evictDownStream(atom, store);
|
|
673
|
-
atom.subject.next({ newValue, oldValue });
|
|
674
|
-
};
|
|
675
|
-
var setSelectorState = (selector, next, store = IMPLICIT.STORE) => {
|
|
676
|
-
var _a, _b;
|
|
677
|
-
const oldValue = getState__INTERNAL(selector, store);
|
|
678
|
-
const newValue = become(next)(oldValue);
|
|
679
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`-> setting selector "${selector.key}" to`, newValue);
|
|
680
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` || propagating change made to "${selector.key}"`);
|
|
681
|
-
selector.set(newValue);
|
|
682
|
-
};
|
|
683
|
-
var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
|
|
684
|
-
if (`set` in state) {
|
|
685
|
-
setSelectorState(state, value, store);
|
|
686
|
-
} else {
|
|
687
|
-
setAtomState(state, value, store);
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
|
|
691
|
-
// src/internal/is-default.ts
|
|
692
|
-
var import_hamt_plus5 = __toESM(require("hamt_plus"));
|
|
693
|
-
var isAtomDefault = (key, store = IMPLICIT.STORE) => {
|
|
694
|
-
return import_hamt_plus5.default.get(key, store.atomsAreDefault);
|
|
695
|
-
};
|
|
696
|
-
var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
697
|
-
const roots = traceAllSelectorAtoms(key, store);
|
|
698
|
-
return roots.every((root) => isAtomDefault(root.key, store));
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
// src/internal/selector-internal.ts
|
|
702
|
-
var lookupSelectorSources = (key, store) => store.selectorGraph.getRelations(key).filter(({ source }) => source !== key).map(({ source }) => lookup(source, store));
|
|
703
|
-
var traceSelectorAtoms = (selectorKey, dependency, store) => {
|
|
704
|
-
const roots = [];
|
|
705
|
-
const sources = lookupSelectorSources(dependency.key, store);
|
|
706
|
-
let depth = 0;
|
|
707
|
-
while (sources.length > 0) {
|
|
708
|
-
const source = sources.shift();
|
|
709
|
-
++depth;
|
|
710
|
-
if (depth > 999) {
|
|
711
|
-
throw new Error(
|
|
712
|
-
`Maximum selector dependency depth exceeded in selector "${selectorKey}".`
|
|
713
|
-
);
|
|
714
|
-
}
|
|
715
|
-
if (source.type !== `atom`) {
|
|
716
|
-
sources.push(...lookupSelectorSources(source.key, store));
|
|
717
|
-
} else {
|
|
718
|
-
roots.push(source);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
return roots;
|
|
722
|
-
};
|
|
723
|
-
var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
724
|
-
const sources = lookupSelectorSources(selectorKey, store);
|
|
725
|
-
return sources.flatMap(
|
|
726
|
-
(source) => source.type === `atom` ? source : traceSelectorAtoms(selectorKey, source, store)
|
|
727
|
-
);
|
|
728
|
-
};
|
|
729
|
-
var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
730
|
-
var _a, _b;
|
|
731
|
-
if (dependency.type === `atom`) {
|
|
732
|
-
store.selectorAtoms = store.selectorAtoms.set(selectorKey, dependency.key);
|
|
733
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
734
|
-
` || adding root for "${selectorKey}": ${dependency.key}`
|
|
735
|
-
);
|
|
736
|
-
return;
|
|
737
|
-
}
|
|
738
|
-
const roots = traceSelectorAtoms(selectorKey, dependency, store);
|
|
739
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` || adding roots for "${selectorKey}":`, roots);
|
|
740
|
-
for (const root of roots) {
|
|
741
|
-
store.selectorAtoms = store.selectorAtoms.set(selectorKey, root.key);
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
745
|
-
get: (dependency) => {
|
|
746
|
-
var _a, _b;
|
|
747
|
-
const alreadyRegistered = store.selectorGraph.getRelations(selectorKey).some(({ source }) => source === dependency.key);
|
|
748
|
-
const dependencyState = withdraw(dependency, store);
|
|
749
|
-
const dependencyValue = getState__INTERNAL(dependencyState, store);
|
|
750
|
-
if (alreadyRegistered) {
|
|
751
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
752
|
-
` || ${selectorKey} <- ${dependency.key} =`,
|
|
753
|
-
dependencyValue
|
|
754
|
-
);
|
|
755
|
-
} else {
|
|
756
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
757
|
-
`\u{1F50C} registerSelector "${selectorKey}" <- "${dependency.key}" =`,
|
|
758
|
-
dependencyValue
|
|
759
|
-
);
|
|
760
|
-
store.selectorGraph = store.selectorGraph.set(
|
|
761
|
-
selectorKey,
|
|
762
|
-
dependency.key,
|
|
763
|
-
{
|
|
764
|
-
source: dependency.key
|
|
765
|
-
}
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
updateSelectorAtoms(selectorKey, dependency, store);
|
|
769
|
-
return dependencyValue;
|
|
770
|
-
},
|
|
771
|
-
set: (stateToken, newValue) => {
|
|
772
|
-
const state = withdraw(stateToken, store);
|
|
773
|
-
setState__INTERNAL(state, newValue, store);
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
// src/internal/subscribe-internal.ts
|
|
778
|
-
var subscribeToRootAtoms = (state, store = IMPLICIT.STORE) => {
|
|
779
|
-
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
|
|
780
|
-
const atom = withdraw(atomToken, store);
|
|
781
|
-
return atom.subject.subscribe((atomChange) => {
|
|
782
|
-
var _a, _b;
|
|
783
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
784
|
-
`\u{1F4E2} atom changed: "${atomToken.key}" (`,
|
|
785
|
-
atomChange.oldValue,
|
|
786
|
-
`->`,
|
|
787
|
-
atomChange.newValue,
|
|
788
|
-
`) re-evaluating "${state.key}"`
|
|
789
|
-
);
|
|
790
|
-
const oldValue = recallState(state, store);
|
|
791
|
-
const newValue = getState__INTERNAL(state, store);
|
|
792
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` <- ${state.key} became`, newValue);
|
|
793
|
-
state.subject.next({ newValue, oldValue });
|
|
794
|
-
});
|
|
795
|
-
});
|
|
796
|
-
return dependencySubscriptions;
|
|
797
|
-
};
|
|
798
|
-
|
|
799
|
-
// src/internal/transaction-internal.ts
|
|
800
|
-
var finishTransaction = (store) => {
|
|
801
|
-
var _a;
|
|
802
|
-
store.transaction = { open: false };
|
|
803
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F6EC}`, `transaction done`);
|
|
804
|
-
};
|
|
805
|
-
var startTransaction = (store) => {
|
|
806
|
-
var _a;
|
|
807
|
-
store.transaction = {
|
|
808
|
-
open: true,
|
|
809
|
-
prev: {
|
|
810
|
-
atoms: store.atoms,
|
|
811
|
-
readonlySelectors: store.readonlySelectors,
|
|
812
|
-
selectorGraph: store.selectorGraph,
|
|
813
|
-
selectors: store.selectors,
|
|
814
|
-
valueMap: store.valueMap
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F6EB}`, `transaction start`);
|
|
818
|
-
};
|
|
819
|
-
var abortTransaction = (store) => {
|
|
820
|
-
var _a, _b;
|
|
821
|
-
if (!store.transaction.open) {
|
|
822
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
823
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
824
|
-
);
|
|
825
|
-
return;
|
|
826
|
-
}
|
|
827
|
-
store.atoms = store.transaction.prev.atoms;
|
|
828
|
-
store.readonlySelectors = store.transaction.prev.readonlySelectors;
|
|
829
|
-
store.selectorGraph = store.transaction.prev.selectorGraph;
|
|
830
|
-
store.selectors = store.transaction.prev.selectors;
|
|
831
|
-
store.valueMap = store.transaction.prev.valueMap;
|
|
832
|
-
store.transaction = { open: false };
|
|
833
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
834
|
-
};
|
|
835
|
-
|
|
836
|
-
// src/index.ts
|
|
837
|
-
var setState = (token, value, store = IMPLICIT.STORE) => {
|
|
838
|
-
startAction(store);
|
|
839
|
-
const state = withdraw(token, store);
|
|
840
|
-
setState__INTERNAL(state, value, store);
|
|
841
|
-
finishAction(store);
|
|
842
|
-
};
|
|
843
|
-
var subscribe = (token, observe, store = IMPLICIT.STORE) => {
|
|
844
|
-
var _a;
|
|
845
|
-
const state = withdraw(token, store);
|
|
846
|
-
const subscription = state.subject.subscribe(observe);
|
|
847
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} subscribe to "${state.key}"`);
|
|
848
|
-
const dependencySubscriptions = subscribeToRootAtoms(state, store);
|
|
849
|
-
const unsubscribe = dependencySubscriptions === null ? () => {
|
|
850
|
-
var _a2;
|
|
851
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
852
|
-
subscription.unsubscribe();
|
|
853
|
-
} : () => {
|
|
854
|
-
var _a2;
|
|
855
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
856
|
-
`\u{1F648} unsubscribe from "${state.key}" and its dependencies`
|
|
857
|
-
);
|
|
858
|
-
subscription.unsubscribe();
|
|
859
|
-
for (const dependencySubscription of dependencySubscriptions) {
|
|
860
|
-
dependencySubscription.unsubscribe();
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
return unsubscribe;
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
// src/react/index.ts
|
|
867
|
-
var composeStoreHooks = ({
|
|
868
|
-
useState,
|
|
869
|
-
useEffect,
|
|
870
|
-
store = internal_exports.IMPLICIT.STORE
|
|
871
|
-
}) => {
|
|
872
|
-
function useI(token) {
|
|
873
|
-
const updateState = (next) => setState(token, next, store);
|
|
874
|
-
return updateState;
|
|
875
|
-
}
|
|
876
|
-
function useO(token) {
|
|
877
|
-
const state = withdraw(token, store);
|
|
878
|
-
const initialValue = internal_exports.getState__INTERNAL(state, store);
|
|
879
|
-
const [current, dispatch] = useState(initialValue);
|
|
880
|
-
useEffect(() => {
|
|
881
|
-
const unsubscribe = subscribe(
|
|
882
|
-
token,
|
|
883
|
-
({ newValue, oldValue }) => {
|
|
884
|
-
if (oldValue !== newValue) {
|
|
885
|
-
dispatch(newValue);
|
|
886
|
-
}
|
|
887
|
-
},
|
|
888
|
-
store
|
|
889
|
-
);
|
|
890
|
-
return unsubscribe;
|
|
891
|
-
}, [current, dispatch]);
|
|
892
|
-
return current;
|
|
893
|
-
}
|
|
894
|
-
function useIO(token) {
|
|
895
|
-
return [useO(token), useI(token)];
|
|
896
|
-
}
|
|
897
|
-
function useStore(token) {
|
|
898
|
-
if (token.type === `readonly_selector`) {
|
|
899
|
-
return useO(token);
|
|
900
|
-
}
|
|
901
|
-
return useIO(token);
|
|
902
|
-
}
|
|
903
|
-
return { useI, useO, useIO, useStore };
|
|
904
|
-
};
|
|
905
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
906
|
-
0 && (module.exports = {
|
|
907
|
-
composeStoreHooks
|
|
908
|
-
});
|
|
909
|
-
//# sourceMappingURL=index.js.map
|