@fictjs/runtime 0.0.10 → 0.0.11
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 +73 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.js +73 -6
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +73 -6
- package/dist/index.js.map +1 -1
- package/dist/slim.cjs +73 -6
- package/dist/slim.cjs.map +1 -1
- package/dist/slim.js +73 -6
- package/dist/slim.js.map +1 -1
- package/package.json +1 -1
- package/src/effect.ts +16 -5
- package/src/signal.ts +86 -2
package/dist/index.js
CHANGED
|
@@ -346,6 +346,7 @@ var isInTransition = false;
|
|
|
346
346
|
var enqueueMicrotask = typeof queueMicrotask === "function" ? queueMicrotask : (fn) => {
|
|
347
347
|
Promise.resolve().then(fn);
|
|
348
348
|
};
|
|
349
|
+
var inCleanup = false;
|
|
349
350
|
function link(dep, sub, version) {
|
|
350
351
|
const prevDep = sub.depsTail;
|
|
351
352
|
if (prevDep !== void 0 && prevDep.dep === dep) return;
|
|
@@ -591,7 +592,15 @@ function updateComputed(c) {
|
|
|
591
592
|
}
|
|
592
593
|
function runEffect(e) {
|
|
593
594
|
const flags = e.flags;
|
|
594
|
-
if (flags & Dirty
|
|
595
|
+
if (flags & Dirty) {
|
|
596
|
+
if (e.runCleanup) {
|
|
597
|
+
inCleanup = true;
|
|
598
|
+
try {
|
|
599
|
+
e.runCleanup();
|
|
600
|
+
} finally {
|
|
601
|
+
inCleanup = false;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
595
604
|
++cycle;
|
|
596
605
|
effectRunDevtools(e);
|
|
597
606
|
e.depsTail = void 0;
|
|
@@ -608,6 +617,35 @@ function runEffect(e) {
|
|
|
608
617
|
e.flags = Watching;
|
|
609
618
|
throw err;
|
|
610
619
|
}
|
|
620
|
+
} else if (flags & Pending && e.deps) {
|
|
621
|
+
if (e.runCleanup) {
|
|
622
|
+
inCleanup = true;
|
|
623
|
+
try {
|
|
624
|
+
e.runCleanup();
|
|
625
|
+
} finally {
|
|
626
|
+
inCleanup = false;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (checkDirty(e.deps, e)) {
|
|
630
|
+
++cycle;
|
|
631
|
+
effectRunDevtools(e);
|
|
632
|
+
e.depsTail = void 0;
|
|
633
|
+
e.flags = WatchingRunning;
|
|
634
|
+
const prevSub = activeSub;
|
|
635
|
+
activeSub = e;
|
|
636
|
+
try {
|
|
637
|
+
e.fn();
|
|
638
|
+
activeSub = prevSub;
|
|
639
|
+
e.flags = Watching;
|
|
640
|
+
purgeDeps(e);
|
|
641
|
+
} catch (err) {
|
|
642
|
+
activeSub = prevSub;
|
|
643
|
+
e.flags = Watching;
|
|
644
|
+
throw err;
|
|
645
|
+
}
|
|
646
|
+
} else {
|
|
647
|
+
e.flags = Watching;
|
|
648
|
+
}
|
|
611
649
|
} else {
|
|
612
650
|
e.flags = Watching;
|
|
613
651
|
}
|
|
@@ -703,7 +741,7 @@ function signalOper(value) {
|
|
|
703
741
|
return;
|
|
704
742
|
}
|
|
705
743
|
const flags = this.flags;
|
|
706
|
-
if (flags & Dirty) {
|
|
744
|
+
if (flags & Dirty && !inCleanup) {
|
|
707
745
|
if (updateSignal(this)) {
|
|
708
746
|
const subs = this.subs;
|
|
709
747
|
if (subs !== void 0) shallowPropagate(subs);
|
|
@@ -785,6 +823,30 @@ function effect(fn) {
|
|
|
785
823
|
}
|
|
786
824
|
return effectOper.bind(e);
|
|
787
825
|
}
|
|
826
|
+
function effectWithCleanup(fn, cleanupRunner) {
|
|
827
|
+
const e = {
|
|
828
|
+
fn,
|
|
829
|
+
subs: void 0,
|
|
830
|
+
subsTail: void 0,
|
|
831
|
+
deps: void 0,
|
|
832
|
+
depsTail: void 0,
|
|
833
|
+
flags: WatchingRunning,
|
|
834
|
+
runCleanup: cleanupRunner,
|
|
835
|
+
__id: void 0
|
|
836
|
+
};
|
|
837
|
+
registerEffectDevtools(e);
|
|
838
|
+
const prevSub = activeSub;
|
|
839
|
+
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
840
|
+
activeSub = e;
|
|
841
|
+
try {
|
|
842
|
+
effectRunDevtools(e);
|
|
843
|
+
fn();
|
|
844
|
+
} finally {
|
|
845
|
+
activeSub = prevSub;
|
|
846
|
+
e.flags &= ~Running;
|
|
847
|
+
}
|
|
848
|
+
return effectOper.bind(e);
|
|
849
|
+
}
|
|
788
850
|
function effectOper() {
|
|
789
851
|
disposeNode(this);
|
|
790
852
|
}
|
|
@@ -1030,8 +1092,11 @@ var $memo = createMemo;
|
|
|
1030
1092
|
function createEffect(fn) {
|
|
1031
1093
|
let cleanups = [];
|
|
1032
1094
|
const rootForError = getCurrentRoot();
|
|
1033
|
-
const
|
|
1095
|
+
const doCleanup = () => {
|
|
1034
1096
|
runCleanupList(cleanups);
|
|
1097
|
+
cleanups = [];
|
|
1098
|
+
};
|
|
1099
|
+
const run = () => {
|
|
1035
1100
|
const bucket = [];
|
|
1036
1101
|
withEffectCleanups(bucket, () => {
|
|
1037
1102
|
try {
|
|
@@ -1048,7 +1113,7 @@ function createEffect(fn) {
|
|
|
1048
1113
|
});
|
|
1049
1114
|
cleanups = bucket;
|
|
1050
1115
|
};
|
|
1051
|
-
const disposeEffect =
|
|
1116
|
+
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1052
1117
|
const teardown = () => {
|
|
1053
1118
|
runCleanupList(cleanups);
|
|
1054
1119
|
disposeEffect();
|
|
@@ -1060,11 +1125,13 @@ var $effect = createEffect;
|
|
|
1060
1125
|
function createRenderEffect(fn) {
|
|
1061
1126
|
let cleanup;
|
|
1062
1127
|
const rootForError = getCurrentRoot();
|
|
1063
|
-
const
|
|
1128
|
+
const doCleanup = () => {
|
|
1064
1129
|
if (cleanup) {
|
|
1065
1130
|
cleanup();
|
|
1066
1131
|
cleanup = void 0;
|
|
1067
1132
|
}
|
|
1133
|
+
};
|
|
1134
|
+
const run = () => {
|
|
1068
1135
|
try {
|
|
1069
1136
|
const maybeCleanup = fn();
|
|
1070
1137
|
if (typeof maybeCleanup === "function") {
|
|
@@ -1078,7 +1145,7 @@ function createRenderEffect(fn) {
|
|
|
1078
1145
|
throw err;
|
|
1079
1146
|
}
|
|
1080
1147
|
};
|
|
1081
|
-
const disposeEffect =
|
|
1148
|
+
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1082
1149
|
const teardown = () => {
|
|
1083
1150
|
if (cleanup) {
|
|
1084
1151
|
cleanup();
|