FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

21
node_modules/alien-signals/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024-present Johnson Chu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

191
node_modules/alien-signals/README.md generated vendored Normal file
View File

@@ -0,0 +1,191 @@
<p align="center">
<img src="assets/logo.png" width="250"><br>
<p>
<p align="center">
<a href="https://npmjs.com/package/alien-signals"><img src="https://badgen.net/npm/v/alien-signals" alt="npm package"></a>
<a href="https://deepwiki.com/stackblitz/alien-signals"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
</p>
# alien-signals
This project explores a push-pull based signal algorithm. Its current implementation is similar to or related to certain other frontend projects:
- Propagation algorithm of Vue 3
- Preacts double-linked-list approach (https://preactjs.com/blog/signal-boosting/)
- Inner effects scheduling of Svelte
- Graph-coloring approach of Reactively (https://milomg.dev/2022-12-01/reactivity)
We impose some constraints (such as not using Array/Set/Map and disallowing function recursion) to ensure performance. We found that under these conditions, maintaining algorithmic simplicity offers more significant improvements than complex scheduling strategies.
Even though Vue 3.4 is already optimized, alien-signals is still noticeably faster. (I wrote code for both, and since they share similar algorithms, theyre quite comparable.)
<img width="1210" alt="Image" src="https://github.com/user-attachments/assets/88448f6d-4034-4389-89aa-9edf3da77254" />
> Benchmark repo: https://github.com/transitive-bullshit/js-reactivity-benchmark
## Background
I spent considerable time [optimizing Vue 3.4s reactivity system](https://github.com/vuejs/core/pull/5912), gaining experience along the way. Since Vue 3.5 [switched to a pull-based algorithm similar to Preact](https://github.com/vuejs/core/pull/10397), I decided to continue researching a push-pull based implementation in a separate project. Our end goal is to implement fully incremental AST parsing and virtual code generation in Vue language tools, based on alien-signals.
## Other Language Implementations
- **Dart:** [medz/alien-signals-dart](https://github.com/medz/alien-signals-dart) <sup>2.0.5</sup>
- **Lua:** [YanqingXu/alien-signals-in-lua](https://github.com/YanqingXu/alien-signals-in-lua) <sup>2.0.5</sup>
- **Lua 5.4:** [xuhuanzy/alien-signals-lua](https://github.com/xuhuanzy/alien-signals-lua) <sup>2.0.5</sup>
- **Luau:** [Nicell/alien-signals-luau](https://github.com/Nicell/alien-signals-luau) <sup>1.0.13</sup>
- **Java:** [CTRL-Neo-Studios/java-alien-signals](https://github.com/CTRL-Neo-Studios/java-alien-signals) <sup>1.0.13</sup>
- **C#:** [CTRL-Neo-Studios/csharp-alien-signals](https://github.com/CTRL-Neo-Studios/csharp-alien-signals) <sup>1.0.13</sup>
- **Go:** [delaneyj/alien-signals-go](https://github.com/delaneyj/alien-signals-go) <sup>1.0.7</sup>
## Derived Projects
- [Rajaniraiyn/react-alien-signals](https://github.com/Rajaniraiyn/react-alien-signals): React bindings for the alien-signals API
- [CCherry07/alien-deepsignals](https://github.com/CCherry07/alien-deepsignals): Use alien-signals with the interface of a plain JavaScript object
- [hunghg255/reactjs-signal](https://github.com/hunghg255/reactjs-signal): Share Store State with Signal Pattern
- [gn8-ai/universe-alien-signals](https://github.com/gn8-ai/universe-alien-signals): Enables simple use of the Alien Signals state management system in modern frontend frameworks
- [WebReflection/alien-signals](https://github.com/WebReflection/alien-signals): Preact signals like API and a class based approach for easy brand check
- [@lift-html/alien](https://github.com/JLarky/lift-html/tree/main/packages/alien): Integrating alien-signals into lift-html
## Adoption
- [vuejs/core](https://github.com/vuejs/core): The core algorithm has been ported to v3.6 (PR: https://github.com/vuejs/core/pull/12349)
- [statelyai/xstate](https://github.com/statelyai/xstate): The core algorithm has been ported to implement the atom architecture (PR: https://github.com/statelyai/xstate/pull/5250)
- [flamrdevs/xignal](https://github.com/flamrdevs/xignal): Infrastructure for the reactive system
- [vuejs/language-tools](https://github.com/vuejs/language-tools): Used in the language-core package for virtual code generation
- [unuse](https://github.com/un-ts/unuse): A framework-agnostic `use` library inspired by `VueUse`
## Usage
#### Basic APIs
```ts
import { signal, computed, effect } from 'alien-signals';
const count = signal(1);
const doubleCount = computed(() => count() * 2);
effect(() => {
console.log(`Count is: ${count()}`);
}); // Console: Count is: 1
console.log(doubleCount()); // 2
count(2); // Console: Count is: 2
console.log(doubleCount()); // 4
```
#### Effect Scope
```ts
import { signal, effect, effectScope } from 'alien-signals';
const count = signal(1);
const stopScope = effectScope(() => {
effect(() => {
console.log(`Count in scope: ${count()}`);
}); // Console: Count in scope: 1
});
count(2); // Console: Count in scope: 2
stopScope();
count(3); // No console output
```
#### Creating Your Own Surface API
You can reuse alien-signals core algorithm via `createReactiveSystem()` to build your own signal API. For implementation examples, see:
- [Starter template](https://github.com/johnsoncodehk/alien-signals-starter) (implements `.get()` & `.set()` methods like the [Signals proposal](https://github.com/tc39/proposal-signals))
- [stackblitz/alien-signals/src/index.ts](https://github.com/stackblitz/alien-signals/blob/master/src/index.ts)
- [proposal-signals/signal-polyfill#44](https://github.com/proposal-signals/signal-polyfill/pull/44)
## About `propagate` and `checkDirty` functions
In order to eliminate recursive calls and improve performance, we record the last link node of the previous loop in `propagate` and `checkDirty` functions, and implement the rollback logic to return to this node.
This results in code that is difficult to understand, and you don't necessarily get the same performance improvements in other languages, so we record the original implementation without eliminating recursive calls here for reference.
#### `propagate`
```ts
function propagate(link: Link): void {
do {
const sub = link.sub;
let flags = sub.flags;
if (flags & (ReactiveFlags.Mutable | ReactiveFlags.Watching)) {
if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed | ReactiveFlags.Dirty | ReactiveFlags.Pending))) {
sub.flags = flags | ReactiveFlags.Pending;
} else if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed))) {
flags = ReactiveFlags.None;
} else if (!(flags & ReactiveFlags.RecursedCheck)) {
sub.flags = (flags & ~ReactiveFlags.Recursed) | ReactiveFlags.Pending;
} else if (!(flags & (ReactiveFlags.Dirty | ReactiveFlags.Pending)) && isValidLink(link, sub)) {
sub.flags = flags | ReactiveFlags.Recursed | ReactiveFlags.Pending;
flags &= ReactiveFlags.Mutable;
} else {
flags = ReactiveFlags.None;
}
if (flags & ReactiveFlags.Watching) {
notify(sub);
}
if (flags & ReactiveFlags.Mutable) {
const subSubs = sub.subs;
if (subSubs !== undefined) {
propagate(subSubs);
}
}
}
link = link.nextSub!;
} while (link !== undefined);
}
```
#### `checkDirty`
```ts
function checkDirty(link: Link, sub: ReactiveNode): boolean {
do {
const dep = link.dep;
const depFlags = dep.flags;
if (sub.flags & ReactiveFlags.Dirty) {
return true;
} else if ((depFlags & (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) === (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) {
if (update(dep)) {
const subs = dep.subs!;
if (subs.nextSub !== undefined) {
shallowPropagate(subs);
}
return true;
}
} else if ((depFlags & (ReactiveFlags.Mutable | ReactiveFlags.Pending)) === (ReactiveFlags.Mutable | ReactiveFlags.Pending)) {
if (checkDirty(dep.deps!, dep)) {
if (update(dep)) {
const subs = dep.subs!;
if (subs.nextSub !== undefined) {
shallowPropagate(subs);
}
return true;
}
} else {
dep.flags = depFlags & ~ReactiveFlags.Pending;
}
}
link = link.nextDep!;
} while (link !== undefined);
return false;
}
```

287
node_modules/alien-signals/cjs/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,287 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.batchDepth = void 0;
exports.getCurrentSub = getCurrentSub;
exports.setCurrentSub = setCurrentSub;
exports.getCurrentScope = getCurrentScope;
exports.setCurrentScope = setCurrentScope;
exports.startBatch = startBatch;
exports.endBatch = endBatch;
exports.pauseTracking = pauseTracking;
exports.resumeTracking = resumeTracking;
exports.signal = signal;
exports.computed = computed;
exports.effect = effect;
exports.effectScope = effectScope;
__exportStar(require("./system.cjs"), exports);
const system_js_1 = require("./system.cjs");
const pauseStack = [];
const queuedEffects = [];
const { link, unlink, propagate, checkDirty, endTracking, startTracking, shallowPropagate, } = (0, system_js_1.createReactiveSystem)({
update(signal) {
if ('getter' in signal) {
return updateComputed(signal);
}
else {
return updateSignal(signal, signal.value);
}
},
notify,
unwatched(node) {
if ('getter' in node) {
let toRemove = node.deps;
if (toRemove !== undefined) {
node.flags = 17;
do {
toRemove = unlink(toRemove, node);
} while (toRemove !== undefined);
}
}
else if (!('previousValue' in node)) {
effectOper.call(node);
}
},
});
exports.batchDepth = 0;
let notifyIndex = 0;
let queuedEffectsLength = 0;
let activeSub;
let activeScope;
function getCurrentSub() {
return activeSub;
}
function setCurrentSub(sub) {
const prevSub = activeSub;
activeSub = sub;
return prevSub;
}
function getCurrentScope() {
return activeScope;
}
function setCurrentScope(scope) {
const prevScope = activeScope;
activeScope = scope;
return prevScope;
}
function startBatch() {
++exports.batchDepth;
}
function endBatch() {
if (!--exports.batchDepth) {
flush();
}
}
function pauseTracking() {
pauseStack.push(setCurrentSub(undefined));
}
function resumeTracking() {
setCurrentSub(pauseStack.pop());
}
function signal(initialValue) {
return signalOper.bind({
previousValue: initialValue,
value: initialValue,
subs: undefined,
subsTail: undefined,
flags: 1,
});
}
function computed(getter) {
return computedOper.bind({
value: undefined,
subs: undefined,
subsTail: undefined,
deps: undefined,
depsTail: undefined,
flags: 17,
getter: getter,
});
}
function effect(fn) {
const e = {
fn,
subs: undefined,
subsTail: undefined,
deps: undefined,
depsTail: undefined,
flags: 2,
};
if (activeSub !== undefined) {
link(e, activeSub);
}
else if (activeScope !== undefined) {
link(e, activeScope);
}
const prev = setCurrentSub(e);
try {
e.fn();
}
finally {
setCurrentSub(prev);
}
return effectOper.bind(e);
}
function effectScope(fn) {
const e = {
deps: undefined,
depsTail: undefined,
subs: undefined,
subsTail: undefined,
flags: 0,
};
if (activeScope !== undefined) {
link(e, activeScope);
}
const prevSub = setCurrentSub(undefined);
const prevScope = setCurrentScope(e);
try {
fn();
}
finally {
setCurrentScope(prevScope);
setCurrentSub(prevSub);
}
return effectOper.bind(e);
}
function updateComputed(c) {
const prevSub = setCurrentSub(c);
startTracking(c);
try {
const oldValue = c.value;
return oldValue !== (c.value = c.getter(oldValue));
}
finally {
setCurrentSub(prevSub);
endTracking(c);
}
}
function updateSignal(s, value) {
s.flags = 1;
return s.previousValue !== (s.previousValue = value);
}
function notify(e) {
const flags = e.flags;
if (!(flags & 64)) {
e.flags = flags | 64;
const subs = e.subs;
if (subs !== undefined) {
notify(subs.sub);
}
else {
queuedEffects[queuedEffectsLength++] = e;
}
}
}
function run(e, flags) {
if (flags & 16
|| (flags & 32 && checkDirty(e.deps, e))) {
const prev = setCurrentSub(e);
startTracking(e);
try {
e.fn();
}
finally {
setCurrentSub(prev);
endTracking(e);
}
return;
}
else if (flags & 32) {
e.flags = flags & ~32;
}
let link = e.deps;
while (link !== undefined) {
const dep = link.dep;
const depFlags = dep.flags;
if (depFlags & 64) {
run(dep, dep.flags = depFlags & ~64);
}
link = link.nextDep;
}
}
function flush() {
while (notifyIndex < queuedEffectsLength) {
const effect = queuedEffects[notifyIndex];
queuedEffects[notifyIndex++] = undefined;
run(effect, effect.flags &= ~64);
}
notifyIndex = 0;
queuedEffectsLength = 0;
}
function computedOper() {
const flags = this.flags;
if (flags & 16
|| (flags & 32 && checkDirty(this.deps, this))) {
if (updateComputed(this)) {
const subs = this.subs;
if (subs !== undefined) {
shallowPropagate(subs);
}
}
}
else if (flags & 32) {
this.flags = flags & ~32;
}
if (activeSub !== undefined) {
link(this, activeSub);
}
else if (activeScope !== undefined) {
link(this, activeScope);
}
return this.value;
}
function signalOper(...value) {
if (value.length) {
const newValue = value[0];
if (this.value !== (this.value = newValue)) {
this.flags = 17;
const subs = this.subs;
if (subs !== undefined) {
propagate(subs);
if (!exports.batchDepth) {
flush();
}
}
}
}
else {
const value = this.value;
if (this.flags & 16) {
if (updateSignal(this, value)) {
const subs = this.subs;
if (subs !== undefined) {
shallowPropagate(subs);
}
}
}
if (activeSub !== undefined) {
link(this, activeSub);
}
return value;
}
}
function effectOper() {
let dep = this.deps;
while (dep !== undefined) {
dep = unlink(dep, this);
}
const sub = this.subs;
if (sub !== undefined) {
unlink(sub);
}
this.flags = 0;
}

264
node_modules/alien-signals/cjs/system.cjs generated vendored Normal file
View File

@@ -0,0 +1,264 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReactiveFlags = void 0;
exports.createReactiveSystem = createReactiveSystem;
var ReactiveFlags;
(function (ReactiveFlags) {
ReactiveFlags[ReactiveFlags["None"] = 0] = "None";
ReactiveFlags[ReactiveFlags["Mutable"] = 1] = "Mutable";
ReactiveFlags[ReactiveFlags["Watching"] = 2] = "Watching";
ReactiveFlags[ReactiveFlags["RecursedCheck"] = 4] = "RecursedCheck";
ReactiveFlags[ReactiveFlags["Recursed"] = 8] = "Recursed";
ReactiveFlags[ReactiveFlags["Dirty"] = 16] = "Dirty";
ReactiveFlags[ReactiveFlags["Pending"] = 32] = "Pending";
})(ReactiveFlags || (exports.ReactiveFlags = ReactiveFlags = {}));
function createReactiveSystem({ update, notify, unwatched, }) {
let version = 0;
return {
link,
unlink,
propagate,
checkDirty,
endTracking,
startTracking,
shallowPropagate,
};
function link(dep, sub) {
const prevDep = sub.depsTail;
if (prevDep !== undefined && prevDep.dep === dep) {
return;
}
let nextDep;
if (sub.flags & 4) {
nextDep = prevDep !== undefined ? prevDep.nextDep : sub.deps;
if (nextDep !== undefined && nextDep.dep === dep) {
nextDep.version = version;
sub.depsTail = nextDep;
return;
}
}
const prevSub = dep.subsTail;
if (prevSub !== undefined && prevSub.version === version && prevSub.sub === sub) {
return;
}
const newLink = sub.depsTail
= dep.subsTail
= {
version,
dep,
sub,
prevDep,
nextDep,
prevSub,
nextSub: undefined,
};
if (nextDep !== undefined) {
nextDep.prevDep = newLink;
}
if (prevDep !== undefined) {
prevDep.nextDep = newLink;
}
else {
sub.deps = newLink;
}
if (prevSub !== undefined) {
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 !== undefined) {
nextDep.prevDep = prevDep;
}
else {
sub.depsTail = prevDep;
}
if (prevDep !== undefined) {
prevDep.nextDep = nextDep;
}
else {
sub.deps = nextDep;
}
if (nextSub !== undefined) {
nextSub.prevSub = prevSub;
}
else {
dep.subsTail = prevSub;
}
if (prevSub !== undefined) {
prevSub.nextSub = nextSub;
}
else if ((dep.subs = nextSub) === undefined) {
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 & 3) {
if (!(flags & 60)) {
sub.flags = flags | 32;
}
else if (!(flags & 12)) {
flags = 0;
}
else if (!(flags & 4)) {
sub.flags = (flags & ~8) | 32;
}
else if (!(flags & 48) && isValidLink(link, sub)) {
sub.flags = flags | 40;
flags &= 1;
}
else {
flags = 0;
}
if (flags & 2) {
notify(sub);
}
if (flags & 1) {
const subSubs = sub.subs;
if (subSubs !== undefined) {
link = subSubs;
if (subSubs.nextSub !== undefined) {
stack = { value: next, prev: stack };
next = link.nextSub;
}
continue;
}
}
}
if ((link = next) !== undefined) {
next = link.nextSub;
continue;
}
while (stack !== undefined) {
link = stack.value;
stack = stack.prev;
if (link !== undefined) {
next = link.nextSub;
continue top;
}
}
break;
} while (true);
}
function startTracking(sub) {
++version;
sub.depsTail = undefined;
sub.flags = (sub.flags & ~56) | 4;
}
function endTracking(sub) {
const depsTail = sub.depsTail;
let toRemove = depsTail !== undefined ? depsTail.nextDep : sub.deps;
while (toRemove !== undefined) {
toRemove = unlink(toRemove, sub);
}
sub.flags &= ~4;
}
function checkDirty(link, sub) {
let stack;
let checkDepth = 0;
top: do {
const dep = link.dep;
const depFlags = dep.flags;
let dirty = false;
if (sub.flags & 16) {
dirty = true;
}
else if ((depFlags & 17) === 17) {
if (update(dep)) {
const subs = dep.subs;
if (subs.nextSub !== undefined) {
shallowPropagate(subs);
}
dirty = true;
}
}
else if ((depFlags & 33) === 33) {
if (link.nextSub !== undefined || link.prevSub !== undefined) {
stack = { value: link, prev: stack };
}
link = dep.deps;
sub = dep;
++checkDepth;
continue;
}
if (!dirty && link.nextDep !== undefined) {
link = link.nextDep;
continue;
}
while (checkDepth) {
--checkDepth;
const firstSub = sub.subs;
const hasMultipleSubs = firstSub.nextSub !== undefined;
if (hasMultipleSubs) {
link = stack.value;
stack = stack.prev;
}
else {
link = firstSub;
}
if (dirty) {
if (update(sub)) {
if (hasMultipleSubs) {
shallowPropagate(firstSub);
}
sub = link.sub;
continue;
}
}
else {
sub.flags &= ~32;
}
sub = link.sub;
if (link.nextDep !== undefined) {
link = link.nextDep;
continue top;
}
dirty = false;
}
return dirty;
} while (true);
}
function shallowPropagate(link) {
do {
const sub = link.sub;
const nextSub = link.nextSub;
const subFlags = sub.flags;
if ((subFlags & 48) === 32) {
sub.flags = subFlags | 16;
if (subFlags & 2) {
notify(sub);
}
}
link = nextSub;
} while (link !== undefined);
}
function isValidLink(checkLink, sub) {
const depsTail = sub.depsTail;
if (depsTail !== undefined) {
let link = sub.deps;
do {
if (link === checkLink) {
return true;
}
if (link === depsTail) {
break;
}
link = link.nextDep;
} while (link !== undefined);
}
return false;
}
}

258
node_modules/alien-signals/esm/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,258 @@
export * from './system.mjs';
import { createReactiveSystem } from './system.mjs';
const pauseStack = [];
const queuedEffects = [];
const { link, unlink, propagate, checkDirty, endTracking, startTracking, shallowPropagate, } = createReactiveSystem({
update(signal) {
if ('getter' in signal) {
return updateComputed(signal);
}
else {
return updateSignal(signal, signal.value);
}
},
notify,
unwatched(node) {
if ('getter' in node) {
let toRemove = node.deps;
if (toRemove !== undefined) {
node.flags = 17;
do {
toRemove = unlink(toRemove, node);
} while (toRemove !== undefined);
}
}
else if (!('previousValue' in node)) {
effectOper.call(node);
}
},
});
export let batchDepth = 0;
let notifyIndex = 0;
let queuedEffectsLength = 0;
let activeSub;
let activeScope;
export function getCurrentSub() {
return activeSub;
}
export function setCurrentSub(sub) {
const prevSub = activeSub;
activeSub = sub;
return prevSub;
}
export function getCurrentScope() {
return activeScope;
}
export function setCurrentScope(scope) {
const prevScope = activeScope;
activeScope = scope;
return prevScope;
}
export function startBatch() {
++batchDepth;
}
export function endBatch() {
if (!--batchDepth) {
flush();
}
}
export function pauseTracking() {
pauseStack.push(setCurrentSub(undefined));
}
export function resumeTracking() {
setCurrentSub(pauseStack.pop());
}
export function signal(initialValue) {
return signalOper.bind({
previousValue: initialValue,
value: initialValue,
subs: undefined,
subsTail: undefined,
flags: 1,
});
}
export function computed(getter) {
return computedOper.bind({
value: undefined,
subs: undefined,
subsTail: undefined,
deps: undefined,
depsTail: undefined,
flags: 17,
getter: getter,
});
}
export function effect(fn) {
const e = {
fn,
subs: undefined,
subsTail: undefined,
deps: undefined,
depsTail: undefined,
flags: 2,
};
if (activeSub !== undefined) {
link(e, activeSub);
}
else if (activeScope !== undefined) {
link(e, activeScope);
}
const prev = setCurrentSub(e);
try {
e.fn();
}
finally {
setCurrentSub(prev);
}
return effectOper.bind(e);
}
export function effectScope(fn) {
const e = {
deps: undefined,
depsTail: undefined,
subs: undefined,
subsTail: undefined,
flags: 0,
};
if (activeScope !== undefined) {
link(e, activeScope);
}
const prevSub = setCurrentSub(undefined);
const prevScope = setCurrentScope(e);
try {
fn();
}
finally {
setCurrentScope(prevScope);
setCurrentSub(prevSub);
}
return effectOper.bind(e);
}
function updateComputed(c) {
const prevSub = setCurrentSub(c);
startTracking(c);
try {
const oldValue = c.value;
return oldValue !== (c.value = c.getter(oldValue));
}
finally {
setCurrentSub(prevSub);
endTracking(c);
}
}
function updateSignal(s, value) {
s.flags = 1;
return s.previousValue !== (s.previousValue = value);
}
function notify(e) {
const flags = e.flags;
if (!(flags & 64)) {
e.flags = flags | 64;
const subs = e.subs;
if (subs !== undefined) {
notify(subs.sub);
}
else {
queuedEffects[queuedEffectsLength++] = e;
}
}
}
function run(e, flags) {
if (flags & 16
|| (flags & 32 && checkDirty(e.deps, e))) {
const prev = setCurrentSub(e);
startTracking(e);
try {
e.fn();
}
finally {
setCurrentSub(prev);
endTracking(e);
}
return;
}
else if (flags & 32) {
e.flags = flags & ~32;
}
let link = e.deps;
while (link !== undefined) {
const dep = link.dep;
const depFlags = dep.flags;
if (depFlags & 64) {
run(dep, dep.flags = depFlags & ~64);
}
link = link.nextDep;
}
}
function flush() {
while (notifyIndex < queuedEffectsLength) {
const effect = queuedEffects[notifyIndex];
queuedEffects[notifyIndex++] = undefined;
run(effect, effect.flags &= ~64);
}
notifyIndex = 0;
queuedEffectsLength = 0;
}
function computedOper() {
const flags = this.flags;
if (flags & 16
|| (flags & 32 && checkDirty(this.deps, this))) {
if (updateComputed(this)) {
const subs = this.subs;
if (subs !== undefined) {
shallowPropagate(subs);
}
}
}
else if (flags & 32) {
this.flags = flags & ~32;
}
if (activeSub !== undefined) {
link(this, activeSub);
}
else if (activeScope !== undefined) {
link(this, activeScope);
}
return this.value;
}
function signalOper(...value) {
if (value.length) {
const newValue = value[0];
if (this.value !== (this.value = newValue)) {
this.flags = 17;
const subs = this.subs;
if (subs !== undefined) {
propagate(subs);
if (!batchDepth) {
flush();
}
}
}
}
else {
const value = this.value;
if (this.flags & 16) {
if (updateSignal(this, value)) {
const subs = this.subs;
if (subs !== undefined) {
shallowPropagate(subs);
}
}
}
if (activeSub !== undefined) {
link(this, activeSub);
}
return value;
}
}
function effectOper() {
let dep = this.deps;
while (dep !== undefined) {
dep = unlink(dep, this);
}
const sub = this.subs;
if (sub !== undefined) {
unlink(sub);
}
this.flags = 0;
}

260
node_modules/alien-signals/esm/system.mjs generated vendored Normal file
View File

@@ -0,0 +1,260 @@
export var ReactiveFlags;
(function (ReactiveFlags) {
ReactiveFlags[ReactiveFlags["None"] = 0] = "None";
ReactiveFlags[ReactiveFlags["Mutable"] = 1] = "Mutable";
ReactiveFlags[ReactiveFlags["Watching"] = 2] = "Watching";
ReactiveFlags[ReactiveFlags["RecursedCheck"] = 4] = "RecursedCheck";
ReactiveFlags[ReactiveFlags["Recursed"] = 8] = "Recursed";
ReactiveFlags[ReactiveFlags["Dirty"] = 16] = "Dirty";
ReactiveFlags[ReactiveFlags["Pending"] = 32] = "Pending";
})(ReactiveFlags || (ReactiveFlags = {}));
export function createReactiveSystem({ update, notify, unwatched, }) {
let version = 0;
return {
link,
unlink,
propagate,
checkDirty,
endTracking,
startTracking,
shallowPropagate,
};
function link(dep, sub) {
const prevDep = sub.depsTail;
if (prevDep !== undefined && prevDep.dep === dep) {
return;
}
let nextDep;
if (sub.flags & 4) {
nextDep = prevDep !== undefined ? prevDep.nextDep : sub.deps;
if (nextDep !== undefined && nextDep.dep === dep) {
nextDep.version = version;
sub.depsTail = nextDep;
return;
}
}
const prevSub = dep.subsTail;
if (prevSub !== undefined && prevSub.version === version && prevSub.sub === sub) {
return;
}
const newLink = sub.depsTail
= dep.subsTail
= {
version,
dep,
sub,
prevDep,
nextDep,
prevSub,
nextSub: undefined,
};
if (nextDep !== undefined) {
nextDep.prevDep = newLink;
}
if (prevDep !== undefined) {
prevDep.nextDep = newLink;
}
else {
sub.deps = newLink;
}
if (prevSub !== undefined) {
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 !== undefined) {
nextDep.prevDep = prevDep;
}
else {
sub.depsTail = prevDep;
}
if (prevDep !== undefined) {
prevDep.nextDep = nextDep;
}
else {
sub.deps = nextDep;
}
if (nextSub !== undefined) {
nextSub.prevSub = prevSub;
}
else {
dep.subsTail = prevSub;
}
if (prevSub !== undefined) {
prevSub.nextSub = nextSub;
}
else if ((dep.subs = nextSub) === undefined) {
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 & 3) {
if (!(flags & 60)) {
sub.flags = flags | 32;
}
else if (!(flags & 12)) {
flags = 0;
}
else if (!(flags & 4)) {
sub.flags = (flags & ~8) | 32;
}
else if (!(flags & 48) && isValidLink(link, sub)) {
sub.flags = flags | 40;
flags &= 1;
}
else {
flags = 0;
}
if (flags & 2) {
notify(sub);
}
if (flags & 1) {
const subSubs = sub.subs;
if (subSubs !== undefined) {
link = subSubs;
if (subSubs.nextSub !== undefined) {
stack = { value: next, prev: stack };
next = link.nextSub;
}
continue;
}
}
}
if ((link = next) !== undefined) {
next = link.nextSub;
continue;
}
while (stack !== undefined) {
link = stack.value;
stack = stack.prev;
if (link !== undefined) {
next = link.nextSub;
continue top;
}
}
break;
} while (true);
}
function startTracking(sub) {
++version;
sub.depsTail = undefined;
sub.flags = (sub.flags & ~56) | 4;
}
function endTracking(sub) {
const depsTail = sub.depsTail;
let toRemove = depsTail !== undefined ? depsTail.nextDep : sub.deps;
while (toRemove !== undefined) {
toRemove = unlink(toRemove, sub);
}
sub.flags &= ~4;
}
function checkDirty(link, sub) {
let stack;
let checkDepth = 0;
top: do {
const dep = link.dep;
const depFlags = dep.flags;
let dirty = false;
if (sub.flags & 16) {
dirty = true;
}
else if ((depFlags & 17) === 17) {
if (update(dep)) {
const subs = dep.subs;
if (subs.nextSub !== undefined) {
shallowPropagate(subs);
}
dirty = true;
}
}
else if ((depFlags & 33) === 33) {
if (link.nextSub !== undefined || link.prevSub !== undefined) {
stack = { value: link, prev: stack };
}
link = dep.deps;
sub = dep;
++checkDepth;
continue;
}
if (!dirty && link.nextDep !== undefined) {
link = link.nextDep;
continue;
}
while (checkDepth) {
--checkDepth;
const firstSub = sub.subs;
const hasMultipleSubs = firstSub.nextSub !== undefined;
if (hasMultipleSubs) {
link = stack.value;
stack = stack.prev;
}
else {
link = firstSub;
}
if (dirty) {
if (update(sub)) {
if (hasMultipleSubs) {
shallowPropagate(firstSub);
}
sub = link.sub;
continue;
}
}
else {
sub.flags &= ~32;
}
sub = link.sub;
if (link.nextDep !== undefined) {
link = link.nextDep;
continue top;
}
dirty = false;
}
return dirty;
} while (true);
}
function shallowPropagate(link) {
do {
const sub = link.sub;
const nextSub = link.nextSub;
const subFlags = sub.flags;
if ((subFlags & 48) === 32) {
sub.flags = subFlags | 16;
if (subFlags & 2) {
notify(sub);
}
}
link = nextSub;
} while (link !== undefined);
}
function isValidLink(checkLink, sub) {
const depsTail = sub.depsTail;
if (depsTail !== undefined) {
let link = sub.deps;
do {
if (link === checkLink) {
return true;
}
if (link === depsTail) {
break;
}
link = link.nextDep;
} while (link !== undefined);
}
return false;
}
}

66
node_modules/alien-signals/package.json generated vendored Normal file
View File

@@ -0,0 +1,66 @@
{
"name": "alien-signals",
"version": "2.0.6",
"license": "MIT",
"description": "The lightest signal library.",
"packageManager": "pnpm@9.12.0",
"types": "./types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./esm/index.mjs",
"require": "./cjs/index.cjs"
},
"./cjs": {
"types": "./types/index.d.ts",
"import": "./cjs/index.cjs",
"require": "./cjs/index.cjs"
},
"./esm": {
"types": "./types/index.d.ts",
"import": "./esm/index.mjs",
"require": "./esm/index.mjs"
},
"./system": {
"types": "./types/system.d.ts",
"import": "./esm/system.mjs",
"require": "./cjs/system.cjs"
},
"./cjs/system": {
"types": "./types/system.d.ts",
"import": "./cjs/system.cjs",
"require": "./cjs/system.cjs"
},
"./esm/system": {
"types": "./types/system.d.ts",
"import": "./esm/system.mjs",
"require": "./esm/system.mjs"
}
},
"files": [
"cjs/*.cjs",
"esm/*.mjs",
"types/*.d.ts"
],
"repository": {
"type": "git",
"url": "git+https://github.com/johnsoncodehk/signals.git"
},
"scripts": {
"prepublishOnly": "npm run check && npm run test",
"check": "tsc --noEmit",
"build": "node ./build.js",
"test": "npm run build && vitest run",
"lint": "tsslint --project tsconfig.json",
"bench": "npm run build && node --jitless --expose-gc benchs/propagate.mjs",
"memory": "npm run build && node --expose-gc benchs/memoryUsage.mjs"
},
"devDependencies": {
"@tsslint/cli": "latest",
"@tsslint/config": "latest",
"mitata": "latest",
"typescript": "latest",
"vitest": "latest",
"jest-extended": "latest"
}
}

30
node_modules/alien-signals/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,30 @@
export * from './system.js';
import { type ReactiveNode } from './system.js';
interface EffectScope extends ReactiveNode {
}
export declare let batchDepth: number;
export declare function getCurrentSub(): ReactiveNode | undefined;
export declare function setCurrentSub(sub: ReactiveNode | undefined): ReactiveNode | undefined;
export declare function getCurrentScope(): EffectScope | undefined;
export declare function setCurrentScope(scope: EffectScope | undefined): EffectScope | undefined;
export declare function startBatch(): void;
export declare function endBatch(): void;
/**
* @deprecated Will be removed in the next major version. Use `const pausedSub = setCurrentSub(undefined)` instead for better performance.
*/
export declare function pauseTracking(): void;
/**
* @deprecated Will be removed in the next major version. Use `setCurrentSub(pausedSub)` instead for better performance.
*/
export declare function resumeTracking(): void;
export declare function signal<T>(): {
(): T | undefined;
(value: T | undefined): void;
};
export declare function signal<T>(initialValue: T): {
(): T;
(value: T): void;
};
export declare function computed<T>(getter: (previousValue?: T) => T): () => T;
export declare function effect(fn: () => void): () => void;
export declare function effectScope(fn: () => void): () => void;

38
node_modules/alien-signals/types/system.d.ts generated vendored Normal file
View File

@@ -0,0 +1,38 @@
export interface ReactiveNode {
deps?: Link;
depsTail?: Link;
subs?: Link;
subsTail?: Link;
flags: ReactiveFlags;
}
export interface Link {
version: number;
dep: ReactiveNode;
sub: ReactiveNode;
prevSub: Link | undefined;
nextSub: Link | undefined;
prevDep: Link | undefined;
nextDep: Link | undefined;
}
export declare enum ReactiveFlags {
None = 0,
Mutable = 1,
Watching = 2,
RecursedCheck = 4,
Recursed = 8,
Dirty = 16,
Pending = 32
}
export declare function createReactiveSystem({ update, notify, unwatched, }: {
update(sub: ReactiveNode): boolean;
notify(sub: ReactiveNode): void;
unwatched(sub: ReactiveNode): void;
}): {
link: (dep: ReactiveNode, sub: ReactiveNode) => void;
unlink: (link: Link, sub?: ReactiveNode) => Link | undefined;
propagate: (link: Link) => void;
checkDirty: (link: Link, sub: ReactiveNode) => boolean;
endTracking: (sub: ReactiveNode) => void;
startTracking: (sub: ReactiveNode) => void;
shallowPropagate: (link: Link) => void;
};