@maverick-js/signals
Advanced tools
Comparing version 5.10.4 to 5.10.5
@@ -17,3 +17,3 @@ import { SCOPE } from './symbols.js'; | ||
for (let i = 0; i < effects.length; i++) { | ||
if (effects[i].d !== STATE_CLEAN) | ||
if (effects[i].$st !== STATE_CLEAN) | ||
runTop(effects[i]); | ||
@@ -28,3 +28,3 @@ } | ||
while (node = node[SCOPE]) { | ||
if (node.j && node.d !== STATE_CLEAN) | ||
if (node.$e && node.$st !== STATE_CLEAN) | ||
ancestors.push(node); | ||
@@ -62,7 +62,7 @@ } | ||
function getContext(key, scope = currentScope) { | ||
return scope?.i[key]; | ||
return scope?.$cx[key]; | ||
} | ||
function setContext(key, value, scope = currentScope) { | ||
if (scope) | ||
scope.i = { ...scope.i, [key]: value }; | ||
scope.$cx = { ...scope.$cx, [key]: value }; | ||
} | ||
@@ -72,3 +72,3 @@ function onError(handler) { | ||
return; | ||
currentScope.f = [handler, ...currentScope.f]; | ||
currentScope.$eh = [handler, ...currentScope.$eh]; | ||
} | ||
@@ -79,17 +79,17 @@ function onDispose(disposable) { | ||
const node = currentScope; | ||
if (!node.a) { | ||
node.a = disposable; | ||
} else if (Array.isArray(node.a)) { | ||
node.a.push(disposable); | ||
if (!node.$d) { | ||
node.$d = disposable; | ||
} else if (Array.isArray(node.$d)) { | ||
node.$d.push(disposable); | ||
} else { | ||
node.a = [node.a, disposable]; | ||
node.$d = [node.$d, disposable]; | ||
} | ||
return function removeDispose() { | ||
if (node.d === STATE_DISPOSED) | ||
if (node.$st === STATE_DISPOSED) | ||
return; | ||
disposable.call(null); | ||
if (isFunction(node.a)) { | ||
node.a = null; | ||
} else if (Array.isArray(node.a)) { | ||
node.a.splice(node.a.indexOf(disposable), 1); | ||
if (isFunction(node.$d)) { | ||
node.$d = null; | ||
} else if (Array.isArray(node.$d)) { | ||
node.$d.splice(node.$d.indexOf(disposable), 1); | ||
} | ||
@@ -99,9 +99,9 @@ }; | ||
function dispose(self = true) { | ||
if (this.d === STATE_DISPOSED) | ||
if (this.$st === STATE_DISPOSED) | ||
return; | ||
let head = self ? this.g ?? this[SCOPE] : this, current = this.e; | ||
let head = self ? this.$ps ?? this[SCOPE] : this, current = this.$ns; | ||
while (current && current[SCOPE] === this) { | ||
dispose.call(current, true); | ||
disposeNode(current); | ||
current = current.e; | ||
current = current.$ns; | ||
} | ||
@@ -111,32 +111,32 @@ if (self) | ||
if (current) | ||
current.g = !self ? this : this.g; | ||
current.$ps = !self ? this : this.$ps; | ||
if (head) | ||
head.e = current; | ||
head.$ns = current; | ||
} | ||
function disposeNode(node) { | ||
node.d = STATE_DISPOSED; | ||
if (node.a) | ||
node.$st = STATE_DISPOSED; | ||
if (node.$d) | ||
emptyDisposal(node); | ||
if (node.b) | ||
if (node.$s) | ||
removeSourceObservers(node, 0); | ||
if (node.g) | ||
node.g.e = null; | ||
if (node.$ps) | ||
node.$ps.$ns = null; | ||
node[SCOPE] = null; | ||
node.b = null; | ||
node.c = null; | ||
node.g = null; | ||
node.i = null; | ||
node.f = null; | ||
node.$s = null; | ||
node.$o = null; | ||
node.$ps = null; | ||
node.$cx = null; | ||
node.$eh = null; | ||
} | ||
function emptyDisposal(scope) { | ||
try { | ||
if (Array.isArray(scope.a)) { | ||
for (let i = 0; i < scope.a.length; i++) { | ||
const callable = scope.a[i]; | ||
if (Array.isArray(scope.$d)) { | ||
for (let i = 0; i < scope.$d.length; i++) { | ||
const callable = scope.$d[i]; | ||
callable.call(callable); | ||
} | ||
} else { | ||
scope.a.call(scope.a); | ||
scope.$d.call(scope.$d); | ||
} | ||
scope.a = null; | ||
scope.$d = null; | ||
} catch (error) { | ||
@@ -160,6 +160,6 @@ handleError(scope, error); | ||
throw error; | ||
let i = 0, len = scope.f.length, coercedError = coerceError(error); | ||
let i = 0, len = scope.$eh.length, coercedError = coerceError(error); | ||
for (i = 0; i < len; i++) { | ||
try { | ||
scope.f[i](coercedError); | ||
scope.$eh[i](coercedError); | ||
break; | ||
@@ -177,6 +177,6 @@ } catch (error2) { | ||
function read() { | ||
if (this.d === STATE_DISPOSED) | ||
return this.h; | ||
if (currentObserver && !this.j) { | ||
if (!currentObservers && currentObserver.b && currentObserver.b[currentObserversIndex] == this) { | ||
if (this.$st === STATE_DISPOSED) | ||
return this.$v; | ||
if (currentObserver && !this.$e) { | ||
if (!currentObservers && currentObserver.$s && currentObserver.$s[currentObserversIndex] == this) { | ||
currentObserversIndex++; | ||
@@ -188,22 +188,22 @@ } else if (!currentObservers) | ||
} | ||
if (this.k) | ||
if (this.$c) | ||
updateCheck(this); | ||
return this.h; | ||
return this.$v; | ||
} | ||
function write(newValue) { | ||
const value = isFunction(newValue) ? newValue(this.h) : newValue; | ||
if (this.l(this.h, value)) { | ||
this.h = value; | ||
if (this.c) { | ||
for (let i = 0; i < this.c.length; i++) { | ||
notify(this.c[i], STATE_DIRTY); | ||
const value = isFunction(newValue) ? newValue(this.$v) : newValue; | ||
if (this.$ch(this.$v, value)) { | ||
this.$v = value; | ||
if (this.$o) { | ||
for (let i = 0; i < this.$o.length; i++) { | ||
notify(this.$o[i], STATE_DIRTY); | ||
} | ||
} | ||
} | ||
return this.h; | ||
return this.$v; | ||
} | ||
const ScopeNode = function Scope() { | ||
this[SCOPE] = null; | ||
this.e = null; | ||
this.g = null; | ||
this.$ns = null; | ||
this.$ps = null; | ||
if (currentScope) | ||
@@ -213,15 +213,15 @@ currentScope.append(this); | ||
const ScopeProto = ScopeNode.prototype; | ||
ScopeProto.i = {}; | ||
ScopeProto.f = []; | ||
ScopeProto.k = null; | ||
ScopeProto.a = null; | ||
ScopeProto.$cx = {}; | ||
ScopeProto.$eh = []; | ||
ScopeProto.$c = null; | ||
ScopeProto.$d = null; | ||
ScopeProto.append = function appendScope(scope) { | ||
scope[SCOPE] = this; | ||
scope.g = this; | ||
scope.i = this.i; | ||
scope.f = this.f; | ||
if (this.e) | ||
this.e.g = scope; | ||
scope.e = this.e; | ||
this.e = scope; | ||
scope.$ps = this; | ||
scope.$cx = this.$cx; | ||
scope.$eh = this.$eh; | ||
if (this.$ns) | ||
this.$ns.$ps = scope; | ||
scope.$ns = this.$ns; | ||
this.$ns = scope; | ||
}; | ||
@@ -233,16 +233,16 @@ function createScope() { | ||
ScopeNode.call(this); | ||
this.d = compute2 ? STATE_DIRTY : STATE_CLEAN; | ||
this.m = false; | ||
this.j = false; | ||
this.b = null; | ||
this.c = null; | ||
this.h = initialValue; | ||
this.$st = compute2 ? STATE_DIRTY : STATE_CLEAN; | ||
this.$i = false; | ||
this.$e = false; | ||
this.$s = null; | ||
this.$o = null; | ||
this.$v = initialValue; | ||
if (compute2) | ||
this.k = compute2; | ||
this.$c = compute2; | ||
if (options && options.dirty) | ||
this.l = options.dirty; | ||
this.$ch = options.dirty; | ||
}; | ||
const ComputeProto = ComputeNode.prototype; | ||
Object.setPrototypeOf(ComputeProto, ScopeProto); | ||
ComputeProto.l = isNotEqual; | ||
ComputeProto.$ch = isNotEqual; | ||
ComputeProto.call = read; | ||
@@ -259,6 +259,6 @@ function createComputation(initialValue, compute2, options) { | ||
function updateCheck(node) { | ||
if (node.d === STATE_CHECK) { | ||
for (let i = 0; i < node.b.length; i++) { | ||
updateCheck(node.b[i]); | ||
if (node.d === STATE_DIRTY) { | ||
if (node.$st === STATE_CHECK) { | ||
for (let i = 0; i < node.$s.length; i++) { | ||
updateCheck(node.$s[i]); | ||
if (node.$st === STATE_DIRTY) { | ||
break; | ||
@@ -268,13 +268,13 @@ } | ||
} | ||
if (node.d === STATE_DIRTY) | ||
if (node.$st === STATE_DIRTY) | ||
update(node); | ||
else | ||
node.d = STATE_CLEAN; | ||
node.$st = STATE_CLEAN; | ||
} | ||
function cleanup(node) { | ||
if (node.e && node.e[SCOPE] === node) | ||
if (node.$ns && node.$ns[SCOPE] === node) | ||
dispose.call(node, false); | ||
if (node.a) | ||
if (node.$d) | ||
emptyDisposal(node); | ||
node.f = node[SCOPE]?.f || []; | ||
node.$eh = node[SCOPE]?.$eh || []; | ||
} | ||
@@ -287,37 +287,37 @@ function update(node) { | ||
cleanup(node); | ||
const result = compute(node, node.k, node); | ||
const result = compute(node, node.$c, node); | ||
if (currentObservers) { | ||
if (node.b) | ||
if (node.$s) | ||
removeSourceObservers(node, currentObserversIndex); | ||
if (node.b && currentObserversIndex > 0) { | ||
node.b.length = currentObserversIndex + currentObservers.length; | ||
if (node.$s && currentObserversIndex > 0) { | ||
node.$s.length = currentObserversIndex + currentObservers.length; | ||
for (let i = 0; i < currentObservers.length; i++) { | ||
node.b[currentObserversIndex + i] = currentObservers[i]; | ||
node.$s[currentObserversIndex + i] = currentObservers[i]; | ||
} | ||
} else { | ||
node.b = currentObservers; | ||
node.$s = currentObservers; | ||
} | ||
let source; | ||
for (let i = currentObserversIndex; i < node.b.length; i++) { | ||
source = node.b[i]; | ||
if (!source.c) | ||
source.c = [node]; | ||
for (let i = currentObserversIndex; i < node.$s.length; i++) { | ||
source = node.$s[i]; | ||
if (!source.$o) | ||
source.$o = [node]; | ||
else | ||
source.c.push(node); | ||
source.$o.push(node); | ||
} | ||
} else if (node.b && currentObserversIndex < node.b.length) { | ||
} else if (node.$s && currentObserversIndex < node.$s.length) { | ||
removeSourceObservers(node, currentObserversIndex); | ||
node.b.length = currentObserversIndex; | ||
node.$s.length = currentObserversIndex; | ||
} | ||
if (!node.j && node.m) { | ||
if (!node.$e && node.$i) { | ||
write.call(node, result); | ||
} else { | ||
node.h = result; | ||
node.m = true; | ||
node.$v = result; | ||
node.$i = true; | ||
} | ||
} catch (error) { | ||
handleError(node, error); | ||
if (node.d === STATE_DIRTY) { | ||
if (node.$st === STATE_DIRTY) { | ||
cleanup(node); | ||
if (node.b) | ||
if (node.$s) | ||
removeSourceObservers(node, 0); | ||
@@ -329,8 +329,8 @@ } | ||
currentObserversIndex = prevObserversIndex; | ||
node.d = STATE_CLEAN; | ||
node.$st = STATE_CLEAN; | ||
} | ||
function notify(node, state) { | ||
if (node.d >= state) | ||
if (node.$st >= state) | ||
return; | ||
if (node.j && node.d === STATE_CLEAN) { | ||
if (node.$e && node.$st === STATE_CLEAN) { | ||
effects.push(node); | ||
@@ -340,6 +340,6 @@ if (!scheduledEffects) | ||
} | ||
node.d = state; | ||
if (node.c) { | ||
for (let i = 0; i < node.c.length; i++) { | ||
notify(node.c[i], STATE_CHECK); | ||
node.$st = state; | ||
if (node.$o) { | ||
for (let i = 0; i < node.$o.length; i++) { | ||
notify(node.$o[i], STATE_CHECK); | ||
} | ||
@@ -350,8 +350,8 @@ } | ||
let source, swap; | ||
for (let i = index; i < node.b.length; i++) { | ||
source = node.b[i]; | ||
if (source.c) { | ||
swap = source.c.indexOf(node); | ||
source.c[swap] = source.c[source.c.length - 1]; | ||
source.c.pop(); | ||
for (let i = index; i < node.$s.length; i++) { | ||
source = node.$s[i]; | ||
if (source.$o) { | ||
swap = source.$o.indexOf(node); | ||
source.$o[swap] = source.$o[source.$o.length - 1]; | ||
source.$o.pop(); | ||
} | ||
@@ -358,0 +358,0 @@ } |
@@ -17,3 +17,3 @@ import { onDispose, read, isNotEqual, write, createComputation, createScope, scoped, dispose, compute } from './core.js'; | ||
nodes.set(key, node = new Selector(key, key === currentKey, nodes)); | ||
node.a += 1; | ||
node.$r += 1; | ||
onDispose(node); | ||
@@ -24,17 +24,17 @@ return read.bind(node); | ||
function Selector(key, initialValue, nodes) { | ||
this.d = /** CLEAN */ | ||
this.$st = /** CLEAN */ | ||
0; | ||
this.c = key; | ||
this.e = initialValue; | ||
this.a = 0; | ||
this.b = nodes; | ||
this.f = null; | ||
this.$k = key; | ||
this.$v = initialValue; | ||
this.$r = 0; | ||
this.$n = nodes; | ||
this.$o = null; | ||
} | ||
const SelectorProto = Selector.prototype; | ||
SelectorProto.g = isNotEqual; | ||
SelectorProto.$ch = isNotEqual; | ||
SelectorProto.call = function() { | ||
this.a -= 1; | ||
if (!this.a) { | ||
this.b.delete(this.c); | ||
this.b = null; | ||
this.$r -= 1; | ||
if (!this.$r) { | ||
this.$n.delete(this.$k); | ||
this.$n = null; | ||
} | ||
@@ -48,9 +48,9 @@ }; | ||
updateMap.bind({ | ||
e: createScope(), | ||
d: 0, | ||
g: list, | ||
c: [], | ||
f: map, | ||
d: createScope(), | ||
c: 0, | ||
f: list, | ||
b: [], | ||
e: map, | ||
a: [], | ||
b: [] | ||
$n: [] | ||
}), | ||
@@ -62,11 +62,11 @@ options | ||
function updateMap() { | ||
let i = 0, newItems = this.g() || [], mapper = () => this.f(read.bind(this.b[i]), i); | ||
let i = 0, newItems = this.f() || [], mapper = () => this.e(read.bind(this.$n[i]), i); | ||
scoped(() => { | ||
if (newItems.length === 0) { | ||
if (this.d !== 0) { | ||
dispose.call(this.e, false); | ||
this.c = []; | ||
if (this.c !== 0) { | ||
dispose.call(this.d, false); | ||
this.b = []; | ||
this.a = []; | ||
this.d = 0; | ||
this.b = []; | ||
this.c = 0; | ||
this.$n = []; | ||
} | ||
@@ -76,7 +76,7 @@ return; | ||
for (i = 0; i < newItems.length; i++) { | ||
if (i < this.c.length && this.c[i] !== newItems[i]) { | ||
write.call(this.b[i], newItems[i]); | ||
} else if (i >= this.c.length) { | ||
if (i < this.b.length && this.b[i] !== newItems[i]) { | ||
write.call(this.$n[i], newItems[i]); | ||
} else if (i >= this.b.length) { | ||
this.a[i] = compute( | ||
this.b[i] = createComputation(newItems[i], null), | ||
this.$n[i] = createComputation(newItems[i], null), | ||
mapper, | ||
@@ -87,8 +87,8 @@ null | ||
} | ||
for (; i < this.c.length; i++) | ||
dispose.call(this.b[i]); | ||
this.d = this.b.length = newItems.length; | ||
this.c = newItems.slice(0); | ||
this.a = this.a.slice(0, this.d); | ||
}, this.e); | ||
for (; i < this.b.length; i++) | ||
dispose.call(this.$n[i]); | ||
this.c = this.$n.length = newItems.length; | ||
this.b = newItems.slice(0); | ||
this.a = this.a.slice(0, this.c); | ||
}, this.d); | ||
return this.a; | ||
@@ -101,9 +101,9 @@ } | ||
updateKeyedMap.bind({ | ||
e: createScope(), | ||
d: 0, | ||
g: list, | ||
c: [], | ||
f: map, | ||
d: createScope(), | ||
c: 0, | ||
f: list, | ||
b: [], | ||
e: map, | ||
a: [], | ||
b: [] | ||
$n: [] | ||
}), | ||
@@ -115,19 +115,19 @@ options | ||
function updateKeyedMap() { | ||
const newItems = this.g() || [], indexed = this.f.length > 1; | ||
const newItems = this.f() || [], indexed = this.e.length > 1; | ||
scoped(() => { | ||
let newLen = newItems.length, i, j, mapper = indexed ? () => this.f(newItems[j], read.bind(this.b[j])) : () => this.f(newItems[j]); | ||
let newLen = newItems.length, i, j, mapper = indexed ? () => this.e(newItems[j], read.bind(this.$n[j])) : () => this.e(newItems[j]); | ||
if (newLen === 0) { | ||
if (this.d !== 0) { | ||
dispose.call(this.e, false); | ||
if (this.c !== 0) { | ||
dispose.call(this.d, false); | ||
this.$n = []; | ||
this.b = []; | ||
this.c = []; | ||
this.a = []; | ||
this.d = 0; | ||
this.c = 0; | ||
} | ||
} else if (this.d === 0) { | ||
} else if (this.c === 0) { | ||
this.a = new Array(newLen); | ||
for (j = 0; j < newLen; j++) { | ||
this.c[j] = newItems[j]; | ||
this.b[j] = newItems[j]; | ||
this.a[j] = compute( | ||
this.b[j] = createComputation(j, null), | ||
this.$n[j] = createComputation(j, null), | ||
mapper, | ||
@@ -137,10 +137,10 @@ null | ||
} | ||
this.d = newLen; | ||
this.c = newLen; | ||
} else { | ||
let start, end, newEnd, item, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen); | ||
for (start = 0, end = Math.min(this.d, newLen); start < end && this.c[start] === newItems[start]; start++) | ||
for (start = 0, end = Math.min(this.c, newLen); start < end && this.b[start] === newItems[start]; start++) | ||
; | ||
for (end = this.d - 1, newEnd = newLen - 1; end >= start && newEnd >= start && this.c[end] === newItems[newEnd]; end--, newEnd--) { | ||
for (end = this.c - 1, newEnd = newLen - 1; end >= start && newEnd >= start && this.b[end] === newItems[newEnd]; end--, newEnd--) { | ||
temp[newEnd] = this.a[end]; | ||
tempNodes[newEnd] = this.b[end]; | ||
tempNodes[newEnd] = this.$n[end]; | ||
} | ||
@@ -156,11 +156,11 @@ newIndices = /* @__PURE__ */ new Map(); | ||
for (i = start; i <= end; i++) { | ||
item = this.c[i]; | ||
item = this.b[i]; | ||
j = newIndices.get(item); | ||
if (j !== void 0 && j !== -1) { | ||
temp[j] = this.a[i]; | ||
tempNodes[j] = this.b[i]; | ||
tempNodes[j] = this.$n[i]; | ||
j = newIndicesNext[j]; | ||
newIndices.set(item, j); | ||
} else | ||
dispose.call(this.b[i]); | ||
dispose.call(this.$n[i]); | ||
} | ||
@@ -170,7 +170,7 @@ for (j = start; j < newLen; j++) { | ||
this.a[j] = temp[j]; | ||
this.b[j] = tempNodes[j]; | ||
write.call(this.b[j], j); | ||
this.$n[j] = tempNodes[j]; | ||
write.call(this.$n[j], j); | ||
} else { | ||
this.a[j] = compute( | ||
this.b[j] = createComputation(j, null), | ||
this.$n[j] = createComputation(j, null), | ||
mapper, | ||
@@ -181,6 +181,6 @@ null | ||
} | ||
this.a = this.a.slice(0, this.d = newLen); | ||
this.c = newItems.slice(0); | ||
this.a = this.a.slice(0, this.c = newLen); | ||
this.b = newItems.slice(0); | ||
} | ||
}, this.e); | ||
}, this.d); | ||
return this.a; | ||
@@ -187,0 +187,0 @@ } |
@@ -31,3 +31,3 @@ import { createComputation, read, write, isFunction, update, dispose, onDispose } from './core.js'; | ||
); | ||
signal2.a = true; | ||
signal2.$e = true; | ||
update(signal2); | ||
@@ -34,0 +34,0 @@ return dispose.bind(signal2, true); |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.10.4", | ||
"version": "5.10.5", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "dist/types/index.d.ts", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
63222
0