bansa 0.0.25 → 0.0.27
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 +112 -85
- package/dist/atom.d.mts +12 -9
- package/dist/atom.d.mts.map +1 -1
- package/dist/atom.mjs +141 -85
- package/dist/atom.mjs.map +1 -1
- package/dist/browser/index.d.ts +12 -9
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/react.d.mts +25 -5
- package/dist/react.d.mts.map +1 -1
- package/dist/react.mjs +44 -18
- package/dist/react.mjs.map +1 -1
- package/dist/utils.mjs +2 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +7 -5
- package/tsconfig.json +2 -2
- package/.oxfmtrc.jsonc +0 -3
- package/README.ko.md +0 -490
- package/oxlint.config.ts +0 -17
- package/tsconfig.app.json +0 -39
- package/tsconfig.lib.json +0 -35
package/dist/atom.mjs
CHANGED
|
@@ -3,19 +3,21 @@ var CommonAtomInternal = class {
|
|
|
3
3
|
_nextValue;
|
|
4
4
|
_nextError;
|
|
5
5
|
_children;
|
|
6
|
+
_wchildren;
|
|
6
7
|
_watchers;
|
|
7
8
|
_subscribers;
|
|
9
|
+
_valueChanged = true;
|
|
8
10
|
get() {
|
|
9
|
-
if (!this.
|
|
11
|
+
if (!this.state.active) {
|
|
10
12
|
execute(this);
|
|
11
13
|
disableAtom(this);
|
|
12
14
|
}
|
|
13
|
-
if (this.state.error) throw this.state.error;
|
|
14
15
|
if (this.state.promise) throw this.state.promise;
|
|
16
|
+
if (this.state.error) throw this.state.error;
|
|
15
17
|
return this.state.value;
|
|
16
18
|
}
|
|
17
19
|
watch(watcher) {
|
|
18
|
-
if (!this.
|
|
20
|
+
if (!this.state.active) requestActivate(this);
|
|
19
21
|
(this._watchers ||= /* @__PURE__ */ new Set()).add(watcher);
|
|
20
22
|
return () => {
|
|
21
23
|
this._watchers.delete(watcher);
|
|
@@ -29,7 +31,7 @@ var CommonAtomInternal = class {
|
|
|
29
31
|
return (atomSubscriber._ctrl ||= createThenableSignal()).signal;
|
|
30
32
|
} }
|
|
31
33
|
};
|
|
32
|
-
if (!this.
|
|
34
|
+
if (!this.state.active) requestActivate(this);
|
|
33
35
|
else if (!this.state.error && !this.state.promise) try {
|
|
34
36
|
subscriber(this.state.value, atomSubscriber._options);
|
|
35
37
|
} catch (e) {
|
|
@@ -54,10 +56,10 @@ var PrimitiveAtomInternal = class extends CommonAtomInternal {
|
|
|
54
56
|
_marked = false;
|
|
55
57
|
constructor(init, options) {
|
|
56
58
|
super();
|
|
57
|
-
this._init = init;
|
|
59
|
+
this._nextValue = this._init = init;
|
|
58
60
|
this._equals = options?.equals;
|
|
59
|
-
this._nextValue = init;
|
|
60
61
|
this.state = {
|
|
62
|
+
active: true,
|
|
61
63
|
promise: void 0,
|
|
62
64
|
error: void 0,
|
|
63
65
|
value: init
|
|
@@ -65,24 +67,27 @@ var PrimitiveAtomInternal = class extends CommonAtomInternal {
|
|
|
65
67
|
}
|
|
66
68
|
set(value) {
|
|
67
69
|
const nextValue = value instanceof Function ? value(this._nextValue) : value;
|
|
68
|
-
if (!
|
|
70
|
+
if (!Object.is(nextValue, this._nextValue)) {
|
|
69
71
|
this._nextValue = nextValue;
|
|
70
72
|
requestPropagate(this);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
};
|
|
74
76
|
PrimitiveAtomInternal.prototype._source = true;
|
|
75
|
-
PrimitiveAtomInternal.prototype.
|
|
77
|
+
PrimitiveAtomInternal.prototype._hasValue = true;
|
|
76
78
|
PrimitiveAtomInternal.prototype._needExecute = false;
|
|
77
79
|
var DerivedAtomInternal = class extends CommonAtomInternal {
|
|
78
|
-
|
|
80
|
+
_hasValue = false;
|
|
79
81
|
_needExecute = false;
|
|
80
82
|
_needPropagate = false;
|
|
81
83
|
_marked = false;
|
|
82
84
|
_counter = 0;
|
|
85
|
+
_resolve;
|
|
86
|
+
_reject;
|
|
83
87
|
_ctrl;
|
|
84
88
|
_dependencies;
|
|
85
|
-
|
|
89
|
+
_wdependencies;
|
|
90
|
+
_allDependencies;
|
|
86
91
|
constructor(init, options) {
|
|
87
92
|
super();
|
|
88
93
|
this._init = init;
|
|
@@ -93,15 +98,14 @@ var DerivedAtomInternal = class extends CommonAtomInternal {
|
|
|
93
98
|
return (self._ctrl ||= createThenableSignal()).signal;
|
|
94
99
|
} };
|
|
95
100
|
this.state = {
|
|
96
|
-
|
|
101
|
+
active: false,
|
|
102
|
+
promise: void 0,
|
|
97
103
|
error: void 0,
|
|
98
104
|
value: void 0
|
|
99
105
|
};
|
|
100
106
|
}
|
|
101
107
|
};
|
|
102
108
|
DerivedAtomInternal.prototype._source = false;
|
|
103
|
-
const inactive = Promise.reject();
|
|
104
|
-
inactive.catch(() => {});
|
|
105
109
|
const $ = (init, options) => {
|
|
106
110
|
if (init instanceof Function) return new DerivedAtomInternal(init, options);
|
|
107
111
|
return new PrimitiveAtomInternal(init, options);
|
|
@@ -118,7 +122,7 @@ const createScope = (parentScope, atomValuePairs) => {
|
|
|
118
122
|
const parentAtom = parentScope?.(baseAtom, true);
|
|
119
123
|
if (strict) return parentAtom;
|
|
120
124
|
const realBaseAtom = parentAtom || baseAtom;
|
|
121
|
-
atomMap.set(baseAtom, scopedAtom = realBaseAtom._init instanceof Function ? $((get, options) => realBaseAtom._init((atom
|
|
125
|
+
atomMap.set(baseAtom, scopedAtom = realBaseAtom._init instanceof Function ? $((get, options) => realBaseAtom._init((atom) => get(scope(atom)), options), {
|
|
122
126
|
equals: realBaseAtom._equals,
|
|
123
127
|
persist: realBaseAtom._persist
|
|
124
128
|
}) : parentAtom || $(realBaseAtom._init));
|
|
@@ -153,9 +157,31 @@ const updateAtoms = () => {
|
|
|
153
157
|
const updatedAtoms = updateQueue;
|
|
154
158
|
updateQueue = [];
|
|
155
159
|
for (const atom of updatedAtoms) {
|
|
156
|
-
atom.state.
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
if (atom.state.active) {
|
|
161
|
+
const prevSuccess = atom._hasValue && !atom.state.promise && !atom.state.error;
|
|
162
|
+
if (atom.state.error = atom._nextError) {
|
|
163
|
+
atom._nextValue = atom.state.value;
|
|
164
|
+
if (atom._reject) {
|
|
165
|
+
atom._reject(atom._nextError);
|
|
166
|
+
atom._resolve = atom._reject = atom.state.promise = void 0;
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
if (!atom._hasValue || !Object.is(atom._nextValue, atom.state.value) && !atom._equals?.(atom._nextValue, atom.state.value)) {
|
|
170
|
+
atom.state.value = atom._nextValue;
|
|
171
|
+
atom._valueChanged = atom._hasValue = true;
|
|
172
|
+
} else {
|
|
173
|
+
atom._nextValue = atom.state.value;
|
|
174
|
+
if (prevSuccess) {
|
|
175
|
+
atom._needPropagate = false;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (atom._resolve) {
|
|
180
|
+
atom._resolve(atom._nextValue);
|
|
181
|
+
atom._resolve = atom._reject = atom.state.promise = void 0;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
159
185
|
mark(atom);
|
|
160
186
|
}
|
|
161
187
|
}
|
|
@@ -178,8 +204,26 @@ const propagate = (atom) => {
|
|
|
178
204
|
} catch (e) {
|
|
179
205
|
logError(e);
|
|
180
206
|
}
|
|
181
|
-
if (
|
|
182
|
-
|
|
207
|
+
if (atom._wchildren) for (const wchild of atom._wchildren) wchild._needExecute = true;
|
|
208
|
+
if (atom.state.promise) {
|
|
209
|
+
if (atom._children) for (const child of atom._children) {
|
|
210
|
+
child.state.promise ||= new Promise((resolve, reject) => {
|
|
211
|
+
child._resolve = resolve;
|
|
212
|
+
child._reject = reject;
|
|
213
|
+
});
|
|
214
|
+
child._needPropagate = true;
|
|
215
|
+
}
|
|
216
|
+
} else if (atom.state.error) {
|
|
217
|
+
if (atom._children) for (const child of atom._children) {
|
|
218
|
+
child.state.error = child._nextError = atom.state.error;
|
|
219
|
+
if (child._reject) {
|
|
220
|
+
child._reject(child._nextError);
|
|
221
|
+
child._resolve = child._reject = child.state.promise = void 0;
|
|
222
|
+
}
|
|
223
|
+
child._needPropagate = true;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
if (atom._valueChanged && atom._subscribers) for (const subscriber of atom._subscribers) {
|
|
183
227
|
if (subscriber._ctrl) {
|
|
184
228
|
subscriber._ctrl.abort();
|
|
185
229
|
subscriber._ctrl = void 0;
|
|
@@ -192,11 +236,13 @@ const propagate = (atom) => {
|
|
|
192
236
|
}
|
|
193
237
|
if (atom._children) for (const child of atom._children) child._needExecute = true;
|
|
194
238
|
}
|
|
239
|
+
atom._valueChanged = false;
|
|
195
240
|
};
|
|
196
241
|
const mark = (atom) => {
|
|
197
242
|
if (!atom._marked) {
|
|
198
243
|
atom._marked = true;
|
|
199
244
|
if (atom._children) for (const child of atom._children) mark(child);
|
|
245
|
+
if (atom._wchildren) for (const child of atom._wchildren) mark(child);
|
|
200
246
|
stack.push(atom);
|
|
201
247
|
}
|
|
202
248
|
};
|
|
@@ -207,81 +253,96 @@ var Wrapped = class {
|
|
|
207
253
|
}
|
|
208
254
|
};
|
|
209
255
|
const expired = Symbol();
|
|
256
|
+
const loading = Symbol();
|
|
210
257
|
const execute = (atom) => {
|
|
211
258
|
const counter = ++atom._counter;
|
|
212
|
-
const
|
|
213
|
-
atom.
|
|
259
|
+
const prevSuccess = atom._hasValue && !atom.state.promise && !atom.state.error;
|
|
260
|
+
atom.state.active = true;
|
|
214
261
|
atom._needExecute = false;
|
|
215
|
-
atom.
|
|
262
|
+
if (atom._dependencies) {
|
|
263
|
+
for (const dep of atom._dependencies) dep._children.delete(atom);
|
|
264
|
+
atom._dependencies.clear();
|
|
265
|
+
}
|
|
266
|
+
if (atom._wdependencies) {
|
|
267
|
+
for (const dep of atom._wdependencies) dep._wchildren.delete(atom);
|
|
268
|
+
atom._wdependencies.clear();
|
|
269
|
+
}
|
|
216
270
|
if (atom._ctrl) {
|
|
217
271
|
atom._ctrl.abort();
|
|
218
272
|
atom._ctrl = void 0;
|
|
219
273
|
}
|
|
220
274
|
try {
|
|
221
|
-
const value = atom._init((anotherAtom,
|
|
275
|
+
const value = atom._init((anotherAtom, watch = false) => {
|
|
222
276
|
if (counter !== atom._counter) throw expired;
|
|
223
277
|
if (atom !== anotherAtom) {
|
|
224
|
-
if (!anotherAtom.
|
|
225
|
-
|
|
226
|
-
|
|
278
|
+
if (!anotherAtom.state.active) execute(anotherAtom);
|
|
279
|
+
(atom._allDependencies ||= /* @__PURE__ */ new Set()).add(anotherAtom);
|
|
280
|
+
if (watch) {
|
|
281
|
+
atom._dependencies?.delete(anotherAtom);
|
|
282
|
+
(atom._wdependencies ||= /* @__PURE__ */ new Set()).add(anotherAtom);
|
|
283
|
+
(anotherAtom._wchildren ||= /* @__PURE__ */ new Set()).add(atom);
|
|
284
|
+
} else if (!atom._wdependencies?.has(anotherAtom)) {
|
|
285
|
+
(atom._dependencies ||= /* @__PURE__ */ new Set()).add(anotherAtom);
|
|
286
|
+
(anotherAtom._children ||= /* @__PURE__ */ new Set()).add(atom);
|
|
227
287
|
}
|
|
228
|
-
(atom._nextDependencies ||= /* @__PURE__ */ new Set()).add(anotherAtom);
|
|
229
|
-
(anotherAtom._children ||= /* @__PURE__ */ new Set()).add(atom);
|
|
230
288
|
}
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
if (
|
|
234
|
-
|
|
289
|
+
const { state } = anotherAtom;
|
|
290
|
+
if (watch) return state;
|
|
291
|
+
if (state.promise) throw loading;
|
|
292
|
+
if (state.error) throw new Wrapped(state.error);
|
|
293
|
+
return state.value;
|
|
235
294
|
}, atom._options);
|
|
236
295
|
if (isPromiseLike(value)) {
|
|
237
|
-
atom.state.promise
|
|
296
|
+
atom.state.promise ||= new Promise((resolve, reject) => {
|
|
297
|
+
atom._resolve = resolve;
|
|
298
|
+
atom._reject = reject;
|
|
299
|
+
});
|
|
238
300
|
value.then((value) => {
|
|
239
301
|
if (counter === atom._counter) {
|
|
240
|
-
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
atom._nextValue = value;
|
|
244
|
-
atom._nextError = void 0;
|
|
245
|
-
}
|
|
302
|
+
++atom._counter;
|
|
303
|
+
if (!atom._hasValue || !Object.is(value, atom._nextValue)) atom._nextValue = value;
|
|
304
|
+
atom._nextError = void 0;
|
|
246
305
|
requestPropagate(atom);
|
|
247
306
|
}
|
|
248
307
|
}, (e) => {
|
|
249
|
-
if (counter === atom._counter) {
|
|
250
|
-
|
|
251
|
-
if (e
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
308
|
+
if (counter === atom._counter && e !== expired) {
|
|
309
|
+
++atom._counter;
|
|
310
|
+
if (e !== loading) {
|
|
311
|
+
if (e instanceof Wrapped) e = e.e;
|
|
312
|
+
else logError(e);
|
|
313
|
+
atom._nextError = e;
|
|
314
|
+
requestPropagate(atom);
|
|
315
|
+
}
|
|
255
316
|
}
|
|
256
317
|
});
|
|
257
318
|
} else {
|
|
258
|
-
|
|
259
|
-
atom.
|
|
260
|
-
|
|
261
|
-
|
|
319
|
+
++atom._counter;
|
|
320
|
+
if (!atom._hasValue || !Object.is(value, atom._nextValue) && !atom._equals?.(value, atom._nextValue)) {
|
|
321
|
+
atom.state.value = atom._nextValue = value;
|
|
322
|
+
atom._valueChanged = atom._hasValue = true;
|
|
323
|
+
} else if (prevSuccess) atom._needPropagate = false;
|
|
324
|
+
atom.state.error = atom._nextError = void 0;
|
|
325
|
+
if (atom._resolve) {
|
|
326
|
+
atom._resolve(atom._nextValue);
|
|
327
|
+
atom._resolve = atom._reject = atom.state.promise = void 0;
|
|
328
|
+
}
|
|
262
329
|
}
|
|
263
330
|
} catch (e) {
|
|
264
|
-
|
|
265
|
-
if (e ===
|
|
331
|
+
++atom._counter;
|
|
332
|
+
if (e === loading) atom.state.promise ||= new Promise((resolve, reject) => {
|
|
333
|
+
atom._resolve = resolve;
|
|
334
|
+
atom._reject = reject;
|
|
335
|
+
});
|
|
266
336
|
else {
|
|
267
337
|
if (e instanceof Wrapped) e = e.e;
|
|
268
338
|
else logError(e);
|
|
269
|
-
atom.state.error = e;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
++atom._counter;
|
|
275
|
-
const oldDependencies = atom._dependencies;
|
|
276
|
-
atom._dependencies = atom._nextDependencies;
|
|
277
|
-
if (oldDependencies) {
|
|
278
|
-
for (const dep of oldDependencies) if (!atom._dependencies?.has(dep)) {
|
|
279
|
-
dep._children.delete(atom);
|
|
280
|
-
disableAtom(dep);
|
|
339
|
+
atom.state.error = atom._nextError = e;
|
|
340
|
+
if (atom._reject) {
|
|
341
|
+
atom._reject(e);
|
|
342
|
+
atom._resolve = atom._reject = atom.state.promise = void 0;
|
|
343
|
+
}
|
|
281
344
|
}
|
|
282
|
-
oldDependencies.clear();
|
|
283
345
|
}
|
|
284
|
-
atom._nextDependencies = oldDependencies;
|
|
285
346
|
};
|
|
286
347
|
let runningGc = false;
|
|
287
348
|
let gcCandidates = /* @__PURE__ */ new Set();
|
|
@@ -296,32 +357,27 @@ const disableAtom = (atom) => {
|
|
|
296
357
|
};
|
|
297
358
|
const gc = () => {
|
|
298
359
|
for (const atom of gcCandidates) if (!atom._source && !atom._persist && !atom._children?.size && !atom._watchers?.size && !atom._subscribers?.size) {
|
|
299
|
-
atom.
|
|
300
|
-
atom.
|
|
301
|
-
atom.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
dep._children.delete(atom);
|
|
309
|
-
disableAtom(dep);
|
|
360
|
+
atom._ctrl?.abort();
|
|
361
|
+
++atom._counter;
|
|
362
|
+
atom._nextValue = atom._nextError = atom.state.error = atom.state.value = atom.state.promise = atom._resolve = atom._reject = atom._ctrl = void 0;
|
|
363
|
+
atom._needPropagate = atom._needExecute = atom._hasValue = atom.state.active = false;
|
|
364
|
+
atom._valueChanged = atom._source;
|
|
365
|
+
if (atom._allDependencies) {
|
|
366
|
+
if (atom._dependencies) {
|
|
367
|
+
for (const dep of atom._dependencies) dep._children.delete(atom);
|
|
368
|
+
atom._dependencies.clear();
|
|
310
369
|
}
|
|
311
|
-
atom.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
dep._children.delete(atom);
|
|
315
|
-
disableAtom(dep);
|
|
316
|
-
}
|
|
317
|
-
atom._nextDependencies.clear();
|
|
370
|
+
if (atom._wdependencies) {
|
|
371
|
+
for (const dep of atom._wdependencies) dep._wchildren.delete(atom);
|
|
372
|
+
atom._wdependencies.clear();
|
|
318
373
|
}
|
|
374
|
+
for (const dep of atom._allDependencies) disableAtom(dep);
|
|
375
|
+
atom._allDependencies.clear();
|
|
319
376
|
}
|
|
320
377
|
}
|
|
321
378
|
gcCandidates.clear();
|
|
322
379
|
runningGc = false;
|
|
323
380
|
};
|
|
324
|
-
const equals = (value, prevValue, equalsFn) => Object.is(value, prevValue) || equalsFn !== void 0 && prevValue !== void 0 && equalsFn(value, prevValue);
|
|
325
381
|
const isPromiseLike = (x) => typeof x?.then === "function";
|
|
326
382
|
const createThenableSignal = () => {
|
|
327
383
|
const ctrl = new AbortController();
|
|
@@ -344,6 +400,6 @@ const logError = (e) => {
|
|
|
344
400
|
});
|
|
345
401
|
};
|
|
346
402
|
//#endregion
|
|
347
|
-
export { $, createScope,
|
|
403
|
+
export { $, createScope, isAtom, isPrimitiveAtom };
|
|
348
404
|
|
|
349
405
|
//# sourceMappingURL=atom.mjs.map
|
package/dist/atom.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom.mjs","names":[],"sources":["../src/atom.ts"],"sourcesContent":["export type Atom<Value> = PrimitiveAtom<Value> | DerivedAtom<Value>;\nexport type CommonAtom<Value> = {\n readonly get: () => Value;\n readonly watch: (watcher: AtomWatcher) => () => void;\n readonly subscribe: (subscriber: AtomSubscribe<Value>) => () => void;\n readonly state: AtomState<Value>;\n};\nexport type PrimitiveAtom<Value> = CommonAtom<Value> & {\n readonly set: (value: AtomUpdater<Value>) => void;\n readonly state: AtomSuccessState<Value>;\n};\nexport type DerivedAtom<Value> = CommonAtom<Value>;\n\nexport type AtomWatcher = () => void;\nexport type AtomSubscribe<Value> = (value: Value, options: AtomSubscriberOptions) => void;\nexport type AtomInit<Value> = Value | AtomGetter<Value>;\nexport type AtomUpdater<Value> = Value | AtomReducer<Value>;\n// TODO: readonly\nexport type AtomInactiveState<Value> = {\n promise: typeof inactive;\n error: any;\n value?: Value;\n};\nexport type AtomPromiseState<Value> = {\n promise: PromiseLike<Value>;\n error: any;\n value?: Value;\n};\nexport type AtomSuccessState<Value> = {\n promise: undefined;\n error: undefined;\n value: Value;\n};\nexport type AtomErrorState<Value> = {\n promise: undefined;\n error: any;\n value?: Value;\n};\nexport type AtomState<Value> =\n | AtomInactiveState<Value>\n | AtomPromiseState<Value>\n | AtomSuccessState<Value>\n | AtomErrorState<Value>;\n\nexport type AtomSubscriberOptions = { readonly signal: ThenableSignal };\nexport type AtomGetter<Value> = (\n get: GetAtom,\n options: AtomGetOptions,\n) => Value | PromiseLike<Value>;\nexport type AtomReducer<Value> = (value: Value) => Value;\n\nexport type AtomGetOptions = { readonly signal: ThenableSignal };\nexport type ThenableSignal = AbortSignal & { then: (f: () => void) => void };\ntype ThenableSignalController = {\n abort: () => void;\n signal: ThenableSignal;\n};\n\nexport type GetAtom = {\n <Value>(anotherAtom: Atom<Value>, unwrap?: true): Value;\n <Value>(anotherAtom: Atom<Value>, unwrap: false): AtomState<Value>;\n};\n\ntype CreateAtom = {\n <Value>(init: AtomGetter<Value>, options?: AtomOptions<Value>): DerivedAtom<Value>;\n <Value>(init: Value, options?: AtomOptions<Value>): PrimitiveAtom<Value>;\n <Value>(init: Value | AtomGetter<Value>, options?: AtomOptions<Value>): Atom<Value>;\n};\nexport type AtomOptions<Value> = {\n equals?: AtomEquals<Value>;\n persist?: boolean;\n eager?: boolean;\n};\n\nexport type AtomEquals<Value> = (value: Value, prevValue: Value) => boolean;\nexport type AtomScope = {\n <Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;\n <Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;\n <Value>(baseAtom: Atom<Value>): Atom<Value>;\n <Value>(baseAtom: PrimitiveAtom<Value>, strict: true): PrimitiveAtom<Value> | undefined;\n <Value>(baseAtom: DerivedAtom<Value>, strict: true): DerivedAtom<Value> | undefined;\n <Value>(baseAtom: Atom<Value>, strict: true): Atom<Value> | undefined;\n};\n\nexport type SetLike<Key> = Key[] | Set<Key> | (Key extends object ? WeakSet<Key> : never);\nexport type MapLike<Key, Value> =\n | Map<Key, Value>\n | (Key extends object ? WeakMap<Key, Value> : never)\n | (Key extends string | number | symbol ? Record<Key, Value> : never);\n\ntype GetAtomInternal = {\n <Value>(anotherAtom: AtomInternal<Value>, unwrap?: true): Value;\n <Value>(anotherAtom: AtomInternal<Value>, unwrap: false): AtomState<Value>;\n};\ntype AtomGetterInternal<Value> = (\n get: GetAtomInternal,\n options: AtomGetOptions,\n) => Value | PromiseLike<Value>;\ntype AtomSubscribeInternal<Value> = {\n _subscriber: AtomSubscribe<Value>;\n _options: AtomSubscriberOptions;\n _ctrl?: ThenableSignalController;\n};\n\ntype AtomInternal<Value> = PrimitiveAtomInternal<Value> | DerivedAtomInternal<Value>;\n\nabstract class CommonAtomInternal<Value> {\n _nextValue: Value | undefined;\n _nextError: any | undefined;\n _children: Set<DerivedAtomInternal<any>> | undefined;\n _watchers: Set<AtomWatcher> | undefined;\n _subscribers: Set<AtomSubscribeInternal<Value>> | undefined;\n\n abstract readonly _source: boolean;\n abstract _active: boolean;\n abstract _needExecute: boolean;\n abstract _needPropagate: boolean;\n abstract _marked: boolean;\n\n abstract readonly _init: Value | AtomGetterInternal<Value>;\n abstract readonly _equals: AtomEquals<Value> | undefined;\n\n abstract readonly state: AtomState<Value>;\n\n get(): Value {\n if (!this._active) {\n execute(this as unknown as DerivedAtomInternal<Value>);\n disableAtom(this as unknown as AtomInternal<Value>);\n }\n if (this.state.error) throw this.state.error;\n if (this.state.promise) throw this.state.promise;\n return this.state.value!;\n }\n\n watch(watcher: AtomWatcher): () => void {\n if (!this._active) {\n requestActivate(this as unknown as DerivedAtomInternal<Value>);\n }\n (this._watchers ||= new Set()).add(watcher);\n return () => {\n this._watchers!.delete(watcher);\n if (!this._watchers!.size) {\n disableAtom(this as unknown as AtomInternal<Value>);\n }\n };\n }\n\n subscribe(subscriber: AtomSubscribe<Value>): () => void {\n const atomSubscriber: AtomSubscribeInternal<Value> = {\n _subscriber: subscriber,\n _options: {\n get signal() {\n return (atomSubscriber._ctrl ||= createThenableSignal()).signal;\n },\n },\n };\n if (!this._active) {\n requestActivate(this as unknown as DerivedAtomInternal<Value>);\n } else if (!this.state.error && !this.state.promise) {\n try {\n subscriber(this.state.value!, atomSubscriber._options);\n } catch (e) {\n logError(e);\n }\n }\n (this._subscribers ||= new Set()).add(atomSubscriber);\n return () => {\n this._subscribers!.delete(atomSubscriber);\n if (atomSubscriber._ctrl) {\n atomSubscriber._ctrl.abort();\n atomSubscriber._ctrl = undefined;\n }\n if (!this._subscribers!.size) {\n disableAtom(this as unknown as AtomInternal<Value>);\n }\n };\n }\n\n [Symbol.toPrimitive](): Value | undefined {\n return this.state.value;\n }\n}\n\nclass PrimitiveAtomInternal<Value> extends CommonAtomInternal<Value> {\n declare readonly _source: true;\n declare readonly _active: true;\n declare readonly _needExecute: false;\n _needPropagate: boolean = false;\n _marked: boolean = false;\n\n declare readonly _init: Value;\n declare readonly _equals: AtomEquals<Value> | undefined;\n\n declare state: AtomSuccessState<Value>;\n\n constructor(init: Value, options?: AtomOptions<Value>) {\n super();\n this._init = init;\n this._equals = options?.equals;\n this._nextValue = init;\n this.state = {\n promise: undefined,\n error: undefined,\n value: init,\n };\n }\n\n set(this: PrimitiveAtomInternal<Value>, value: AtomUpdater<Value>) {\n const nextValue = value instanceof Function ? value(this._nextValue!) : value;\n if (!equals(nextValue, this.state.value, this._equals)) {\n this._nextValue = nextValue;\n requestPropagate(this);\n }\n }\n}\n// @ts-expect-error\nPrimitiveAtomInternal.prototype._source = true;\n// @ts-expect-error\nPrimitiveAtomInternal.prototype._active = true;\n// @ts-expect-error\nPrimitiveAtomInternal.prototype._needExecute = false;\n\nclass DerivedAtomInternal<Value> extends CommonAtomInternal<Value> {\n declare readonly _source: false;\n\n _active = false;\n _needExecute = false;\n _needPropagate = false;\n _marked = false;\n\n _counter = 0;\n _ctrl: ThenableSignalController | undefined;\n _dependencies: Set<AtomInternal<any>> | undefined;\n _nextDependencies: Set<AtomInternal<any>> | undefined;\n\n declare readonly _init: AtomGetterInternal<Value>;\n declare readonly _equals: AtomEquals<Value> | undefined;\n declare readonly _persist: boolean;\n declare readonly _options: AtomGetOptions;\n\n declare state: AtomState<Value>;\n\n constructor(init: AtomGetter<Value>, options?: AtomOptions<Value>) {\n super();\n this._init = init as AtomGetterInternal<Value>;\n this._equals = options?.equals;\n this._persist = !!options?.persist;\n\n const self = this;\n this._options = {\n get signal() {\n return (self._ctrl ||= createThenableSignal()).signal;\n },\n };\n\n this.state = {\n promise: inactive,\n error: undefined,\n value: undefined,\n };\n }\n}\n// @ts-expect-error\nDerivedAtomInternal.prototype._source = false;\n\nexport const inactive = Promise.reject();\ninactive.catch(() => {});\n\nexport const $: CreateAtom = <Value>(\n init: Value | AtomGetter<Value>,\n options?: AtomOptions<Value>,\n) => {\n if (init instanceof Function) return new DerivedAtomInternal(init, options);\n return new PrimitiveAtomInternal(init, options) as any;\n};\n\nexport const isAtom = (x: unknown): x is Atom<unknown> => x instanceof CommonAtomInternal;\n\nexport const isPrimitiveAtom = (x: unknown): x is PrimitiveAtom<unknown> =>\n x instanceof PrimitiveAtomInternal;\n\nexport type AtomValuePair<Value> =\n | [Atom<Value>, Value | PrimitiveAtom<Value>]\n | [DerivedAtom<Value>, Value | Atom<Value>];\nexport const createScope = <T extends AtomValuePair<unknown>[]>(\n parentScope?: AtomScope | null,\n atomValuePairs?: T,\n): AtomScope => {\n const scopeMap = new WeakMap<Atom<any>, Atom<any>>();\n const atomMap = parentScope ? new WeakMap<Atom<any>, Atom<any>>() : scopeMap;\n const scope = (<T extends Atom<unknown>>(baseAtom: T, strict = false) => {\n let scopedAtom = scopeMap.get(baseAtom);\n if (!strict) scopedAtom ||= atomMap.get(baseAtom);\n // TODO: 현재 스코프마다 사용되는 모든 아톰을 저장해서 메모리 사용이 비효율적인데 해결할 수 있을까?\n // 의존성이 동적이라 많이 어렵다\n if (!scopedAtom) {\n const parentAtom = parentScope?.(baseAtom, true);\n if (strict) return parentAtom;\n const realBaseAtom = parentAtom || baseAtom;\n atomMap.set(\n baseAtom,\n (scopedAtom = (\n (realBaseAtom as AtomInternal<never>)._init instanceof Function\n ? $(\n (get, options) =>\n (realBaseAtom as AtomInternal<never>)._init(\n (atom, unwrap) => get(scope(atom), unwrap as any),\n options,\n ),\n {\n equals: (realBaseAtom as AtomInternal<never>)._equals,\n persist: (realBaseAtom as DerivedAtomInternal<never>)._persist,\n },\n )\n : // baseAtom을 전달하지 않고 새로 생성하는 이유는 SSR 등에서 사용자 간 상태 공유를 막기 위함\n parentAtom || $((realBaseAtom as AtomInternal<any>)._init)\n ) as T),\n );\n }\n return scopedAtom;\n }) as AtomScope;\n if (atomValuePairs) {\n for (const [atom, value] of atomValuePairs) {\n scopeMap.set(atom, isAtom(value) ? (parentScope || scope)(value) : $(value));\n }\n }\n return scope;\n};\n\nlet pendingUpdateAtoms = false;\nlet updateQueue: AtomInternal<any>[] = [];\nlet stack: AtomInternal<any>[] = [];\nconst requestActivate = <Value>(atom: DerivedAtomInternal<Value>) => {\n if (!atom._needExecute) {\n atom._needExecute = true;\n requestPropagate(atom);\n }\n};\nconst requestPropagate = <Value>(atom: AtomInternal<Value>) => {\n if (!atom._needPropagate) {\n atom._needPropagate = true;\n updateQueue.push(atom);\n if (!pendingUpdateAtoms) {\n pendingUpdateAtoms = true;\n queueMicrotask(updateAtoms);\n }\n }\n};\nconst updateAtoms = () => {\n pendingUpdateAtoms = false;\n {\n const updatedAtoms = updateQueue;\n updateQueue = [];\n for (const atom of updatedAtoms) {\n atom.state.promise = undefined;\n atom.state.error = atom._nextError;\n atom.state.value = atom._nextValue;\n mark(atom);\n }\n }\n const markedAtoms = stack;\n stack = [];\n for (let i = markedAtoms.length; i--; ) {\n const atom = markedAtoms[i]!;\n atom._marked = false;\n if (atom._needExecute) {\n atom._needPropagate = true;\n execute(atom);\n }\n if (atom._needPropagate) {\n propagate(atom);\n }\n }\n};\nconst propagate = <Value>(atom: AtomInternal<Value>) => {\n atom._needPropagate = false;\n if (atom._watchers) {\n for (const watcher of atom._watchers) {\n try {\n watcher();\n } catch (e) {\n logError(e);\n }\n }\n }\n if (!atom.state.error && !atom.state.promise) {\n if (atom._subscribers) {\n for (const subscriber of atom._subscribers) {\n if (subscriber._ctrl) {\n subscriber._ctrl.abort();\n subscriber._ctrl = undefined;\n }\n try {\n subscriber._subscriber(atom.state.value!, subscriber._options);\n } catch (e) {\n logError(e);\n }\n }\n }\n if (atom._children) {\n for (const child of atom._children) {\n child._needExecute = true;\n }\n }\n }\n};\nconst mark = (atom: AtomInternal<any>) => {\n if (!atom._marked) {\n atom._marked = true;\n if (atom._children) {\n for (const child of atom._children) {\n mark(child);\n }\n }\n stack.push(atom);\n }\n};\n\nclass Wrapped {\n e: unknown;\n constructor(e: unknown) {\n this.e = e;\n }\n}\nconst expired = Symbol();\nconst execute = <Value>(atom: DerivedAtomInternal<Value>) => {\n const counter = ++atom._counter;\n const prevActive = atom._active;\n atom._active = true;\n atom._needExecute = false;\n atom.state.promise = undefined;\n\n if (atom._ctrl) {\n atom._ctrl.abort();\n atom._ctrl = undefined;\n }\n\n try {\n const value = atom._init(<V>(anotherAtom: AtomInternal<V>, unwrap = true) => {\n if (counter !== atom._counter) throw expired;\n if ((atom as unknown) !== anotherAtom) {\n if (!anotherAtom._active) {\n execute(anotherAtom);\n if (anotherAtom._needPropagate) {\n propagate(anotherAtom);\n }\n }\n (atom._nextDependencies ||= new Set()).add(anotherAtom);\n (anotherAtom._children ||= new Set()).add(atom);\n }\n if (!unwrap) return anotherAtom.state;\n if (anotherAtom.state.error) throw new Wrapped(anotherAtom.state.error);\n if (anotherAtom.state.promise) throw new Wrapped(anotherAtom.state.promise);\n return anotherAtom.state.value as V;\n }, atom._options);\n\n if (isPromiseLike(value)) {\n atom.state.promise = value;\n value.then(\n (value) => {\n if (counter === atom._counter) {\n finalizeExecution(atom);\n if (prevActive && equals(value, atom.state.value, atom._equals)) {\n atom.state.promise = undefined;\n // 동일한 값인데 propagate해줘야 되는 거 마음에 안 든다\n // watchers만 호출할까?\n } else {\n atom._nextValue = value;\n atom._nextError = undefined;\n }\n requestPropagate(atom);\n }\n },\n (e) => {\n if (counter === atom._counter) {\n finalizeExecution(atom);\n if (e instanceof Wrapped) {\n e = e.e;\n } else {\n logError(e);\n }\n atom._nextError = e;\n requestPropagate(atom);\n }\n },\n );\n } else {\n finalizeExecution(atom);\n atom.state.error = undefined;\n if (prevActive && equals(value, atom.state.value, atom._equals)) {\n atom._needPropagate = false;\n } else {\n atom.state.value = atom._nextValue = value;\n }\n }\n } catch (e) {\n finalizeExecution(atom);\n if (e === expired) {\n atom._needPropagate = false;\n } else {\n if (e instanceof Wrapped) {\n e = e.e;\n } else {\n logError(e);\n }\n atom.state.error = e;\n }\n }\n};\n\nconst finalizeExecution = <Value>(atom: DerivedAtomInternal<Value>) => {\n ++atom._counter;\n\n const oldDependencies = atom._dependencies;\n atom._dependencies = atom._nextDependencies;\n if (oldDependencies) {\n for (const dep of oldDependencies) {\n if (!atom._dependencies?.has(dep)) {\n dep._children!.delete(atom);\n disableAtom(dep);\n }\n }\n oldDependencies.clear();\n }\n atom._nextDependencies = oldDependencies;\n};\n\nlet runningGc = false;\nlet gcCandidates: Set<DerivedAtomInternal<any>> = new Set();\nconst disableAtom = <Value>(atom: AtomInternal<Value>) => {\n if (\n !atom._source &&\n !atom._persist &&\n !atom._children?.size &&\n !atom._watchers?.size &&\n !atom._subscribers?.size\n ) {\n gcCandidates.add(atom);\n if (!runningGc) {\n runningGc = true;\n setTimeout(gc, 0);\n }\n }\n};\nconst gc = () => {\n for (const atom of gcCandidates) {\n if (\n !atom._source &&\n !atom._persist &&\n !atom._children?.size &&\n !atom._watchers?.size &&\n !atom._subscribers?.size\n ) {\n atom.state.promise = inactive;\n atom._nextValue = atom._nextError = atom.state.error = atom.state.value = undefined;\n atom._needPropagate = atom._needExecute = atom._active = false;\n if (atom._ctrl) {\n atom._ctrl.abort();\n atom._ctrl = undefined;\n }\n if (atom._dependencies) {\n for (const dep of atom._dependencies) {\n dep._children!.delete(atom);\n disableAtom(dep);\n }\n atom._dependencies.clear();\n\n if (atom._nextDependencies) {\n for (const dep of atom._nextDependencies) {\n dep._children!.delete(atom);\n disableAtom(dep);\n }\n atom._nextDependencies.clear();\n }\n }\n }\n }\n gcCandidates.clear();\n runningGc = false;\n};\n\nconst equals = <Value>(\n value: Value,\n prevValue?: Value,\n equalsFn?: (value: Value, prevValue: Value) => boolean,\n) =>\n Object.is(value, prevValue) ||\n (equalsFn !== undefined && prevValue !== undefined && equalsFn(value, prevValue));\n\nconst isPromiseLike = (x: unknown): x is PromiseLike<unknown> =>\n typeof (x as PromiseLike<unknown>)?.then === \"function\";\n\nconst createThenableSignal = () => {\n const ctrl = new AbortController();\n const signal = ctrl.signal as ThenableSignal;\n const promise = new Promise((resolve) => {\n signal.then = (f: () => void) => promise.then(f);\n signal.addEventListener(\"abort\", resolve, {\n once: true,\n passive: true,\n });\n });\n return {\n abort: () => ctrl.abort(),\n signal,\n };\n};\n\nconst logError = (e: unknown) => {\n // Chrome's console.error doesn't follow the stack trace of the given Error\n queueMicrotask(() => {\n throw e;\n });\n};\n"],"mappings":";AA0GA,IAAe,qBAAf,MAAyC;CACvC;CACA;CACA;CACA;CACA;C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ElF,MAAM,iBAAiB,MACrB,OAAQ,GAA4B,SAAS;AAE/C,MAAM,6BAA6B;CACjC,MAAM,OAAO,IAAI,iBAAiB;CAClC,MAAM,SAAS,KAAK;CACpB,MAAM,UAAU,IAAI,SAAS,YAAY;AACvC,SAAO,QAAQ,MAAkB,QAAQ,KAAK,EAAE;AAChD,SAAO,iBAAiB,SAAS,SAAS;GACxC,MAAM;GACN,SAAS;GACV,CAAC;GACF;AACF,QAAO;EACL,aAAa,KAAK,OAAO;EACzB;EACD;;AAGH,MAAM,YAAY,MAAe;AAE/B,sBAAqB;AACnB,QAAM;GACN"}
|
|
1
|
+
{"version":3,"file":"atom.mjs","names":[],"sources":["../src/atom.ts"],"sourcesContent":["export type Atom<Value> = PrimitiveAtom<Value> | DerivedAtom<Value>;\nexport type CommonAtom<Value> = {\n readonly get: () => Value;\n readonly watch: (watcher: AtomWatcher) => () => void;\n readonly subscribe: (subscriber: AtomSubscribe<Value>) => () => void;\n readonly state: AtomState<Value>;\n};\nexport type PrimitiveAtom<Value> = CommonAtom<Value> & {\n readonly set: (value: AtomUpdater<Value>) => void;\n readonly state: AtomSuccessState<Value>;\n};\nexport type DerivedAtom<Value> = CommonAtom<Value>;\n\nexport type AtomWatcher = () => void;\nexport type AtomSubscribe<Value> = (value: Value, options: AtomSubscriberOptions) => void;\nexport type AtomInit<Value> = Value | AtomGetter<Value>;\nexport type AtomUpdater<Value> = Value | AtomReducer<Value>;\n// TODO: readonly\nexport type AtomInactiveState<Value> = {\n active: false;\n error: any;\n promise: undefined;\n value?: Value;\n};\nexport type AtomPromiseState<Value> = {\n active: true;\n error: any;\n promise: PromiseLike<Value>;\n value?: Value;\n};\nexport type AtomSuccessState<Value> = {\n active: true;\n error: undefined;\n promise: undefined;\n value: Value;\n};\nexport type AtomErrorState<Value> = {\n active: true;\n error: any;\n promise: undefined;\n value?: Value;\n};\nexport type AtomState<Value> =\n | AtomInactiveState<Value>\n | AtomPromiseState<Value>\n | AtomErrorState<Value>\n | AtomSuccessState<Value>;\n\nexport type AtomSubscriberOptions = { readonly signal: ThenableSignal };\nexport type AtomGetter<Value> = (\n get: GetAtom,\n options: AtomGetOptions,\n) => Value | PromiseLike<Value>;\nexport type AtomReducer<Value> = (value: Value) => Value;\n\nexport type AtomGetOptions = { readonly signal: ThenableSignal };\nexport type ThenableSignal = AbortSignal & { then: (f: () => void) => void };\ntype ThenableSignalController = {\n abort: () => void;\n signal: ThenableSignal;\n};\n\nexport type GetAtom = {\n <Value>(anotherAtom: Atom<Value>, watch?: false): Value;\n <Value>(\n anotherAtom: Atom<Value>,\n watch: true,\n ): AtomPromiseState<Value> | AtomErrorState<Value> | AtomSuccessState<Value>;\n};\n\ntype CreateAtom = {\n <Value>(init: AtomGetter<Value>, options?: AtomOptions<Value>): DerivedAtom<Value>;\n <Value>(init: Value, options?: AtomOptions<Value>): PrimitiveAtom<Value>;\n <Value>(init: Value | AtomGetter<Value>, options?: AtomOptions<Value>): Atom<Value>;\n};\nexport type AtomOptions<Value> = {\n equals?: AtomEquals<Value>;\n persist?: boolean;\n eager?: boolean;\n};\n\nexport type AtomEquals<Value> = (value: Value, prevValue: Value) => boolean;\nexport type AtomScope = {\n <Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;\n <Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;\n <Value>(baseAtom: Atom<Value>): Atom<Value>;\n <Value>(baseAtom: PrimitiveAtom<Value>, strict: true): PrimitiveAtom<Value> | undefined;\n <Value>(baseAtom: DerivedAtom<Value>, strict: true): DerivedAtom<Value> | undefined;\n <Value>(baseAtom: Atom<Value>, strict: true): Atom<Value> | undefined;\n};\n\nexport type SetLike<Key> = Key[] | Set<Key> | (Key extends object ? WeakSet<Key> : never);\nexport type MapLike<Key, Value> =\n | Map<Key, Value>\n | (Key extends object ? WeakMap<Key, Value> : never)\n | (Key extends string | number | symbol ? Record<Key, Value> : never);\n\ntype GetAtomInternal = <Value>(anotherAtom: AtomInternal<Value>) => Value;\ntype AtomGetterInternal<Value> = (\n get: GetAtomInternal,\n options: AtomGetOptions,\n) => Value | PromiseLike<Value>;\ntype AtomSubscribeInternal<Value> = {\n _subscriber: AtomSubscribe<Value>;\n _options: AtomSubscriberOptions;\n _ctrl?: ThenableSignalController;\n};\n\ntype AtomInternal<Value> = PrimitiveAtomInternal<Value> | DerivedAtomInternal<Value>;\n\nabstract class CommonAtomInternal<Value> {\n _nextValue: Value | undefined;\n _nextError: any | undefined;\n _children: Set<DerivedAtomInternal<any>> | undefined;\n _wchildren: Set<DerivedAtomInternal<any>> | undefined;\n _watchers: Set<AtomWatcher> | undefined;\n _subscribers: Set<AtomSubscribeInternal<Value>> | undefined;\n _valueChanged = true;\n\n abstract readonly _source: boolean;\n abstract _needExecute: boolean;\n abstract _needPropagate: boolean;\n abstract _marked: boolean;\n abstract _resolve: ((value: Value) => void) | undefined;\n abstract _reject: ((reason: any) => void) | undefined;\n\n abstract readonly _init: Value | AtomGetterInternal<Value>;\n abstract readonly _equals: AtomEquals<Value> | undefined;\n\n abstract readonly state: AtomState<Value>;\n\n get(): Value {\n if (!this.state.active) {\n execute(this as unknown as DerivedAtomInternal<Value>);\n disableAtom(this as unknown as AtomInternal<Value>);\n }\n if (this.state.promise) throw this.state.promise;\n if (this.state.error) throw this.state.error;\n return this.state.value!;\n }\n\n watch(watcher: AtomWatcher): () => void {\n if (!this.state.active) {\n requestActivate(this as unknown as DerivedAtomInternal<Value>);\n }\n (this._watchers ||= new Set()).add(watcher);\n return () => {\n this._watchers!.delete(watcher);\n if (!this._watchers!.size) {\n disableAtom(this as unknown as AtomInternal<Value>);\n }\n };\n }\n\n subscribe(subscriber: AtomSubscribe<Value>): () => void {\n const atomSubscriber: AtomSubscribeInternal<Value> = {\n _subscriber: subscriber,\n _options: {\n get signal() {\n return (atomSubscriber._ctrl ||= createThenableSignal()).signal;\n },\n },\n };\n if (!this.state.active) {\n requestActivate(this as unknown as DerivedAtomInternal<Value>);\n } else if (!this.state.error && !this.state.promise) {\n try {\n subscriber(this.state.value!, atomSubscriber._options);\n } catch (e) {\n logError(e);\n }\n }\n (this._subscribers ||= new Set()).add(atomSubscriber);\n return () => {\n this._subscribers!.delete(atomSubscriber);\n if (atomSubscriber._ctrl) {\n atomSubscriber._ctrl.abort();\n atomSubscriber._ctrl = undefined;\n }\n if (!this._subscribers!.size) {\n disableAtom(this as unknown as AtomInternal<Value>);\n }\n };\n }\n\n [Symbol.toPrimitive](): Value | undefined {\n return this.state.value;\n }\n}\n\nclass PrimitiveAtomInternal<Value> extends CommonAtomInternal<Value> {\n declare readonly _source: true;\n declare readonly _needExecute: false;\n _needPropagate: boolean = false;\n _marked: boolean = false;\n\n declare readonly _init: Value;\n declare readonly _equals: AtomEquals<Value> | undefined;\n\n declare state: AtomSuccessState<Value>;\n declare _hasValue: true;\n declare _nextValue: Value;\n declare _nextError: undefined;\n declare _resolve: undefined;\n declare _reject: undefined;\n\n constructor(init: Value, options?: AtomOptions<Value>) {\n super();\n this._nextValue = this._init = init;\n this._equals = options?.equals;\n this.state = {\n active: true,\n promise: undefined,\n error: undefined,\n value: init,\n };\n }\n\n set(this: PrimitiveAtomInternal<Value>, value: AtomUpdater<Value>) {\n const nextValue = value instanceof Function ? value(this._nextValue!) : value;\n if (!Object.is(nextValue, this._nextValue)) {\n this._nextValue = nextValue;\n requestPropagate(this);\n }\n }\n}\n// @ts-expect-error\nPrimitiveAtomInternal.prototype._source = true;\nPrimitiveAtomInternal.prototype._hasValue = true;\n// @ts-expect-error\nPrimitiveAtomInternal.prototype._needExecute = false;\n\nclass DerivedAtomInternal<Value> extends CommonAtomInternal<Value> {\n declare readonly _source: false;\n\n _hasValue = false;\n _needExecute = false;\n _needPropagate = false;\n _marked = false;\n\n _counter = 0;\n _resolve: ((value: Value) => void) | undefined;\n _reject: ((reason: any) => void) | undefined;\n _ctrl: ThenableSignalController | undefined;\n _dependencies: Set<AtomInternal<any>> | undefined;\n _wdependencies: Set<AtomInternal<any>> | undefined;\n _allDependencies: Set<AtomInternal<any>> | undefined;\n\n declare readonly _init: AtomGetterInternal<Value>;\n declare readonly _equals: AtomEquals<Value> | undefined;\n declare readonly _persist: boolean;\n declare readonly _options: AtomGetOptions;\n\n declare state: AtomState<Value>;\n\n constructor(init: AtomGetter<Value>, options?: AtomOptions<Value>) {\n super();\n this._init = init as AtomGetterInternal<Value>;\n this._equals = options?.equals;\n this._persist = !!options?.persist;\n\n const self = this;\n this._options = {\n get signal() {\n return (self._ctrl ||= createThenableSignal()).signal;\n },\n };\n\n this.state = {\n active: false,\n promise: undefined,\n error: undefined,\n value: undefined,\n };\n }\n}\n// @ts-expect-error\nDerivedAtomInternal.prototype._source = false;\n\nexport const $: CreateAtom = <Value>(\n init: Value | AtomGetter<Value>,\n options?: AtomOptions<Value>,\n) => {\n if (init instanceof Function) return new DerivedAtomInternal(init, options);\n return new PrimitiveAtomInternal(init, options) as any;\n};\n\nexport const isAtom = (x: unknown): x is Atom<unknown> => x instanceof CommonAtomInternal;\n\nexport const isPrimitiveAtom = (x: unknown): x is PrimitiveAtom<unknown> =>\n x instanceof PrimitiveAtomInternal;\n\nexport type AtomValuePair<Value> =\n | [Atom<Value>, Value | PrimitiveAtom<Value>]\n | [DerivedAtom<Value>, Value | Atom<Value>];\nexport const createScope = <T extends AtomValuePair<unknown>[]>(\n parentScope?: AtomScope | null,\n atomValuePairs?: T,\n): AtomScope => {\n const scopeMap = new WeakMap<Atom<any>, Atom<any>>();\n const atomMap = parentScope ? new WeakMap<Atom<any>, Atom<any>>() : scopeMap;\n const scope = (<T extends Atom<unknown>>(baseAtom: T, strict = false) => {\n let scopedAtom = scopeMap.get(baseAtom);\n if (!strict) scopedAtom ||= atomMap.get(baseAtom);\n // TODO: 현재 스코프마다 사용되는 모든 아톰을 저장해서 메모리 사용이 비효율적인데 해결할 수 있을까?\n // 의존성이 동적이라 많이 어렵다\n if (!scopedAtom) {\n const parentAtom = parentScope?.(baseAtom, true);\n if (strict) return parentAtom;\n const realBaseAtom = parentAtom || baseAtom;\n atomMap.set(\n baseAtom,\n (scopedAtom = (\n (realBaseAtom as AtomInternal<never>)._init instanceof Function\n ? $(\n (get, options) =>\n (realBaseAtom as AtomInternal<never>)._init((atom) => get(scope(atom)), options),\n {\n equals: (realBaseAtom as AtomInternal<never>)._equals,\n persist: (realBaseAtom as DerivedAtomInternal<never>)._persist,\n },\n )\n : // baseAtom을 전달하지 않고 새로 생성하는 이유는 SSR 등에서 사용자 간 상태 공유를 막기 위함\n parentAtom || $((realBaseAtom as AtomInternal<any>)._init)\n ) as T),\n );\n }\n return scopedAtom;\n }) as AtomScope;\n if (atomValuePairs) {\n for (const [atom, value] of atomValuePairs) {\n scopeMap.set(atom, isAtom(value) ? (parentScope || scope)(value) : $(value));\n }\n }\n return scope;\n};\n\nlet pendingUpdateAtoms = false;\nlet updateQueue: AtomInternal<any>[] = [];\nlet stack: AtomInternal<any>[] = [];\nconst requestActivate = <Value>(atom: DerivedAtomInternal<Value>) => {\n if (!atom._needExecute) {\n atom._needExecute = true;\n requestPropagate(atom);\n }\n};\nconst requestPropagate = <Value>(atom: AtomInternal<Value>) => {\n if (!atom._needPropagate) {\n atom._needPropagate = true;\n updateQueue.push(atom);\n if (!pendingUpdateAtoms) {\n pendingUpdateAtoms = true;\n queueMicrotask(updateAtoms);\n }\n }\n};\nconst updateAtoms = () => {\n pendingUpdateAtoms = false;\n {\n const updatedAtoms = updateQueue;\n updateQueue = [];\n for (const atom of updatedAtoms) {\n if (atom.state.active) {\n const prevSuccess = atom._hasValue && !atom.state.promise && !atom.state.error;\n if ((atom.state.error = atom._nextError)) {\n atom._nextValue = atom.state.value;\n if (atom._reject) {\n atom._reject(atom._nextError);\n atom._resolve = atom._reject = atom.state.promise = undefined;\n }\n } else {\n if (\n !atom._hasValue ||\n (!Object.is(atom._nextValue, atom.state.value) &&\n !atom._equals?.(atom._nextValue, atom.state.value!))\n ) {\n atom.state.value = atom._nextValue;\n atom._valueChanged = atom._hasValue = true;\n } else {\n atom._nextValue = atom.state.value;\n if (prevSuccess) {\n atom._needPropagate = false;\n continue;\n }\n }\n if (atom._resolve) {\n atom._resolve(atom._nextValue!);\n atom._resolve = atom._reject = atom.state.promise = undefined;\n }\n }\n }\n mark(atom);\n }\n }\n const markedAtoms = stack;\n stack = [];\n for (let i = markedAtoms.length; i--; ) {\n const atom = markedAtoms[i]!;\n atom._marked = false;\n if (atom._needExecute) {\n atom._needPropagate = true;\n execute(atom);\n }\n if (atom._needPropagate) {\n propagate(atom);\n }\n }\n};\nconst propagate = <Value>(atom: AtomInternal<Value>) => {\n atom._needPropagate = false;\n if (atom._watchers) {\n for (const watcher of atom._watchers) {\n try {\n watcher();\n } catch (e) {\n logError(e);\n }\n }\n }\n if (atom._wchildren) {\n for (const wchild of atom._wchildren) {\n wchild._needExecute = true;\n }\n }\n if (atom.state.promise) {\n if (atom._children) {\n for (const child of atom._children) {\n child.state.promise ||= new Promise((resolve, reject) => {\n child._resolve = resolve;\n child._reject = reject;\n });\n child._needPropagate = true;\n }\n }\n } else if (atom.state.error) {\n if (atom._children) {\n for (const child of atom._children) {\n child.state.error = child._nextError = atom.state.error;\n if (child._reject) {\n child._reject(child._nextError);\n child._resolve = child._reject = child.state.promise = undefined;\n }\n child._needPropagate = true;\n }\n }\n } else {\n if (atom._valueChanged && atom._subscribers) {\n for (const subscriber of atom._subscribers) {\n if (subscriber._ctrl) {\n subscriber._ctrl.abort();\n subscriber._ctrl = undefined;\n }\n try {\n subscriber._subscriber(atom.state.value!, subscriber._options);\n } catch (e) {\n logError(e);\n }\n }\n }\n if (atom._children) {\n for (const child of atom._children) {\n child._needExecute = true;\n }\n }\n }\n atom._valueChanged = false;\n};\nconst mark = (atom: AtomInternal<any>) => {\n if (!atom._marked) {\n atom._marked = true;\n if (atom._children) {\n for (const child of atom._children) {\n mark(child);\n }\n }\n if (atom._wchildren) {\n for (const child of atom._wchildren) {\n mark(child);\n }\n }\n stack.push(atom);\n }\n};\n\nclass Wrapped {\n e: unknown;\n constructor(e: unknown) {\n this.e = e;\n }\n}\nconst expired = Symbol();\nconst loading = Symbol();\nconst execute = <Value>(atom: DerivedAtomInternal<Value>) => {\n const counter = ++atom._counter;\n const prevSuccess = atom._hasValue && !atom.state.promise && !atom.state.error;\n\n atom.state.active = true;\n atom._needExecute = false;\n\n if (atom._dependencies) {\n for (const dep of atom._dependencies) {\n dep._children!.delete(atom);\n // TODO?: if (dep.aggressiveGc) disableAtom(dep);\n }\n atom._dependencies.clear();\n }\n if (atom._wdependencies) {\n for (const dep of atom._wdependencies) {\n dep._wchildren!.delete(atom);\n // TODO?: if (dep.aggressiveGc) disableAtom(dep);\n }\n atom._wdependencies.clear();\n }\n if (atom._ctrl) {\n atom._ctrl.abort();\n atom._ctrl = undefined;\n }\n\n try {\n const value = atom._init(<V>(anotherAtom: AtomInternal<V>, watch = false) => {\n if (counter !== atom._counter) throw expired;\n\n if ((atom as unknown) !== anotherAtom) {\n if (!anotherAtom.state.active) {\n execute(anotherAtom as DerivedAtomInternal<V>);\n }\n (atom._allDependencies ||= new Set()).add(anotherAtom);\n if (watch) {\n atom._dependencies?.delete(anotherAtom);\n (atom._wdependencies ||= new Set()).add(anotherAtom);\n (anotherAtom._wchildren ||= new Set()).add(atom);\n } else if (!atom._wdependencies?.has(anotherAtom)) {\n (atom._dependencies ||= new Set()).add(anotherAtom);\n (anotherAtom._children ||= new Set()).add(atom);\n }\n }\n\n const { state } = anotherAtom;\n if (watch) return state as V;\n if (state.promise) throw loading;\n if (state.error) throw new Wrapped(state.error);\n return state.value as V;\n }, atom._options);\n\n if (isPromiseLike(value)) {\n atom.state.promise ||= new Promise((resolve, reject) => {\n atom._resolve = resolve;\n atom._reject = reject;\n });\n value.then(\n (value) => {\n if (counter === atom._counter) {\n ++atom._counter;\n if (!atom._hasValue || !Object.is(value, atom._nextValue!)) atom._nextValue = value;\n atom._nextError = undefined;\n requestPropagate(atom);\n }\n },\n (e) => {\n if (counter === atom._counter && e !== expired) {\n ++atom._counter;\n if (e !== loading) {\n if (e instanceof Wrapped) {\n e = e.e;\n } else {\n logError(e);\n }\n atom._nextError = e;\n requestPropagate(atom);\n }\n }\n },\n );\n } else {\n ++atom._counter;\n if (\n !atom._hasValue ||\n (!Object.is(value, atom._nextValue) && !atom._equals?.(value, atom._nextValue!))\n ) {\n atom.state.value = atom._nextValue = value;\n atom._valueChanged = atom._hasValue = true;\n } else if (prevSuccess) {\n atom._needPropagate = false;\n }\n atom.state.error = atom._nextError = undefined;\n if (atom._resolve) {\n atom._resolve(atom._nextValue!);\n atom._resolve = atom._reject = atom.state.promise = undefined;\n }\n }\n } catch (e) {\n // assert(e !== expired);\n ++atom._counter;\n if (e === loading) {\n atom.state.promise ||= new Promise((resolve, reject) => {\n atom._resolve = resolve;\n atom._reject = reject;\n });\n } else {\n if (e instanceof Wrapped) {\n e = e.e;\n } else {\n logError(e);\n }\n atom.state.error = atom._nextError = e;\n if (atom._reject) {\n atom._reject(e);\n atom._resolve = atom._reject = atom.state.promise = undefined;\n }\n }\n }\n};\n\nlet runningGc = false;\nlet gcCandidates: Set<DerivedAtomInternal<any>> = new Set();\nconst disableAtom = <Value>(atom: AtomInternal<Value>) => {\n if (\n !atom._source &&\n !atom._persist &&\n !atom._children?.size &&\n !atom._watchers?.size &&\n !atom._subscribers?.size\n ) {\n gcCandidates.add(atom);\n if (!runningGc) {\n runningGc = true;\n setTimeout(gc, 0);\n }\n }\n};\nconst gc = () => {\n for (const atom of gcCandidates) {\n if (\n !atom._source &&\n !atom._persist &&\n !atom._children?.size &&\n !atom._watchers?.size &&\n !atom._subscribers?.size\n ) {\n atom._ctrl?.abort();\n // atom._reject?.(null);\n ++atom._counter;\n atom._nextValue =\n atom._nextError =\n atom.state.error =\n atom.state.value =\n atom.state.promise =\n atom._resolve =\n atom._reject =\n atom._ctrl =\n undefined;\n atom._needPropagate = atom._needExecute = atom._hasValue = atom.state.active = false;\n atom._valueChanged = atom._source;\n if (atom._allDependencies) {\n if (atom._dependencies) {\n for (const dep of atom._dependencies) {\n dep._children!.delete(atom);\n }\n atom._dependencies.clear();\n }\n if (atom._wdependencies) {\n for (const dep of atom._wdependencies) {\n dep._wchildren!.delete(atom);\n }\n atom._wdependencies.clear();\n }\n for (const dep of atom._allDependencies) {\n disableAtom(dep);\n }\n atom._allDependencies.clear();\n }\n }\n }\n gcCandidates.clear();\n runningGc = false;\n};\n\nconst isPromiseLike = (x: unknown): x is PromiseLike<unknown> =>\n typeof (x as PromiseLike<unknown>)?.then === \"function\";\n\nconst createThenableSignal = () => {\n const ctrl = new AbortController();\n const signal = ctrl.signal as ThenableSignal;\n const promise = new Promise((resolve) => {\n signal.then = (f: () => void) => promise.then(f);\n signal.addEventListener(\"abort\", resolve, {\n once: true,\n passive: true,\n });\n });\n return {\n abort: () => ctrl.abort(),\n signal,\n };\n};\n\nconst logError = (e: unknown) => {\n // Chrome's console.error doesn't follow the stack trace of the given Error\n queueMicrotask(() => {\n throw e;\n });\n};\n"],"mappings":";AA8GA,IAAe,qBAAf,MAAyC;CACvC;CACA;CACA;CACA;CACA;CACA;CACA,gBAAgB;CAchB,MAAa;AACX,MAAI,CAAC,KAAK,MAAM,QAAQ;AACtB,WAAQ,KAA8C;AACtD,eAAY,KAAuC;;AAErD,MAAI,KAAK,MAAM,QAAS,OAAM,KAAK,MAAM;AACzC,MAAI,KAAK,MAAM,MAAO,OAAM,KAAK,MAAM;AACvC,SAAO,KAAK,MAAM;;CAGpB,MAAM,SAAkC;AACtC,MAAI,CAAC,KAAK,MAAM,OACd,iBAAgB,KAA8C;AAEhE,GAAC,KAAK,8BAAc,IAAI,KAAK,EAAE,IAAI,QAAQ;AAC3C,eAAa;AACX,QAAK,UAAW,OAAO,QAAQ;AAC/B,OAAI,CAAC,KAAK,UAAW,KACnB,aAAY,KAAuC;;;CAKzD,UAAU,YAA8C;EACtD,MAAM,iBAA+C;GACnD,aAAa;GACb,UAAU,EACR,IAAI,SAAS;AACX,YAAQ,eAAe,UAAU,sBAAsB,EAAE;MAE5D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,iBAAiB;CAClC,MAAM,SAAS,KAAK;CACpB,MAAM,UAAU,IAAI,SAAS,YAAY;AACvC,SAAO,QAAQ,MAAkB,QAAQ,KAAK,EAAE;AAChD,SAAO,iBAAiB,SAAS,SAAS;GACxC,MAAM;GACN,SAAS;GACV,CAAC;GACF;AACF,QAAO;EACL,aAAa,KAAK,OAAO;EACzB;EACD;;AAGH,MAAM,YAAY,MAAe;AAE/B,sBAAqB;AACnB,QAAM;GACN"}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -16,26 +16,30 @@ type AtomSubscribe<Value> = (value: Value, options: AtomSubscriberOptions) => vo
|
|
|
16
16
|
type AtomInit<Value> = Value | AtomGetter<Value>;
|
|
17
17
|
type AtomUpdater<Value> = Value | AtomReducer<Value>;
|
|
18
18
|
type AtomInactiveState<Value> = {
|
|
19
|
-
|
|
19
|
+
active: false;
|
|
20
20
|
error: any;
|
|
21
|
+
promise: undefined;
|
|
21
22
|
value?: Value;
|
|
22
23
|
};
|
|
23
24
|
type AtomPromiseState<Value> = {
|
|
24
|
-
|
|
25
|
+
active: true;
|
|
25
26
|
error: any;
|
|
27
|
+
promise: PromiseLike<Value>;
|
|
26
28
|
value?: Value;
|
|
27
29
|
};
|
|
28
30
|
type AtomSuccessState<Value> = {
|
|
29
|
-
|
|
31
|
+
active: true;
|
|
30
32
|
error: undefined;
|
|
33
|
+
promise: undefined;
|
|
31
34
|
value: Value;
|
|
32
35
|
};
|
|
33
36
|
type AtomErrorState<Value> = {
|
|
34
|
-
|
|
37
|
+
active: true;
|
|
35
38
|
error: any;
|
|
39
|
+
promise: undefined;
|
|
36
40
|
value?: Value;
|
|
37
41
|
};
|
|
38
|
-
type AtomState<Value> = AtomInactiveState<Value> | AtomPromiseState<Value> |
|
|
42
|
+
type AtomState<Value> = AtomInactiveState<Value> | AtomPromiseState<Value> | AtomErrorState<Value> | AtomSuccessState<Value>;
|
|
39
43
|
type AtomSubscriberOptions = {
|
|
40
44
|
readonly signal: ThenableSignal;
|
|
41
45
|
};
|
|
@@ -48,8 +52,8 @@ type ThenableSignal = AbortSignal & {
|
|
|
48
52
|
then: (f: () => void) => void;
|
|
49
53
|
};
|
|
50
54
|
type GetAtom = {
|
|
51
|
-
<Value>(anotherAtom: Atom<Value>,
|
|
52
|
-
<Value>(anotherAtom: Atom<Value>,
|
|
55
|
+
<Value>(anotherAtom: Atom<Value>, watch?: false): Value;
|
|
56
|
+
<Value>(anotherAtom: Atom<Value>, watch: true): AtomPromiseState<Value> | AtomErrorState<Value> | AtomSuccessState<Value>;
|
|
53
57
|
};
|
|
54
58
|
type CreateAtom = {
|
|
55
59
|
<Value>(init: AtomGetter<Value>, options?: AtomOptions<Value>): DerivedAtom<Value>;
|
|
@@ -72,7 +76,6 @@ type AtomScope = {
|
|
|
72
76
|
};
|
|
73
77
|
type SetLike<Key> = Key[] | Set<Key> | (Key extends object ? WeakSet<Key> : never);
|
|
74
78
|
type MapLike<Key, Value> = Map<Key, Value> | (Key extends object ? WeakMap<Key, Value> : never) | (Key extends string | number | symbol ? Record<Key, Value> : never);
|
|
75
|
-
declare const inactive: Promise<never>;
|
|
76
79
|
declare const $: CreateAtom;
|
|
77
80
|
declare const isAtom: (x: unknown) => x is Atom<unknown>;
|
|
78
81
|
declare const isPrimitiveAtom: (x: unknown) => x is PrimitiveAtom<unknown>;
|
|
@@ -92,5 +95,5 @@ declare const collectAtoms: <T>(tree: T, get?: <T_1>(atom: Atom<T_1>) => T_1) =>
|
|
|
92
95
|
declare const setAtoms: <T>(tree: T, values: RecursiveOptional<CollectedAtoms<T>>) => void;
|
|
93
96
|
declare const $$: CollectAtom;
|
|
94
97
|
//#endregion
|
|
95
|
-
export { $, $$, Atom, AtomEquals, AtomErrorState, AtomGetOptions, AtomGetter, AtomInactiveState, AtomInit, AtomOptions, AtomPromiseState, AtomReducer, AtomScope, AtomState, AtomSubscribe, AtomSubscriberOptions, AtomSuccessState, AtomUpdater, AtomValuePair, AtomWatcher, Atomized, CollectedAtoms, CommonAtom, DerivedAtom, GetAtom, MapLike, PrimitiveAtom, RecursiveOptional, SetLike, ThenableSignal, atomize, collectAtoms, createScope,
|
|
98
|
+
export { $, $$, Atom, AtomEquals, AtomErrorState, AtomGetOptions, AtomGetter, AtomInactiveState, AtomInit, AtomOptions, AtomPromiseState, AtomReducer, AtomScope, AtomState, AtomSubscribe, AtomSubscriberOptions, AtomSuccessState, AtomUpdater, AtomValuePair, AtomWatcher, Atomized, CollectedAtoms, CommonAtom, DerivedAtom, GetAtom, MapLike, PrimitiveAtom, RecursiveOptional, SetLike, ThenableSignal, atomize, collectAtoms, createScope, isAtom, isPrimitiveAtom, setAtoms };
|
|
96
99
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/atom.ts","../../src/utils.ts"],"mappings":";KAAY,IAAA,UAAc,aAAA,CAAc,KAAA,IAAS,WAAA,CAAY,KAAA;AAAA,KACjD,UAAA;EAAA,SACD,GAAA,QAAW,KAAA;EAAA,SACX,KAAA,GAAQ,OAAA,EAAS,WAAA;EAAA,SACjB,SAAA,GAAY,UAAA,EAAY,aAAA,CAAc,KAAA;EAAA,SACtC,KAAA,EAAO,SAAA,CAAU,KAAA;AAAA;AAAA,KAEhB,aAAA,UAAuB,UAAA,CAAW,KAAA;EAAA,SACnC,GAAA,GAAM,KAAA,EAAO,WAAA,CAAY,KAAA;EAAA,SACzB,KAAA,EAAO,gBAAA,CAAiB,KAAA;AAAA;AAAA,KAEvB,WAAA,UAAqB,UAAA,CAAW,KAAA;AAAA,KAEhC,WAAA;AAAA,KACA,aAAA,WAAwB,KAAA,EAAO,KAAA,EAAO,OAAA,EAAS,qBAAA;AAAA,KAC/C,QAAA,UAAkB,KAAA,GAAQ,UAAA,CAAW,KAAA;AAAA,KACrC,WAAA,UAAqB,KAAA,GAAQ,WAAA,CAAY,KAAA;AAAA,KAEzC,iBAAA;EACV,
|
|
1
|
+
{"version":3,"file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AA;AAAA,KAGvC,iBAAA,MACR,CAAA,IACC,CAAA,gCAEiB,CAAA,GAAI,iBAAA,CAAkB,CAAA,CAAE,CAAA;AAAA,cAajC,OAAA,MAAc,IAAA,EAAM,CAAA,KAAI,QAAA,CAAS,CAAA;AAAA,cASjC,YAAA,MAAmB,IAAA,EAAM,CAAA,EAAG,GAAA,SAAA,IAAA,EADf,IAAA,CAAK,GAAA,MAAK,GAAA,KACqB,cAAA,CAAe,CAAA;AAAA,cAY3D,QAAA,MAAe,IAAA,EAAM,CAAA,EAAG,MAAA,EAAQ,iBAAA,CAAkB,cAAA,CAAe,CAAA;AAAA,cAajE,EAAA,EAAI,WAAA"}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=class{_nextValue;_nextError;_children;_watchers;_subscribers;get(){if(this.
|
|
1
|
+
var e=class{_nextValue;_nextError;_children;_wchildren;_watchers;_subscribers;_valueChanged=!0;get(){if(this.state.active||(v(this),x(this)),this.state.promise)throw this.state.promise;if(this.state.error)throw this.state.error;return this.state.value}watch(e){return this.state.active||u(this),(this._watchers||=new Set).add(e),()=>{this._watchers.delete(e),this._watchers.size||x(this)}}subscribe(e){let t={_subscriber:e,_options:{get signal(){return(t._ctrl||=w()).signal}}};if(!this.state.active)u(this);else if(!this.state.error&&!this.state.promise)try{e(this.state.value,t._options)}catch(e){T(e)}return(this._subscribers||=new Set).add(t),()=>{this._subscribers.delete(t),t._ctrl&&=(t._ctrl.abort(),void 0),this._subscribers.size||x(this)}}[Symbol.toPrimitive](){return this.state.value}},t=class extends e{_needPropagate=!1;_marked=!1;constructor(e,t){super(),this._nextValue=this._init=e,this._equals=t?.equals,this.state={active:!0,promise:void 0,error:void 0,value:e}}set(e){let t=e instanceof Function?e(this._nextValue):e;Object.is(t,this._nextValue)||(this._nextValue=t,d(this))}};t.prototype._source=!0,t.prototype._hasValue=!0,t.prototype._needExecute=!1;var n=class extends e{_hasValue=!1;_needExecute=!1;_needPropagate=!1;_marked=!1;_counter=0;_resolve;_reject;_ctrl;_dependencies;_wdependencies;_allDependencies;constructor(e,t){super(),this._init=e,this._equals=t?.equals,this._persist=!!t?.persist;let n=this;this._options={get signal(){return(n._ctrl||=w()).signal}},this.state={active:!1,promise:void 0,error:void 0,value:void 0}}};n.prototype._source=!1;const r=(e,r)=>e instanceof Function?new n(e,r):new t(e,r),i=t=>t instanceof e,a=e=>e instanceof t,o=(e,t)=>{let n=new WeakMap,a=e?new WeakMap:n,o=((t,i=!1)=>{let s=n.get(t);if(i||(s||=a.get(t)),!s){let n=e?.(t,!0);if(i)return n;let c=n||t;a.set(t,s=c._init instanceof Function?r((e,t)=>c._init(t=>e(o(t)),t),{equals:c._equals,persist:c._persist}):n||r(c._init))}return s});if(t)for(let[a,s]of t)n.set(a,i(s)?(e||o)(s):r(s));return o};let s=!1,c=[],l=[];const u=e=>{e._needExecute||(e._needExecute=!0,d(e))},d=e=>{e._needPropagate||(e._needPropagate=!0,c.push(e),s||(s=!0,queueMicrotask(f)))},f=()=>{s=!1;{let e=c;c=[];for(let t of e){if(t.state.active){let e=t._hasValue&&!t.state.promise&&!t.state.error;if(t.state.error=t._nextError)t._nextValue=t.state.value,t._reject&&(t._reject(t._nextError),t._resolve=t._reject=t.state.promise=void 0);else{if(!t._hasValue||!Object.is(t._nextValue,t.state.value)&&!t._equals?.(t._nextValue,t.state.value))t.state.value=t._nextValue,t._valueChanged=t._hasValue=!0;else if(t._nextValue=t.state.value,e){t._needPropagate=!1;continue}t._resolve&&=(t._resolve(t._nextValue),t._reject=t.state.promise=void 0)}}m(t)}}let e=l;l=[];for(let t=e.length;t--;){let n=e[t];n._marked=!1,n._needExecute&&(n._needPropagate=!0,v(n)),n._needPropagate&&p(n)}},p=e=>{if(e._needPropagate=!1,e._watchers)for(let t of e._watchers)try{t()}catch(e){T(e)}if(e._wchildren)for(let t of e._wchildren)t._needExecute=!0;if(e.state.promise){if(e._children)for(let t of e._children)t.state.promise||=new Promise((e,n)=>{t._resolve=e,t._reject=n}),t._needPropagate=!0}else if(e.state.error){if(e._children)for(let t of e._children)t.state.error=t._nextError=e.state.error,t._reject&&(t._reject(t._nextError),t._resolve=t._reject=t.state.promise=void 0),t._needPropagate=!0}else{if(e._valueChanged&&e._subscribers)for(let t of e._subscribers){t._ctrl&&=(t._ctrl.abort(),void 0);try{t._subscriber(e.state.value,t._options)}catch(e){T(e)}}if(e._children)for(let t of e._children)t._needExecute=!0}e._valueChanged=!1},m=e=>{if(!e._marked){if(e._marked=!0,e._children)for(let t of e._children)m(t);if(e._wchildren)for(let t of e._wchildren)m(t);l.push(e)}};var h=class{e;constructor(e){this.e=e}};const g=Symbol(),_=Symbol(),v=e=>{let t=++e._counter,n=e._hasValue&&!e.state.promise&&!e.state.error;if(e.state.active=!0,e._needExecute=!1,e._dependencies){for(let t of e._dependencies)t._children.delete(e);e._dependencies.clear()}if(e._wdependencies){for(let t of e._wdependencies)t._wchildren.delete(e);e._wdependencies.clear()}e._ctrl&&=(e._ctrl.abort(),void 0);try{let r=e._init((n,r=!1)=>{if(t!==e._counter)throw g;e!==n&&(n.state.active||v(n),(e._allDependencies||=new Set).add(n),r?(e._dependencies?.delete(n),(e._wdependencies||=new Set).add(n),(n._wchildren||=new Set).add(e)):e._wdependencies?.has(n)||((e._dependencies||=new Set).add(n),(n._children||=new Set).add(e)));let{state:i}=n;if(r)return i;if(i.promise)throw _;if(i.error)throw new h(i.error);return i.value},e._options);C(r)?(e.state.promise||=new Promise((t,n)=>{e._resolve=t,e._reject=n}),r.then(n=>{t===e._counter&&(++e._counter,(!e._hasValue||!Object.is(n,e._nextValue))&&(e._nextValue=n),e._nextError=void 0,d(e))},n=>{t===e._counter&&n!==g&&(++e._counter,n!==_&&(n instanceof h?n=n.e:T(n),e._nextError=n,d(e)))})):(++e._counter,!e._hasValue||!Object.is(r,e._nextValue)&&!e._equals?.(r,e._nextValue)?(e.state.value=e._nextValue=r,e._valueChanged=e._hasValue=!0):n&&(e._needPropagate=!1),e.state.error=e._nextError=void 0,e._resolve&&=(e._resolve(e._nextValue),e._reject=e.state.promise=void 0))}catch(t){++e._counter,t===_?e.state.promise||=new Promise((t,n)=>{e._resolve=t,e._reject=n}):(t instanceof h?t=t.e:T(t),e.state.error=e._nextError=t,e._reject&&(e._reject(t),e._resolve=e._reject=e.state.promise=void 0))}};let y=!1,b=new Set;const x=e=>{!e._source&&!e._persist&&!e._children?.size&&!e._watchers?.size&&!e._subscribers?.size&&(b.add(e),y||(y=!0,setTimeout(S,0)))},S=()=>{for(let e of b)if(!e._source&&!e._persist&&!e._children?.size&&!e._watchers?.size&&!e._subscribers?.size&&(e._ctrl?.abort(),++e._counter,e._nextValue=e._nextError=e.state.error=e.state.value=e.state.promise=e._resolve=e._reject=e._ctrl=void 0,e._needPropagate=e._needExecute=e._hasValue=e.state.active=!1,e._valueChanged=e._source,e._allDependencies)){if(e._dependencies){for(let t of e._dependencies)t._children.delete(e);e._dependencies.clear()}if(e._wdependencies){for(let t of e._wdependencies)t._wchildren.delete(e);e._wdependencies.clear()}for(let t of e._allDependencies)x(t);e._allDependencies.clear()}b.clear(),y=!1},C=e=>typeof e?.then==`function`,w=()=>{let e=new AbortController,t=e.signal,n=new Promise(e=>{t.then=e=>n.then(e),t.addEventListener(`abort`,e,{once:!0,passive:!0})});return{abort:()=>e.abort(),signal:t}},T=e=>{queueMicrotask(()=>{throw e})},E=()=>E,D=()=>void 0;Object.setPrototypeOf(E,new Proxy(E,{get:(e,t)=>t===Symbol.toPrimitive?D:E}));const O=e=>{if(typeof e!=`object`||!e)return r(e);if(Array.isArray(e))return e.map(O);let t=Object.create(null);for(let n in e)t[n]=O(e[n]);return t},k=e=>e.get(),A=(e,t=k)=>{let n=e=>{if(typeof e!=`object`||!e)return e;if(i(e))return t(e);if(Array.isArray(e))return e.map(n);let r=Object.create(null);for(let t in e)r[t]=n(e[t]);return r};return n(e)},j=(e,t)=>{let n=(e,t)=>{if(typeof e==`object`&&e)if(i(e))a(e)&&e.set(t);else for(let r in t)n(e[r],t[r])};n(e,t)},M=e=>e instanceof Function?r((t,n)=>{let r,i,a=e(e=>{let n=t(e,!0);if(n.error)i=n.error;else if(n.promise)(r||=[]).push(n.promise);else return n.value;return E},n);if(i)throw i;return r?Promise.all(r):a},{equals:N}):M(t=>A(e,t)),N=(e,t)=>{if(typeof e!=`object`||typeof t!=`object`||!e||!t)return!1;let n=e.constructor;if(n!==t.constructor)return!1;if(n===Array){let n=e.length;if(n!==t.length)return!1;for(;(n=n-1|0)>=0;)if(!Object.is(e[n],t[n]))return!1;return!0}let r=0;for(let n in e){if(!(n in t&&Object.is(e[n],t[n])))return!1;r=r+1|0}for(let e in t)if((r=r-1|0)<0)return!1;return!0};export{r as $,M as $$,O as atomize,A as collectAtoms,o as createScope,i as isAtom,a as isPrimitiveAtom,j as setAtoms};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|