q9
This commit is contained in:
2
node_modules/alien-signals/cjs/unstable/computedArray.d.ts
generated
vendored
Normal file
2
node_modules/alien-signals/cjs/unstable/computedArray.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { ISignal } from '../index.js';
|
||||
export declare function computedArray<I, O>(arr: ISignal<I[]>, getGetter: (item: ISignal<I>, index: number) => () => O): readonly Readonly<O>[];
|
||||
43
node_modules/alien-signals/cjs/unstable/computedArray.js
generated
vendored
Normal file
43
node_modules/alien-signals/cjs/unstable/computedArray.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.computedArray = computedArray;
|
||||
const index_js_1 = require("../index.js");
|
||||
function computedArray(arr, getGetter) {
|
||||
const length = (0, index_js_1.computed)(() => arr.get().length);
|
||||
const keys = (0, index_js_1.computed)(() => {
|
||||
const keys = [];
|
||||
for (let i = 0; i < length.get(); i++) {
|
||||
keys.push(String(i));
|
||||
}
|
||||
return keys;
|
||||
});
|
||||
const items = (0, index_js_1.computed)((array) => {
|
||||
array ??= [];
|
||||
while (array.length < length.get()) {
|
||||
const index = array.length;
|
||||
const item = (0, index_js_1.computed)(() => arr.get()[index]);
|
||||
array.push((0, index_js_1.computed)(getGetter(item, index)));
|
||||
}
|
||||
if (array.length > length.get()) {
|
||||
array.length = length.get();
|
||||
}
|
||||
return array;
|
||||
});
|
||||
return new Proxy({}, {
|
||||
get(_, p, receiver) {
|
||||
if (p === 'length') {
|
||||
return length.get();
|
||||
}
|
||||
if (typeof p === 'string' && !isNaN(Number(p))) {
|
||||
return items.get()[Number(p)]?.get();
|
||||
}
|
||||
return Reflect.get(items.get(), p, receiver);
|
||||
},
|
||||
has(_, p) {
|
||||
return Reflect.has(items.get(), p);
|
||||
},
|
||||
ownKeys() {
|
||||
return keys.get();
|
||||
},
|
||||
});
|
||||
}
|
||||
2
node_modules/alien-signals/cjs/unstable/computedSet.d.ts
generated
vendored
Normal file
2
node_modules/alien-signals/cjs/unstable/computedSet.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { ISignal } from '../index.js';
|
||||
export declare function computedSet<T>(source: ISignal<Set<T>>): ISignal<Set<T>>;
|
||||
13
node_modules/alien-signals/cjs/unstable/computedSet.js
generated
vendored
Normal file
13
node_modules/alien-signals/cjs/unstable/computedSet.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.computedSet = computedSet;
|
||||
const index_js_1 = require("../index.js");
|
||||
function computedSet(source) {
|
||||
return (0, index_js_1.computed)((oldValue) => {
|
||||
const newValue = source.get();
|
||||
if (oldValue?.size === newValue.size && [...oldValue].every(c => newValue.has(c))) {
|
||||
return oldValue;
|
||||
}
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
6
node_modules/alien-signals/cjs/unstable/equalityComputed.d.ts
generated
vendored
Normal file
6
node_modules/alien-signals/cjs/unstable/equalityComputed.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Computed, ISignal } from '../index.js';
|
||||
export declare function equalityComputed<T>(getter: () => T): ISignal<T>;
|
||||
export declare class EqualityComputed<T = any> extends Computed<T> {
|
||||
constructor(getter: () => T);
|
||||
equals(a: any, b: any): boolean;
|
||||
}
|
||||
58
node_modules/alien-signals/cjs/unstable/equalityComputed.js
generated
vendored
Normal file
58
node_modules/alien-signals/cjs/unstable/equalityComputed.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EqualityComputed = void 0;
|
||||
exports.equalityComputed = equalityComputed;
|
||||
const index_js_1 = require("../index.js");
|
||||
function equalityComputed(getter) {
|
||||
return new EqualityComputed(getter);
|
||||
}
|
||||
class EqualityComputed extends index_js_1.Computed {
|
||||
constructor(getter) {
|
||||
super(oldValue => {
|
||||
const newValue = getter();
|
||||
if (this.equals(oldValue, newValue)) {
|
||||
return oldValue;
|
||||
}
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
equals(a, b) {
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (a === null || b === null || typeof a !== typeof b) {
|
||||
return false;
|
||||
}
|
||||
if (typeof a === 'object') {
|
||||
if (Array.isArray(a) && Array.isArray(b)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!this.equals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!Array.isArray(a) && !Array.isArray(b)) {
|
||||
for (const key in a) {
|
||||
if (a.hasOwnProperty(key)) {
|
||||
if (!b.hasOwnProperty(key) || !this.equals(a[key], b[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const key in b) {
|
||||
if (b.hasOwnProperty(key) && !a.hasOwnProperty(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false; // One is array and the other is not
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.EqualityComputed = EqualityComputed;
|
||||
4
node_modules/alien-signals/cjs/unstable/index.d.ts
generated
vendored
Normal file
4
node_modules/alien-signals/cjs/unstable/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './computedArray.js';
|
||||
export * from './computedSet.js';
|
||||
export * from './equalityComputed.js';
|
||||
export * as Vue from './vue.js';
|
||||
21
node_modules/alien-signals/cjs/unstable/index.js
generated
vendored
Normal file
21
node_modules/alien-signals/cjs/unstable/index.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"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.Vue = void 0;
|
||||
__exportStar(require("./computedArray.js"), exports);
|
||||
__exportStar(require("./computedSet.js"), exports);
|
||||
__exportStar(require("./equalityComputed.js"), exports);
|
||||
exports.Vue = require("./vue.js");
|
||||
34
node_modules/alien-signals/cjs/unstable/vue.d.ts
generated
vendored
Normal file
34
node_modules/alien-signals/cjs/unstable/vue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Effect, EffectScope, Signal } from '../index.js';
|
||||
export { EffectScope };
|
||||
export declare function effect(fn: () => void): ReactiveEffect;
|
||||
declare class VueEffectScope extends EffectScope {
|
||||
onDispose: (() => void)[];
|
||||
run<T>(fn: () => T): T;
|
||||
stop(): void;
|
||||
}
|
||||
export declare function effectScope(): VueEffectScope;
|
||||
export declare function triggerRef(ref: ShallowRef): void;
|
||||
export declare function pauseTracking(): void;
|
||||
export declare function resetTracking(): void;
|
||||
export declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
|
||||
export declare function shallowRef<T = any>(oldValue: T): ShallowRef<T>;
|
||||
export declare function computed<T>(options: {
|
||||
get(): T;
|
||||
set(value: T): void;
|
||||
}): {
|
||||
value: T;
|
||||
};
|
||||
export declare function computed<T>(fn: () => T): {
|
||||
readonly value: T;
|
||||
};
|
||||
export declare function getCurrentScope(): VueEffectScope | undefined;
|
||||
export declare class ShallowRef<T = any> extends Signal<T> {
|
||||
get value(): T;
|
||||
set value(value: T);
|
||||
}
|
||||
export declare class ReactiveEffect extends Effect {
|
||||
get dirty(): boolean;
|
||||
set scheduler(fn: () => void);
|
||||
stop(): void;
|
||||
}
|
||||
export declare function onScopeDispose(cb: () => void): void;
|
||||
118
node_modules/alien-signals/cjs/unstable/vue.js
generated
vendored
Normal file
118
node_modules/alien-signals/cjs/unstable/vue.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ReactiveEffect = exports.ShallowRef = exports.EffectScope = void 0;
|
||||
exports.effect = effect;
|
||||
exports.effectScope = effectScope;
|
||||
exports.triggerRef = triggerRef;
|
||||
exports.pauseTracking = pauseTracking;
|
||||
exports.resetTracking = resetTracking;
|
||||
exports.shallowRef = shallowRef;
|
||||
exports.computed = computed;
|
||||
exports.getCurrentScope = getCurrentScope;
|
||||
exports.onScopeDispose = onScopeDispose;
|
||||
const index_js_1 = require("../index.js");
|
||||
Object.defineProperty(exports, "EffectScope", { enumerable: true, get: function () { return index_js_1.EffectScope; } });
|
||||
function effect(fn) {
|
||||
const e = new ReactiveEffect(fn);
|
||||
e.run();
|
||||
return e;
|
||||
}
|
||||
let currentEffectScope = undefined;
|
||||
class VueEffectScope extends index_js_1.EffectScope {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.onDispose = [];
|
||||
}
|
||||
run(fn) {
|
||||
const prevScope = currentEffectScope;
|
||||
currentEffectScope = this;
|
||||
const res = super.run(fn);
|
||||
currentEffectScope = prevScope;
|
||||
return res;
|
||||
}
|
||||
stop() {
|
||||
super.stop();
|
||||
this.onDispose.forEach(cb => cb());
|
||||
}
|
||||
}
|
||||
function effectScope() {
|
||||
return new VueEffectScope();
|
||||
}
|
||||
function triggerRef(ref) {
|
||||
if (ref.subs !== undefined) {
|
||||
(0, index_js_1.startBatch)();
|
||||
index_js_1.Dependency.propagate(ref.subs);
|
||||
(0, index_js_1.endBatch)();
|
||||
}
|
||||
}
|
||||
const pausedSubs = [];
|
||||
function pauseTracking() {
|
||||
pausedSubs.push(index_js_1.System.activeSub);
|
||||
index_js_1.System.activeSub = undefined;
|
||||
index_js_1.System.activeTrackId = -1;
|
||||
}
|
||||
function resetTracking() {
|
||||
const prevSub = pausedSubs.pop();
|
||||
index_js_1.System.activeSub = prevSub;
|
||||
index_js_1.System.activeTrackId = prevSub.trackId;
|
||||
}
|
||||
function shallowRef(value) {
|
||||
return new ShallowRef(value);
|
||||
}
|
||||
function computed(fn) {
|
||||
if (typeof fn === 'function') {
|
||||
return new VueComputed(fn);
|
||||
}
|
||||
else {
|
||||
const { get, set } = fn;
|
||||
const c = new VueComputed(get);
|
||||
return {
|
||||
get value() {
|
||||
return c.get();
|
||||
},
|
||||
set value(value) {
|
||||
set(value);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
function getCurrentScope() {
|
||||
return currentEffectScope;
|
||||
}
|
||||
class ShallowRef extends index_js_1.Signal {
|
||||
get value() {
|
||||
return this.get();
|
||||
}
|
||||
set value(value) {
|
||||
this.set(value);
|
||||
}
|
||||
}
|
||||
exports.ShallowRef = ShallowRef;
|
||||
class VueComputed extends index_js_1.Computed {
|
||||
get value() {
|
||||
return this.get();
|
||||
}
|
||||
}
|
||||
class ReactiveEffect extends index_js_1.Effect {
|
||||
get dirty() {
|
||||
if (this.dirtyLevel === 2 /* DirtyLevels.MaybeDirty */) {
|
||||
index_js_1.Subscriber.resolveMaybeDirty(this);
|
||||
}
|
||||
return this.dirtyLevel === 3 /* DirtyLevels.Dirty */;
|
||||
}
|
||||
set scheduler(fn) {
|
||||
this.notify = fn;
|
||||
}
|
||||
stop() {
|
||||
if (this.deps !== undefined) {
|
||||
index_js_1.Subscriber.clearTrack(this.deps);
|
||||
this.deps = undefined;
|
||||
this.depsTail = undefined;
|
||||
}
|
||||
this.dirtyLevel = 0 /* DirtyLevels.None */;
|
||||
}
|
||||
}
|
||||
exports.ReactiveEffect = ReactiveEffect;
|
||||
function onScopeDispose(cb) {
|
||||
currentEffectScope?.onDispose.push(cb);
|
||||
}
|
||||
Reference in New Issue
Block a user