Server: Phase 2 (REVIEW not respected yet)

This commit is contained in:
Thomas Karner committed 2026-09-21 11:24:43 +02:00
1 parent 5d16ded553
commit 142b47674d
4271 files changed
+1203269

No files matched your search

+182
View File
@@ -0,0 +1,182 @@
//#region src/alien.ts
const NONE = 0;
const MUTABLE = 1;
const WATCHING = 2;
const RECURSED_CHECK = 4;
const RECURSED = 8;
const DIRTY = 16;
const PENDING = 32;
/* @__NO_SIDE_EFFECTS__ */
function createReactiveSystem({ update, notify, unwatched }) {
return {
link,
unlink,
propagate,
checkDirty,
shallowPropagate
};
function link(dep, sub, version) {
const prevDep = sub.depsTail;
if (prevDep !== void 0 && prevDep.dep === dep) return;
const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
if (nextDep !== void 0 && nextDep.dep === dep) {
nextDep.version = version;
sub.depsTail = nextDep;
return;
}
const prevSub = dep.subsTail;
if (prevSub !== void 0 && prevSub.version === version && prevSub.sub === sub) return;
const newLink = sub.depsTail = dep.subsTail = {
version,
dep,
sub,
prevDep,
nextDep,
prevSub,
nextSub: void 0
};
if (nextDep !== void 0) nextDep.prevDep = newLink;
if (prevDep !== void 0) prevDep.nextDep = newLink;
else sub.deps = newLink;
if (prevSub !== void 0) prevSub.nextSub = newLink;
else dep.subs = newLink;
}
function unlink(link, sub = link.sub) {
const dep = link.dep;
const prevDep = link.prevDep;
const nextDep = link.nextDep;
const nextSub = link.nextSub;
const prevSub = link.prevSub;
if (nextDep !== void 0) nextDep.prevDep = prevDep;
else sub.depsTail = prevDep;
if (prevDep !== void 0) prevDep.nextDep = nextDep;
else sub.deps = nextDep;
if (nextSub !== void 0) nextSub.prevSub = prevSub;
else dep.subsTail = prevSub;
if (prevSub !== void 0) prevSub.nextSub = nextSub;
else if ((dep.subs = nextSub) === void 0) unwatched(dep);
return nextDep;
}
function propagate(link) {
let next = link.nextSub;
let stack;
top: do {
const sub = link.sub;
let flags = sub.flags;
if (!(flags & 60)) sub.flags = flags | 32;
else if (!(flags & (4 | 8))) flags = 0;
else if (!(flags & 4)) sub.flags = flags & ~8 | 32;
else if (!(flags & (16 | 32)) && isValidLink(link, sub)) {
sub.flags = flags | (8 | 32);
flags &= 1;
} else flags = 0;
if (flags & 2) notify(sub);
if (flags & 1) {
const subSubs = sub.subs;
if (subSubs !== void 0) {
const nextSub = (link = subSubs).nextSub;
if (nextSub !== void 0) {
stack = {
value: next,
prev: stack
};
next = nextSub;
}
continue;
}
}
if ((link = next) !== void 0) {
next = link.nextSub;
continue;
}
while (stack !== void 0) {
link = stack.value;
stack = stack.prev;
if (link !== void 0) {
next = link.nextSub;
continue top;
}
}
break;
} while (true);
}
function checkDirty(link, sub) {
let stack;
let checkDepth = 0;
let dirty = false;
top: do {
const dep = link.dep;
const flags = dep.flags;
if (sub.flags & 16) dirty = true;
else if ((flags & (1 | 16)) === (1 | 16)) {
if (update(dep)) {
const subs = dep.subs;
if (subs.nextSub !== void 0) shallowPropagate(subs);
dirty = true;
}
} else if ((flags & (1 | 32)) === (1 | 32)) {
if (link.nextSub !== void 0 || link.prevSub !== void 0) stack = {
value: link,
prev: stack
};
link = dep.deps;
sub = dep;
++checkDepth;
continue;
}
if (!dirty) {
const nextDep = link.nextDep;
if (nextDep !== void 0) {
link = nextDep;
continue;
}
}
while (checkDepth--) {
const firstSub = sub.subs;
const hasMultipleSubs = firstSub.nextSub !== void 0;
if (hasMultipleSubs) {
link = stack.value;
stack = stack.prev;
} else link = firstSub;
if (dirty) {
if (update(sub)) {
if (hasMultipleSubs) shallowPropagate(firstSub);
sub = link.sub;
continue;
}
dirty = false;
} else sub.flags &= ~32;
sub = link.sub;
const nextDep = link.nextDep;
if (nextDep !== void 0) {
link = nextDep;
continue top;
}
}
return dirty;
} while (true);
}
function shallowPropagate(link) {
do {
const sub = link.sub;
const flags = sub.flags;
if ((flags & (32 | 16)) === 32) {
sub.flags = flags | 16;
if ((flags & (2 | 4)) === 2) notify(sub);
}
} while ((link = link.nextSub) !== void 0);
}
function isValidLink(checkLink, sub) {
let link = sub.depsTail;
while (link !== void 0) {
if (link === checkLink) return true;
link = link.prevDep;
}
return false;
}
}
//#endregion
exports.createReactiveSystem = createReactiveSystem;
//# sourceMappingURL=alien.cjs.map