alien-signals
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,6 +0,6 @@ | ||
export * from './lib/computed'; | ||
export * from './lib/effect'; | ||
export * from './lib/effectScope'; | ||
export * from './lib/signal'; | ||
export * from './lib/system'; | ||
export * from './lib/computed.js'; | ||
export * from './lib/effect.js'; | ||
export * from './lib/effectScope.js'; | ||
export * from './lib/signal.js'; | ||
export * from './lib/system.js'; | ||
export declare function enableEffectsPropagation(): void; |
33
index.js
@@ -1,26 +0,9 @@ | ||
"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.enableEffectsPropagation = enableEffectsPropagation; | ||
const system_1 = require("./lib/system"); | ||
__exportStar(require("./lib/computed"), exports); | ||
__exportStar(require("./lib/effect"), exports); | ||
__exportStar(require("./lib/effectScope"), exports); | ||
__exportStar(require("./lib/signal"), exports); | ||
__exportStar(require("./lib/system"), exports); | ||
function enableEffectsPropagation() { | ||
system_1.Dependency.propagate = system_1.Dependency.effectsPropagate; | ||
import { Dependency } from './lib/system.js'; | ||
export * from './lib/computed.js'; | ||
export * from './lib/effect.js'; | ||
export * from './lib/effectScope.js'; | ||
export * from './lib/signal.js'; | ||
export * from './lib/system.js'; | ||
export function enableEffectsPropagation() { | ||
Dependency.propagate = Dependency.effectsPropagate; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Dependency, DirtyLevels, Subscriber } from './system'; | ||
import { Dependency, DirtyLevels, Subscriber } from './system.js'; | ||
export declare function computed<T>(getter: (cachedValue?: T) => T): Computed<T>; | ||
@@ -13,5 +13,4 @@ export declare class Computed<T = any> implements Dependency, Subscriber { | ||
constructor(getter: (cachedValue?: T) => T); | ||
notifyLostSubs(): void; | ||
get(): T; | ||
update(): T; | ||
} |
@@ -1,10 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Computed = void 0; | ||
exports.computed = computed; | ||
const system_1 = require("./system"); | ||
function computed(getter) { | ||
import { Dependency, Subscriber } from './system.js'; | ||
export function computed(getter) { | ||
return new Computed(getter); | ||
} | ||
class Computed { | ||
export class Computed { | ||
constructor(getter) { | ||
@@ -22,11 +18,7 @@ this.getter = getter; | ||
} | ||
notifyLostSubs() { | ||
system_1.Subscriber.clearTrack(this); | ||
this.versionOrDirtyLevel = 3 /* DirtyLevels.Dirty */; | ||
} | ||
get() { | ||
system_1.Dependency.linkSubOnly(this); | ||
Dependency.linkDepsSub(this); | ||
const dirtyLevel = this.versionOrDirtyLevel; | ||
if (dirtyLevel === 2 /* DirtyLevels.MaybeDirty */) { | ||
system_1.Subscriber.resolveMaybeDirty(this); | ||
Subscriber.resolveMaybeDirty(this); | ||
if (this.versionOrDirtyLevel === 3 /* DirtyLevels.Dirty */) { | ||
@@ -36,3 +28,3 @@ return this.update(); | ||
} | ||
else if (dirtyLevel === 3 /* DirtyLevels.Dirty */) { | ||
else if (dirtyLevel >= 3 /* DirtyLevels.Dirty */) { | ||
return this.update(); | ||
@@ -43,9 +35,9 @@ } | ||
update() { | ||
const prevSub = system_1.Subscriber.startTrack(this); | ||
const prevSub = Subscriber.startTrackDeps(this); | ||
const oldValue = this.cachedValue; | ||
const newValue = this.getter(oldValue); | ||
system_1.Subscriber.endTrack(this, prevSub); | ||
Subscriber.endTrackDeps(this, prevSub); | ||
if (oldValue !== newValue) { | ||
this.cachedValue = newValue; | ||
system_1.Dependency.propagate(this); | ||
Dependency.propagate(this); | ||
} | ||
@@ -55,2 +47,1 @@ return newValue; | ||
} | ||
exports.Computed = Computed; |
@@ -1,2 +0,2 @@ | ||
import { Dependency, DirtyLevels, IEffect, Subscriber } from './system'; | ||
import { Dependency, DirtyLevels, IEffect, Subscriber } from './system.js'; | ||
export declare function effect(fn: () => void): Effect; | ||
@@ -13,5 +13,4 @@ export declare class Effect implements IEffect, Dependency, Subscriber { | ||
constructor(fn: () => void); | ||
notifyLostSubs(): void; | ||
notify(): void; | ||
run(): void; | ||
} |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Effect = void 0; | ||
exports.effect = effect; | ||
const system_1 = require("./system"); | ||
function effect(fn) { | ||
import { Dependency, Subscriber } from './system.js'; | ||
export function effect(fn) { | ||
const e = new Effect(fn); | ||
@@ -11,3 +7,3 @@ e.run(); | ||
} | ||
class Effect { | ||
export class Effect { | ||
constructor(fn) { | ||
@@ -24,7 +20,6 @@ this.fn = fn; | ||
this.versionOrDirtyLevel = 3 /* DirtyLevels.Dirty */; | ||
system_1.Dependency.link(this); | ||
if (!Dependency.linkDepsSub(this)) { | ||
Dependency.linkEffectsSub(this); | ||
} | ||
} | ||
notifyLostSubs() { | ||
system_1.Subscriber.clearTrack(this); | ||
} | ||
notify() { | ||
@@ -34,7 +29,7 @@ const dirtyLevel = this.versionOrDirtyLevel; | ||
this.versionOrDirtyLevel = 0 /* DirtyLevels.None */; | ||
system_1.Subscriber.runInnerEffects(this); | ||
Subscriber.runInnerEffects(this); | ||
} | ||
else { | ||
if (dirtyLevel === 2 /* DirtyLevels.MaybeDirty */) { | ||
system_1.Subscriber.resolveMaybeDirty(this); | ||
Subscriber.resolveMaybeDirty(this); | ||
} | ||
@@ -45,3 +40,3 @@ if (this.versionOrDirtyLevel === 3 /* DirtyLevels.Dirty */) { | ||
else { | ||
system_1.Subscriber.runInnerEffects(this); | ||
Subscriber.runInnerEffects(this); | ||
} | ||
@@ -51,7 +46,6 @@ } | ||
run() { | ||
const prevSub = system_1.Subscriber.startTrack(this); | ||
const prevSub = Subscriber.startTrackDeps(this); | ||
this.fn(); | ||
system_1.Subscriber.endTrack(this, prevSub); | ||
Subscriber.endTrackDeps(this, prevSub); | ||
} | ||
} | ||
exports.Effect = Effect; |
@@ -1,2 +0,2 @@ | ||
import { DirtyLevels, IEffect, Subscriber } from './system'; | ||
import { DirtyLevels, IEffect, Subscriber } from './system.js'; | ||
export declare function effectScope(): EffectScope; | ||
@@ -3,0 +3,0 @@ export declare class EffectScope implements IEffect, Subscriber { |
@@ -1,10 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EffectScope = void 0; | ||
exports.effectScope = effectScope; | ||
const system_1 = require("./system"); | ||
function effectScope() { | ||
import { Subscriber } from './system.js'; | ||
export function effectScope() { | ||
return new EffectScope(); | ||
} | ||
class EffectScope { | ||
export class EffectScope { | ||
constructor() { | ||
@@ -20,15 +16,19 @@ this.nextNotify = undefined; | ||
this.versionOrDirtyLevel = 0 /* DirtyLevels.None */; | ||
system_1.Subscriber.runInnerEffects(this); | ||
Subscriber.runInnerEffects(this); | ||
} | ||
} | ||
run(fn) { | ||
const prevActiveSub = system_1.Subscriber.startTrack(this, true); | ||
const prevActiveSub = Subscriber.startTrackEffects(this); | ||
const res = fn(); | ||
system_1.Subscriber.endTrack(this, prevActiveSub); | ||
Subscriber.endTrackEffects(this, prevActiveSub); | ||
return res; | ||
} | ||
stop() { | ||
system_1.Subscriber.clearTrack(this); | ||
if (this.deps !== undefined) { | ||
Subscriber.clearTrack(this.deps); | ||
this.deps = undefined; | ||
this.depsTail = undefined; | ||
} | ||
this.versionOrDirtyLevel = 0 /* DirtyLevels.None */; | ||
} | ||
} | ||
exports.EffectScope = EffectScope; |
@@ -1,2 +0,2 @@ | ||
import { Dependency } from './system'; | ||
import { Dependency } from './system.js'; | ||
export declare function signal<T>(): Signal<T | undefined>; | ||
@@ -3,0 +3,0 @@ export declare function signal<T>(oldValue: T): Signal<T>; |
@@ -1,10 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Signal = void 0; | ||
exports.signal = signal; | ||
const system_1 = require("./system"); | ||
function signal(oldValue) { | ||
import { System, Dependency } from './system.js'; | ||
export function signal(oldValue) { | ||
return new Signal(oldValue); | ||
} | ||
class Signal { | ||
export class Signal { | ||
constructor(currentValue) { | ||
@@ -18,3 +14,3 @@ this.currentValue = currentValue; | ||
get() { | ||
system_1.Dependency.linkSubOnly(this); | ||
Dependency.linkDepsSub(this); | ||
return this.currentValue; | ||
@@ -24,8 +20,7 @@ } | ||
if (this.currentValue !== (this.currentValue = value)) { | ||
system_1.System.startBatch(); | ||
system_1.Dependency.propagate(this); | ||
system_1.System.endBatch(); | ||
System.startBatch(); | ||
Dependency.propagate(this); | ||
System.endBatch(); | ||
} | ||
} | ||
} | ||
exports.Signal = Signal; |
@@ -9,3 +9,2 @@ export interface IEffect { | ||
subVersion: number; | ||
notifyLostSubs?(): void; | ||
update?(): void; | ||
@@ -36,8 +35,10 @@ } | ||
MaybeDirty = 2, | ||
Dirty = 3 | ||
Dirty = 3, | ||
Released = 4 | ||
} | ||
export declare namespace System { | ||
let activeSub: Subscriber | undefined; | ||
let activeSubsDepth: number; | ||
let activeSubIsScopeOrNothing: boolean; | ||
let activeDepsSub: Subscriber | undefined; | ||
let activeEffectsSub: Subscriber | undefined; | ||
let activeDepsSubsDepth: number; | ||
let activeEffectsSubsDepth: number; | ||
let batchDepth: number; | ||
@@ -51,10 +52,9 @@ let lastSubVersion: number; | ||
export declare namespace Link { | ||
let pool: Link | undefined; | ||
function get(dep: Dependency, sub: Subscriber): Link; | ||
function releaseDeps(toBreak: Link): void; | ||
function release(link: Link): void; | ||
} | ||
export declare namespace Dependency { | ||
let propagate: typeof fastPropagate; | ||
function linkSubOnly(dep: Dependency): void; | ||
function link(dep: Dependency): void; | ||
function linkDepsSub(dep: Dependency): boolean; | ||
function linkEffectsSub(dep: Dependency): boolean; | ||
function effectsPropagate(dep: Dependency): void; | ||
@@ -66,5 +66,7 @@ function fastPropagate(dep: Dependency): void; | ||
function resolveMaybeDirty(sub: Subscriber): void; | ||
function startTrack(sub: Subscriber, isScope?: boolean): Subscriber | undefined; | ||
function endTrack(sub: Subscriber, prevSub: Subscriber | undefined): void; | ||
function clearTrack(sub: Subscriber): void; | ||
function startTrackDeps(sub: Subscriber): Subscriber | undefined; | ||
function endTrackDeps(sub: Subscriber, prevSub: Subscriber | undefined): void; | ||
function clearTrack(link: Link | undefined): void; | ||
function startTrackEffects(sub: Subscriber): Subscriber | undefined; | ||
function endTrackEffects(sub: Subscriber, prevSub: Subscriber | undefined): void; | ||
} |
@@ -1,11 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Subscriber = exports.Dependency = exports.Link = exports.System = void 0; | ||
var System; | ||
export var System; | ||
(function (System) { | ||
System.activeSub = undefined; | ||
System.activeSubsDepth = 0; | ||
System.activeSubIsScopeOrNothing = true; | ||
System.activeDepsSub = undefined; | ||
System.activeEffectsSub = undefined; | ||
System.activeDepsSubsDepth = 0; | ||
System.activeEffectsSubsDepth = 0; | ||
System.batchDepth = 0; | ||
System.lastSubVersion = 3 /* DirtyLevels.Dirty */ + 1; | ||
System.lastSubVersion = 4 /* DirtyLevels.Released */ + 1; | ||
System.queuedEffects = undefined; | ||
@@ -34,10 +32,10 @@ System.queuedEffectsTail = undefined; | ||
System.endBatch = endBatch; | ||
})(System || (exports.System = System = {})); | ||
var Link; | ||
})(System || (System = {})); | ||
export var Link; | ||
(function (Link) { | ||
let pool = undefined; | ||
Link.pool = undefined; | ||
function get(dep, sub) { | ||
if (pool !== undefined) { | ||
const link = pool; | ||
pool = link.queuedPropagateOrNextReleased; | ||
if (Link.pool !== undefined) { | ||
const link = Link.pool; | ||
Link.pool = link.queuedPropagateOrNextReleased; | ||
link.queuedPropagateOrNextReleased = undefined; | ||
@@ -60,57 +58,15 @@ link.dep = dep; | ||
Link.get = get; | ||
function releaseDeps(toBreak) { | ||
let nextDep = toBreak.nextDep; | ||
while (nextDep !== undefined) { | ||
toBreak.nextDep = undefined; | ||
const nextNext = nextDep.nextDep; | ||
Link.release(nextDep); | ||
toBreak = nextDep; | ||
nextDep = nextNext; | ||
} | ||
} | ||
Link.releaseDeps = releaseDeps; | ||
function release(link) { | ||
const dep = link.dep; | ||
const nextSub = link.nextSub; | ||
const prevSub = link.prevSubOrUpdate; | ||
if (nextSub !== undefined) { | ||
nextSub.prevSubOrUpdate = prevSub; | ||
} | ||
if (prevSub !== undefined) { | ||
prevSub.nextSub = nextSub; | ||
} | ||
if (nextSub === undefined) { | ||
link.dep.subsTail = prevSub; | ||
} | ||
if (prevSub === undefined) { | ||
link.dep.subs = nextSub; | ||
} | ||
// @ts-ignore | ||
link.dep = undefined; | ||
// @ts-ignore | ||
link.sub = undefined; | ||
link.prevSubOrUpdate = undefined; | ||
link.nextSub = undefined; | ||
link.nextDep = undefined; | ||
link.queuedPropagateOrNextReleased = pool; | ||
pool = link; | ||
if (dep.subs === undefined && 'notifyLostSubs' in dep) { | ||
dep.notifyLostSubs(); | ||
} | ||
} | ||
Link.release = release; | ||
})(Link || (exports.Link = Link = {})); | ||
var Dependency; | ||
})(Link || (Link = {})); | ||
export var Dependency; | ||
(function (Dependency) { | ||
const system = System; | ||
Dependency.propagate = fastPropagate; | ||
// TODO: remove duplication | ||
function linkSubOnly(dep) { | ||
if (system.activeSubIsScopeOrNothing) { | ||
return; | ||
function linkDepsSub(dep) { | ||
if (system.activeDepsSubsDepth === 0) { | ||
return false; | ||
} | ||
const sub = system.activeSub; | ||
const sub = system.activeDepsSub; | ||
const subVersion = sub.versionOrDirtyLevel; | ||
if (dep.subVersion === subVersion) { | ||
return; | ||
return true; | ||
} | ||
@@ -147,12 +103,13 @@ dep.subVersion = subVersion; | ||
} | ||
return true; | ||
} | ||
Dependency.linkSubOnly = linkSubOnly; | ||
function link(dep) { | ||
if (system.activeSubsDepth === 0) { | ||
return; | ||
Dependency.linkDepsSub = linkDepsSub; | ||
function linkEffectsSub(dep) { | ||
if (system.activeEffectsSubsDepth === 0) { | ||
return false; | ||
} | ||
const sub = system.activeSub; | ||
const sub = system.activeEffectsSub; | ||
const subVersion = sub.versionOrDirtyLevel; | ||
if (dep.subVersion === subVersion) { | ||
return; | ||
return true; | ||
} | ||
@@ -167,5 +124,3 @@ dep.subVersion = subVersion; | ||
if (old !== undefined) { | ||
const nextDep = old.nextDep; | ||
Link.release(old); | ||
newLink.nextDep = nextDep; | ||
newLink.nextDep = old; | ||
} | ||
@@ -192,4 +147,5 @@ if (depsTail === undefined) { | ||
} | ||
return true; | ||
} | ||
Dependency.link = link; | ||
Dependency.linkEffectsSub = linkEffectsSub; | ||
function effectsPropagate(dep) { | ||
@@ -319,4 +275,4 @@ let depIsEffect = false; | ||
Dependency.fastPropagate = fastPropagate; | ||
})(Dependency || (exports.Dependency = Dependency = {})); | ||
var Subscriber; | ||
})(Dependency || (Dependency = {})); | ||
export var Subscriber; | ||
(function (Subscriber) { | ||
@@ -348,3 +304,3 @@ const system = System; | ||
} | ||
else if (depDirtyLevel === 3 /* DirtyLevels.Dirty */ && dep.update !== undefined) { | ||
else if (depDirtyLevel === 3 /* DirtyLevels.Dirty */ && 'update' in dep) { | ||
dep.update(); | ||
@@ -379,49 +335,88 @@ if (sub.versionOrDirtyLevel === 3 /* DirtyLevels.Dirty */) { | ||
Subscriber.resolveMaybeDirty = resolveMaybeDirty; | ||
function startTrack(sub, isScope) { | ||
const prevSub = system.activeSub; | ||
system.activeSub = sub; | ||
system.activeSubsDepth++; | ||
let version = system.lastSubVersion + 1; | ||
if (isScope) { | ||
if (version % 2 === 0) { | ||
version += 1; | ||
} | ||
system.activeSubIsScopeOrNothing = true; | ||
} | ||
else { | ||
if (version % 2 === 1) { | ||
version += 1; | ||
} | ||
system.activeSubIsScopeOrNothing = false; | ||
} | ||
system.lastSubVersion = version; | ||
function startTrackDeps(sub) { | ||
const prevSub = system.activeDepsSub; | ||
system.activeDepsSub = sub; | ||
system.activeDepsSubsDepth++; | ||
sub.depsTail = undefined; | ||
sub.versionOrDirtyLevel = version; | ||
sub.versionOrDirtyLevel = system.lastSubVersion++; | ||
return prevSub; | ||
} | ||
Subscriber.startTrack = startTrack; | ||
function endTrack(sub, prevSub) { | ||
system.activeSubsDepth--; | ||
system.activeSub = prevSub; | ||
if (prevSub !== undefined) { | ||
system.activeSubIsScopeOrNothing = prevSub.versionOrDirtyLevel % 2 === 1; | ||
Subscriber.startTrackDeps = startTrackDeps; | ||
function endTrackDeps(sub, prevSub) { | ||
system.activeDepsSubsDepth--; | ||
system.activeDepsSub = prevSub; | ||
const depsTail = sub.depsTail; | ||
if (depsTail !== undefined) { | ||
if (depsTail.nextDep !== undefined) { | ||
clearTrack(depsTail.nextDep); | ||
depsTail.nextDep = undefined; | ||
} | ||
} | ||
else { | ||
system.activeSubIsScopeOrNothing = true; | ||
else if (sub.deps !== undefined) { | ||
clearTrack(sub.deps); | ||
sub.deps = undefined; | ||
} | ||
postTrack(sub); | ||
sub.versionOrDirtyLevel = 0 /* DirtyLevels.None */; | ||
} | ||
Subscriber.endTrack = endTrack; | ||
function clearTrack(sub) { | ||
Subscriber.endTrackDeps = endTrackDeps; | ||
function clearTrack(link) { | ||
while (link !== undefined) { | ||
const nextDep = link.nextDep; | ||
const dep = link.dep; | ||
const nextSub = link.nextSub; | ||
const prevSub = link.prevSubOrUpdate; | ||
if (nextSub !== undefined) { | ||
nextSub.prevSubOrUpdate = prevSub; | ||
} | ||
if (prevSub !== undefined) { | ||
prevSub.nextSub = nextSub; | ||
} | ||
if (nextSub === undefined) { | ||
link.dep.subsTail = prevSub; | ||
} | ||
if (prevSub === undefined) { | ||
link.dep.subs = nextSub; | ||
} | ||
// @ts-ignore | ||
link.dep = undefined; | ||
// @ts-ignore | ||
link.sub = undefined; | ||
link.prevSubOrUpdate = undefined; | ||
link.nextSub = undefined; | ||
link.nextDep = undefined; | ||
link.queuedPropagateOrNextReleased = Link.pool; | ||
Link.pool = link; | ||
if (dep.subs === undefined && dep.deps !== undefined) { | ||
link = dep.deps; | ||
dep.depsTail.nextDep = nextDep; | ||
dep.deps = undefined; | ||
dep.depsTail = undefined; | ||
dep.versionOrDirtyLevel = 4 /* DirtyLevels.Released */; | ||
continue; | ||
} | ||
link = nextDep; | ||
} | ||
} | ||
Subscriber.clearTrack = clearTrack; | ||
function startTrackEffects(sub) { | ||
const prevSub = system.activeEffectsSub; | ||
system.activeEffectsSub = sub; | ||
system.activeEffectsSubsDepth++; | ||
sub.depsTail = undefined; | ||
postTrack(sub); | ||
sub.versionOrDirtyLevel = system.lastSubVersion++; | ||
return prevSub; | ||
} | ||
Subscriber.clearTrack = clearTrack; | ||
function postTrack(sub) { | ||
if (sub.depsTail !== undefined) { | ||
Link.releaseDeps(sub.depsTail); | ||
Subscriber.startTrackEffects = startTrackEffects; | ||
function endTrackEffects(sub, prevSub) { | ||
system.activeEffectsSubsDepth--; | ||
system.activeEffectsSub = prevSub; | ||
const depsTail = sub.depsTail; | ||
if (depsTail !== undefined) { | ||
if (depsTail.nextDep !== undefined) { | ||
clearTrack(depsTail.nextDep); | ||
depsTail.nextDep = undefined; | ||
} | ||
} | ||
else if (sub.deps !== undefined) { | ||
Link.releaseDeps(sub.deps); | ||
Link.release(sub.deps); | ||
clearTrack(sub.deps); | ||
sub.deps = undefined; | ||
@@ -431,2 +426,3 @@ } | ||
} | ||
})(Subscriber || (exports.Subscriber = Subscriber = {})); | ||
Subscriber.endTrackEffects = endTrackEffects; | ||
})(Subscriber || (Subscriber = {})); |
{ | ||
"name": "alien-signals", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"license": "MIT", | ||
"packageManager": "pnpm@9.12.0", | ||
"type": "module", | ||
"main": "index.js", | ||
"files": [ | ||
@@ -7,0 +9,0 @@ "**/*.js", |
@@ -1,8 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.computedArray = computedArray; | ||
const computed_1 = require("../lib/computed"); | ||
function computedArray(arr, getGetter) { | ||
const length = (0, computed_1.computed)(() => arr.get().length); | ||
const keys = (0, computed_1.computed)(() => { | ||
import { computed } from '../lib/computed'; | ||
export function computedArray(arr, getGetter) { | ||
const length = computed(() => arr.get().length); | ||
const keys = computed(() => { | ||
const keys = []; | ||
@@ -14,8 +11,8 @@ for (let i = 0; i < length.get(); i++) { | ||
}); | ||
const items = (0, computed_1.computed)((array) => { | ||
const items = computed((array) => { | ||
array ??= []; | ||
while (array.length < length.get()) { | ||
const index = array.length; | ||
const item = (0, computed_1.computed)(() => arr.get()[index]); | ||
array.push((0, computed_1.computed)(getGetter(item, index))); | ||
const item = computed(() => arr.get()[index]); | ||
array.push(computed(getGetter(item, index))); | ||
} | ||
@@ -22,0 +19,0 @@ if (array.length > length.get()) { |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.computedSet = computedSet; | ||
const computed_1 = require("../lib/computed"); | ||
function computedSet(getter) { | ||
return (0, computed_1.computed)((oldValue) => { | ||
import { computed } from '../lib/computed'; | ||
export function computedSet(getter) { | ||
return computed((oldValue) => { | ||
const newValue = getter(); | ||
@@ -8,0 +5,0 @@ if (oldValue?.size === newValue.size && [...oldValue].every(c => newValue.has(c))) { |
@@ -1,10 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EqualityComputed = void 0; | ||
exports.equalityComputed = equalityComputed; | ||
const computed_1 = require("../lib/computed"); | ||
function equalityComputed(getter) { | ||
import { Computed } from '../lib/computed'; | ||
export function equalityComputed(getter) { | ||
return new EqualityComputed(getter); | ||
} | ||
class EqualityComputed extends computed_1.Computed { | ||
export class EqualityComputed extends Computed { | ||
constructor(getter) { | ||
@@ -58,2 +54,1 @@ super(oldValue => { | ||
} | ||
exports.EqualityComputed = EqualityComputed; |
@@ -1,20 +0,8 @@ | ||
"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) { | ||
import { Computed, Dependency, Effect, EffectScope, Signal, Subscriber, System, } from '../index.js'; | ||
export { EffectScope }; | ||
export function effect(fn) { | ||
return new ReactiveEffect(fn); | ||
} | ||
let currentEffectScope = undefined; | ||
class VueEffectScope extends index_js_1.EffectScope { | ||
class VueEffectScope extends EffectScope { | ||
constructor() { | ||
@@ -36,28 +24,28 @@ super(...arguments); | ||
} | ||
function effectScope() { | ||
export function effectScope() { | ||
return new VueEffectScope(); | ||
} | ||
function triggerRef(ref) { | ||
index_js_1.System.startBatch(); | ||
index_js_1.Dependency.propagate(ref); | ||
index_js_1.System.endBatch(); | ||
export function triggerRef(ref) { | ||
System.startBatch(); | ||
Dependency.propagate(ref); | ||
System.endBatch(); | ||
} | ||
const pausedSubsDepths = []; | ||
function pauseTracking() { | ||
pausedSubsDepths.push(index_js_1.System.activeSubsDepth); | ||
index_js_1.System.activeSubsDepth = 0; | ||
export function pauseTracking() { | ||
pausedSubsDepths.push(System.activeDepsSubsDepth); | ||
System.activeDepsSubsDepth = 0; | ||
} | ||
function resetTracking() { | ||
index_js_1.System.activeSubsDepth = pausedSubsDepths.pop(); | ||
export function resetTracking() { | ||
System.activeDepsSubsDepth = pausedSubsDepths.pop(); | ||
} | ||
function shallowRef(value) { | ||
export function shallowRef(value) { | ||
return new ShallowRef(value); | ||
} | ||
function computed(fn) { | ||
export function computed(fn) { | ||
return new VueComputed(fn); | ||
} | ||
function getCurrentScope() { | ||
export function getCurrentScope() { | ||
return currentEffectScope; | ||
} | ||
class ShallowRef extends index_js_1.Signal { | ||
export class ShallowRef extends Signal { | ||
get value() { | ||
@@ -70,4 +58,3 @@ return this.get(); | ||
} | ||
exports.ShallowRef = ShallowRef; | ||
class VueComputed extends index_js_1.Computed { | ||
class VueComputed extends Computed { | ||
get value() { | ||
@@ -77,6 +64,6 @@ return this.get(); | ||
} | ||
class ReactiveEffect extends index_js_1.Effect { | ||
export class ReactiveEffect extends Effect { | ||
get dirty() { | ||
if (this.versionOrDirtyLevel === 2 /* DirtyLevels.MaybeDirty */) { | ||
index_js_1.Subscriber.resolveMaybeDirty(this); | ||
Subscriber.resolveMaybeDirty(this); | ||
} | ||
@@ -89,8 +76,12 @@ return this.versionOrDirtyLevel === 3 /* DirtyLevels.Dirty */; | ||
stop() { | ||
index_js_1.Subscriber.clearTrack(this); | ||
if (this.deps !== undefined) { | ||
Subscriber.clearTrack(this.deps); | ||
this.deps = undefined; | ||
this.depsTail = undefined; | ||
} | ||
this.versionOrDirtyLevel = 0 /* DirtyLevels.None */; | ||
} | ||
} | ||
exports.ReactiveEffect = ReactiveEffect; | ||
function onScopeDispose(cb) { | ||
export function onScopeDispose(cb) { | ||
currentEffectScope?.onDispose.push(cb); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
35641
926