@fictjs/runtime 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +728 -678
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +555 -530
- package/dist/index.d.ts +555 -530
- package/dist/index.dev.js +729 -679
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +726 -679
- package/dist/index.js.map +1 -1
- package/dist/slim.cjs +87 -8
- package/dist/slim.cjs.map +1 -1
- package/dist/slim.d.cts +31 -4
- package/dist/slim.d.ts +31 -4
- package/dist/slim.js +85 -9
- package/dist/slim.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/scope.ts +55 -0
- package/src/slim.ts +1 -0
package/dist/slim.cjs
CHANGED
|
@@ -101,6 +101,7 @@ function reportCycle(reason, detail = void 0) {
|
|
|
101
101
|
|
|
102
102
|
// src/lifecycle.ts
|
|
103
103
|
var currentRoot;
|
|
104
|
+
var currentEffectCleanups;
|
|
104
105
|
var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
|
|
105
106
|
var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
|
|
106
107
|
function createRootContext(parent = currentRoot) {
|
|
@@ -130,6 +131,9 @@ function onDestroy(fn) {
|
|
|
130
131
|
}
|
|
131
132
|
runLifecycle(fn);
|
|
132
133
|
}
|
|
134
|
+
function onCleanup(fn) {
|
|
135
|
+
registerEffectCleanup(fn);
|
|
136
|
+
}
|
|
133
137
|
function flushOnMount(root) {
|
|
134
138
|
const cbs = root.onMountCallbacks;
|
|
135
139
|
if (!cbs || cbs.length === 0) return;
|
|
@@ -168,10 +172,35 @@ function destroyRoot(root) {
|
|
|
168
172
|
globalSuspenseHandlers.delete(root);
|
|
169
173
|
}
|
|
170
174
|
}
|
|
175
|
+
function createRoot(fn) {
|
|
176
|
+
const root = createRootContext();
|
|
177
|
+
const prev = pushRoot(root);
|
|
178
|
+
let value;
|
|
179
|
+
try {
|
|
180
|
+
value = fn();
|
|
181
|
+
} finally {
|
|
182
|
+
popRoot(prev);
|
|
183
|
+
}
|
|
184
|
+
flushOnMount(root);
|
|
185
|
+
return {
|
|
186
|
+
dispose: () => destroyRoot(root),
|
|
187
|
+
value
|
|
188
|
+
};
|
|
189
|
+
}
|
|
171
190
|
function withEffectCleanups(bucket, fn) {
|
|
191
|
+
const prev = currentEffectCleanups;
|
|
192
|
+
currentEffectCleanups = bucket;
|
|
172
193
|
try {
|
|
173
194
|
return fn();
|
|
174
195
|
} finally {
|
|
196
|
+
currentEffectCleanups = prev;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function registerEffectCleanup(fn) {
|
|
200
|
+
if (currentEffectCleanups) {
|
|
201
|
+
currentEffectCleanups.push(fn);
|
|
202
|
+
} else {
|
|
203
|
+
registerRootCleanup(fn);
|
|
175
204
|
}
|
|
176
205
|
}
|
|
177
206
|
function runCleanupList(list) {
|
|
@@ -720,6 +749,21 @@ function effect(fn) {
|
|
|
720
749
|
function effectOper() {
|
|
721
750
|
disposeNode(this);
|
|
722
751
|
}
|
|
752
|
+
function effectScope(fn) {
|
|
753
|
+
const e = { deps: void 0, depsTail: void 0, subs: void 0, subsTail: void 0, flags: 0 };
|
|
754
|
+
const prevSub = activeSub;
|
|
755
|
+
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
756
|
+
activeSub = e;
|
|
757
|
+
try {
|
|
758
|
+
fn();
|
|
759
|
+
} finally {
|
|
760
|
+
activeSub = prevSub;
|
|
761
|
+
}
|
|
762
|
+
return effectScopeOper.bind(e);
|
|
763
|
+
}
|
|
764
|
+
function effectScopeOper() {
|
|
765
|
+
disposeNode(this);
|
|
766
|
+
}
|
|
723
767
|
function batch(fn) {
|
|
724
768
|
++batchDepth;
|
|
725
769
|
try {
|
|
@@ -863,14 +907,6 @@ function createRenderEffect(fn) {
|
|
|
863
907
|
return teardown;
|
|
864
908
|
}
|
|
865
909
|
|
|
866
|
-
// src/scheduler.ts
|
|
867
|
-
function batch2(fn) {
|
|
868
|
-
return batch(fn);
|
|
869
|
-
}
|
|
870
|
-
function untrack2(fn) {
|
|
871
|
-
return untrack(fn);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
910
|
// src/constants.ts
|
|
875
911
|
var booleans = [
|
|
876
912
|
"allowfullscreen",
|
|
@@ -2347,6 +2383,46 @@ function bumpBlockVersion(block) {
|
|
|
2347
2383
|
block.version(block.version() + 1);
|
|
2348
2384
|
}
|
|
2349
2385
|
|
|
2386
|
+
// src/scope.ts
|
|
2387
|
+
function createScope() {
|
|
2388
|
+
let dispose = null;
|
|
2389
|
+
const stop = () => {
|
|
2390
|
+
if (dispose) {
|
|
2391
|
+
dispose();
|
|
2392
|
+
dispose = null;
|
|
2393
|
+
}
|
|
2394
|
+
};
|
|
2395
|
+
const run = (fn) => {
|
|
2396
|
+
stop();
|
|
2397
|
+
const { dispose: rootDispose, value } = createRoot(fn);
|
|
2398
|
+
dispose = rootDispose;
|
|
2399
|
+
return value;
|
|
2400
|
+
};
|
|
2401
|
+
registerRootCleanup(stop);
|
|
2402
|
+
return { run, stop };
|
|
2403
|
+
}
|
|
2404
|
+
function runInScope(flag, fn) {
|
|
2405
|
+
const scope = createScope();
|
|
2406
|
+
const evaluate = () => isReactive(flag) ? flag() : !!flag;
|
|
2407
|
+
createEffect(() => {
|
|
2408
|
+
const enabled = evaluate();
|
|
2409
|
+
if (enabled) {
|
|
2410
|
+
scope.run(fn);
|
|
2411
|
+
} else {
|
|
2412
|
+
scope.stop();
|
|
2413
|
+
}
|
|
2414
|
+
});
|
|
2415
|
+
onCleanup(scope.stop);
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
// src/scheduler.ts
|
|
2419
|
+
function batch2(fn) {
|
|
2420
|
+
return batch(fn);
|
|
2421
|
+
}
|
|
2422
|
+
function untrack2(fn) {
|
|
2423
|
+
return untrack(fn);
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2350
2426
|
// src/hooks.ts
|
|
2351
2427
|
var ctxStack = [];
|
|
2352
2428
|
function __fictUseContext() {
|
|
@@ -3366,10 +3442,12 @@ exports.createList = createList;
|
|
|
3366
3442
|
exports.createMemo = createMemo;
|
|
3367
3443
|
exports.createPropsProxy = createPropsProxy;
|
|
3368
3444
|
exports.createRenderEffect = createRenderEffect;
|
|
3445
|
+
exports.createScope = createScope;
|
|
3369
3446
|
exports.createSelector = createSelector;
|
|
3370
3447
|
exports.createSignal = signal;
|
|
3371
3448
|
exports.delegateEvents = delegateEvents;
|
|
3372
3449
|
exports.destroyMarkerBlock = destroyMarkerBlock;
|
|
3450
|
+
exports.effectScope = effectScope;
|
|
3373
3451
|
exports.getFirstNodeAfter = getFirstNodeAfter;
|
|
3374
3452
|
exports.insert = insert;
|
|
3375
3453
|
exports.insertNodesBefore = insertNodesBefore;
|
|
@@ -3379,6 +3457,7 @@ exports.onDestroy = onDestroy;
|
|
|
3379
3457
|
exports.prop = __fictProp;
|
|
3380
3458
|
exports.removeNodes = removeNodes;
|
|
3381
3459
|
exports.render = render;
|
|
3460
|
+
exports.runInScope = runInScope;
|
|
3382
3461
|
exports.template = template;
|
|
3383
3462
|
exports.toNodeArray = toNodeArray;
|
|
3384
3463
|
exports.untrack = untrack2;
|