mono-jsx 0.9.3 → 0.9.4
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/dom/jsx-runtime.mjs +27 -13
- package/package.json +1 -1
- package/types/dom/index.d.ts +3 -3
package/dom/jsx-runtime.mjs
CHANGED
|
@@ -55,12 +55,17 @@ var Reactive = class {
|
|
|
55
55
|
var Signal = class extends Reactive {
|
|
56
56
|
#scope;
|
|
57
57
|
#key;
|
|
58
|
-
|
|
58
|
+
#isAtom;
|
|
59
|
+
constructor(scope, key, isAtom = false) {
|
|
59
60
|
super();
|
|
60
61
|
this.#scope = scope;
|
|
61
62
|
this.#key = key;
|
|
63
|
+
this.#isAtom = isAtom;
|
|
62
64
|
}
|
|
63
65
|
get() {
|
|
66
|
+
if (this.#isAtom) {
|
|
67
|
+
$depsMark?.add(this);
|
|
68
|
+
}
|
|
64
69
|
return this.#scope[$get](this.#key);
|
|
65
70
|
}
|
|
66
71
|
set(value) {
|
|
@@ -237,19 +242,29 @@ var createScope = (slots, abortSignal) => {
|
|
|
237
242
|
return refs;
|
|
238
243
|
default: {
|
|
239
244
|
const value = Reflect.get(target, key, receiver);
|
|
240
|
-
if (
|
|
241
|
-
return
|
|
245
|
+
if (typeof key === "symbol" || isFunction(value)) {
|
|
246
|
+
return value;
|
|
242
247
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
248
|
+
const getRawValue = !exprMode || $depsMark !== void 0;
|
|
249
|
+
if (value instanceof Reactive) {
|
|
250
|
+
if (getRawValue) {
|
|
251
|
+
if (value instanceof Signal) {
|
|
252
|
+
$depsMark?.add(value);
|
|
253
|
+
}
|
|
254
|
+
return value.get();
|
|
246
255
|
}
|
|
247
256
|
return value;
|
|
248
257
|
}
|
|
249
|
-
|
|
250
|
-
|
|
258
|
+
let signal = signals.get(key);
|
|
259
|
+
if (!signal) {
|
|
260
|
+
signal = new Signal(receiver, key);
|
|
261
|
+
signals.set(key, signal);
|
|
262
|
+
}
|
|
263
|
+
if (getRawValue) {
|
|
264
|
+
$depsMark?.add(signal);
|
|
265
|
+
return value;
|
|
251
266
|
}
|
|
252
|
-
return
|
|
267
|
+
return signal;
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
270
|
},
|
|
@@ -264,7 +279,6 @@ var createScope = (slots, abortSignal) => {
|
|
|
264
279
|
return true;
|
|
265
280
|
}
|
|
266
281
|
});
|
|
267
|
-
let getSignal = (key) => signals.get(key) ?? signals.set(key, new Signal(scope, key)).get(key);
|
|
268
282
|
onAbort(abortSignal, () => {
|
|
269
283
|
watchHandlers.clear();
|
|
270
284
|
refElements.clear();
|
|
@@ -278,9 +292,9 @@ var atom = (value) => {
|
|
|
278
292
|
if (!atomScope) {
|
|
279
293
|
atomScope = createScope();
|
|
280
294
|
}
|
|
281
|
-
const atomKey = "
|
|
282
|
-
atomScope
|
|
283
|
-
return new Signal(atomScope, atomKey);
|
|
295
|
+
const atomKey = "$" + atomIndex++;
|
|
296
|
+
atomScope[atomKey] = value;
|
|
297
|
+
return new Signal(atomScope, atomKey, true);
|
|
284
298
|
};
|
|
285
299
|
var store = (props) => {
|
|
286
300
|
const scope = createScope().extend(props);
|
package/package.json
CHANGED
package/types/dom/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="../jsx.d.ts" />
|
|
2
2
|
|
|
3
3
|
export interface IAtom<T> {
|
|
4
|
-
get
|
|
5
|
-
set
|
|
6
|
-
map
|
|
4
|
+
get(): T;
|
|
5
|
+
set(value: T | ((prev: T) => T)): void;
|
|
6
|
+
map(callback: (value: T extends (infer V)[] ? V : T, index: number) => JSX.Element): JSX.Element[];
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export const atom: <T>(initValue: T) => IAtom<T>;
|