@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.dev.js
CHANGED
|
@@ -348,6 +348,7 @@ var isInTransition = false;
|
|
|
348
348
|
var enqueueMicrotask = typeof queueMicrotask === "function" ? queueMicrotask : (fn) => {
|
|
349
349
|
Promise.resolve().then(fn);
|
|
350
350
|
};
|
|
351
|
+
var inCleanup = false;
|
|
351
352
|
function link(dep, sub, version) {
|
|
352
353
|
const prevDep = sub.depsTail;
|
|
353
354
|
if (prevDep !== void 0 && prevDep.dep === dep) return;
|
|
@@ -593,7 +594,15 @@ function updateComputed(c) {
|
|
|
593
594
|
}
|
|
594
595
|
function runEffect(e) {
|
|
595
596
|
const flags = e.flags;
|
|
596
|
-
if (flags & Dirty
|
|
597
|
+
if (flags & Dirty) {
|
|
598
|
+
if (e.runCleanup) {
|
|
599
|
+
inCleanup = true;
|
|
600
|
+
try {
|
|
601
|
+
e.runCleanup();
|
|
602
|
+
} finally {
|
|
603
|
+
inCleanup = false;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
597
606
|
++cycle;
|
|
598
607
|
effectRunDevtools(e);
|
|
599
608
|
e.depsTail = void 0;
|
|
@@ -610,6 +619,35 @@ function runEffect(e) {
|
|
|
610
619
|
e.flags = Watching;
|
|
611
620
|
throw err;
|
|
612
621
|
}
|
|
622
|
+
} else if (flags & Pending && e.deps) {
|
|
623
|
+
if (e.runCleanup) {
|
|
624
|
+
inCleanup = true;
|
|
625
|
+
try {
|
|
626
|
+
e.runCleanup();
|
|
627
|
+
} finally {
|
|
628
|
+
inCleanup = false;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (checkDirty(e.deps, e)) {
|
|
632
|
+
++cycle;
|
|
633
|
+
effectRunDevtools(e);
|
|
634
|
+
e.depsTail = void 0;
|
|
635
|
+
e.flags = WatchingRunning;
|
|
636
|
+
const prevSub = activeSub;
|
|
637
|
+
activeSub = e;
|
|
638
|
+
try {
|
|
639
|
+
e.fn();
|
|
640
|
+
activeSub = prevSub;
|
|
641
|
+
e.flags = Watching;
|
|
642
|
+
purgeDeps(e);
|
|
643
|
+
} catch (err) {
|
|
644
|
+
activeSub = prevSub;
|
|
645
|
+
e.flags = Watching;
|
|
646
|
+
throw err;
|
|
647
|
+
}
|
|
648
|
+
} else {
|
|
649
|
+
e.flags = Watching;
|
|
650
|
+
}
|
|
613
651
|
} else {
|
|
614
652
|
e.flags = Watching;
|
|
615
653
|
}
|
|
@@ -705,7 +743,7 @@ function signalOper(value) {
|
|
|
705
743
|
return;
|
|
706
744
|
}
|
|
707
745
|
const flags = this.flags;
|
|
708
|
-
if (flags & Dirty) {
|
|
746
|
+
if (flags & Dirty && !inCleanup) {
|
|
709
747
|
if (updateSignal(this)) {
|
|
710
748
|
const subs = this.subs;
|
|
711
749
|
if (subs !== void 0) shallowPropagate(subs);
|
|
@@ -787,6 +825,30 @@ function effect(fn) {
|
|
|
787
825
|
}
|
|
788
826
|
return effectOper.bind(e);
|
|
789
827
|
}
|
|
828
|
+
function effectWithCleanup(fn, cleanupRunner) {
|
|
829
|
+
const e = {
|
|
830
|
+
fn,
|
|
831
|
+
subs: void 0,
|
|
832
|
+
subsTail: void 0,
|
|
833
|
+
deps: void 0,
|
|
834
|
+
depsTail: void 0,
|
|
835
|
+
flags: WatchingRunning,
|
|
836
|
+
runCleanup: cleanupRunner,
|
|
837
|
+
__id: void 0
|
|
838
|
+
};
|
|
839
|
+
registerEffectDevtools(e);
|
|
840
|
+
const prevSub = activeSub;
|
|
841
|
+
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
842
|
+
activeSub = e;
|
|
843
|
+
try {
|
|
844
|
+
effectRunDevtools(e);
|
|
845
|
+
fn();
|
|
846
|
+
} finally {
|
|
847
|
+
activeSub = prevSub;
|
|
848
|
+
e.flags &= ~Running;
|
|
849
|
+
}
|
|
850
|
+
return effectOper.bind(e);
|
|
851
|
+
}
|
|
790
852
|
function effectOper() {
|
|
791
853
|
disposeNode(this);
|
|
792
854
|
}
|
|
@@ -1034,8 +1096,11 @@ var $memo = createMemo;
|
|
|
1034
1096
|
function createEffect(fn) {
|
|
1035
1097
|
let cleanups = [];
|
|
1036
1098
|
const rootForError = getCurrentRoot();
|
|
1037
|
-
const
|
|
1099
|
+
const doCleanup = () => {
|
|
1038
1100
|
runCleanupList(cleanups);
|
|
1101
|
+
cleanups = [];
|
|
1102
|
+
};
|
|
1103
|
+
const run = () => {
|
|
1039
1104
|
const bucket = [];
|
|
1040
1105
|
withEffectCleanups(bucket, () => {
|
|
1041
1106
|
try {
|
|
@@ -1052,7 +1117,7 @@ function createEffect(fn) {
|
|
|
1052
1117
|
});
|
|
1053
1118
|
cleanups = bucket;
|
|
1054
1119
|
};
|
|
1055
|
-
const disposeEffect =
|
|
1120
|
+
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1056
1121
|
const teardown = () => {
|
|
1057
1122
|
runCleanupList(cleanups);
|
|
1058
1123
|
disposeEffect();
|
|
@@ -1064,11 +1129,13 @@ var $effect = createEffect;
|
|
|
1064
1129
|
function createRenderEffect(fn) {
|
|
1065
1130
|
let cleanup;
|
|
1066
1131
|
const rootForError = getCurrentRoot();
|
|
1067
|
-
const
|
|
1132
|
+
const doCleanup = () => {
|
|
1068
1133
|
if (cleanup) {
|
|
1069
1134
|
cleanup();
|
|
1070
1135
|
cleanup = void 0;
|
|
1071
1136
|
}
|
|
1137
|
+
};
|
|
1138
|
+
const run = () => {
|
|
1072
1139
|
try {
|
|
1073
1140
|
const maybeCleanup = fn();
|
|
1074
1141
|
if (typeof maybeCleanup === "function") {
|
|
@@ -1082,7 +1149,7 @@ function createRenderEffect(fn) {
|
|
|
1082
1149
|
throw err;
|
|
1083
1150
|
}
|
|
1084
1151
|
};
|
|
1085
|
-
const disposeEffect =
|
|
1152
|
+
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1086
1153
|
const teardown = () => {
|
|
1087
1154
|
if (cleanup) {
|
|
1088
1155
|
cleanup();
|