@dhmk/atom
Advanced tools
Comparing version 2.0.1-test.7 to 2.0.1-test.8
@@ -13,3 +13,3 @@ var __assign = (this && this.__assign) || function () { | ||
import { runtime } from "../runtime"; | ||
import { useAtom, removeAtom, invalidate, } from "../shared"; | ||
import { useAtom, removeAtom, invalidateSubs, } from "../shared"; | ||
import { EID, defaultAtomOptions, Id } from "../types"; | ||
@@ -36,2 +36,5 @@ var DerivedAtom = /** @class */ (function () { | ||
var _this = this; | ||
if (this.state >= 4) { | ||
throw new Error("circular dependency"); | ||
} | ||
if (this.state === 1 || this.state === 2) { | ||
@@ -67,4 +70,2 @@ var ok = this.deps.every(function (t) { | ||
} | ||
// temp hack | ||
// if (this.deps.length) this.deps.length = this.pdi; | ||
prevDeps.forEach(function (t) { | ||
@@ -87,3 +88,3 @@ var a = t.a; | ||
this.vid = new Id(); | ||
invalidate(this.subs, 3, false); | ||
invalidateSubs(this, false); | ||
} | ||
@@ -105,8 +106,6 @@ } | ||
} | ||
var ti = deps.length; // this.pdi++; | ||
// deps[ti] = { a, v: vid, t: am }; // literal is faster than class | ||
deps.push({ a: a, v: vid, t: am }); | ||
a.m = mark; | ||
a.ti = ti; | ||
a.ti = deps.length; | ||
a.readFlag = true; | ||
deps.push({ a: a, v: vid, t: am }); // literal is faster than class | ||
}; | ||
@@ -120,4 +119,2 @@ DerivedAtom.prototype.dispose = function () { | ||
runtime.addEffect({ actualize: onBUO }); | ||
// temp hack | ||
// this.deps.length = this.pdi; | ||
this.deps.forEach(function (t) { return removeAtom(t.a, _this); }); | ||
@@ -124,0 +121,0 @@ this.deps.length = 0; |
@@ -12,3 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import { useAtom, invalidate } from "../shared"; | ||
import { useAtom, invalidateSubs } from "../shared"; | ||
import { Id, defaultAtomOptions, EID, } from "../types"; | ||
@@ -34,3 +34,3 @@ import { runtime } from "../runtime"; | ||
this.vid = new Id(); | ||
invalidate(this.subs, 3, true); | ||
invalidateSubs(this, true); | ||
}; | ||
@@ -37,0 +37,0 @@ ValueAtom.prototype.actualize = function () { }; |
import { ValueAtom } from "./atoms/value"; | ||
import { DerivedAtom } from "./atoms/derived"; | ||
import { runtime } from "./runtime"; | ||
import { invalidate } from "./shared"; | ||
import { invalidateSubs } from "./shared"; | ||
import observable from "./observable"; | ||
@@ -16,3 +16,3 @@ import observableObject, { as } from "./observable/object"; | ||
ea.state = 3; | ||
invalidate(ea.subs, 3, false); | ||
invalidateSubs(ea, false); | ||
runtime.addEffect(ea); | ||
@@ -19,0 +19,0 @@ runtime.runEffects(); |
@@ -7,2 +7,2 @@ export declare const removeAtom: (a: any, self: unknown) => void; | ||
export declare function eachar(a: any, fn: any): boolean; | ||
export declare function invalidate(as: any, s: any, iv: any): void; | ||
export declare function invalidateSubs(atom: any, iv: any, s?: number): void; |
@@ -39,8 +39,9 @@ import { runtime } from "./runtime"; | ||
} | ||
export function invalidate(as, s, iv) { | ||
as.forEach(function (_, a) { | ||
export function invalidateSubs(atom, iv, s) { | ||
if (s === void 0) { s = 3; } | ||
atom.subs.forEach(function (a) { | ||
if (iv && a.state === 4) { | ||
if (a.isEffect) | ||
runtime.addEffect(a); | ||
a.state = 1; | ||
a.state = 5; | ||
return; | ||
@@ -53,4 +54,4 @@ } | ||
runtime.addEffect(a); | ||
a.subs.size && invalidate(a.subs, 2, iv); | ||
a.subs.size && invalidateSubs(a, iv, 2); | ||
}); | ||
} |
@@ -38,2 +38,5 @@ "use strict"; | ||
var _this = this; | ||
if (this.state >= 4) { | ||
throw new Error("circular dependency"); | ||
} | ||
if (this.state === 1 || this.state === 2) { | ||
@@ -69,4 +72,2 @@ var ok = this.deps.every(function (t) { | ||
} | ||
// temp hack | ||
// if (this.deps.length) this.deps.length = this.pdi; | ||
prevDeps.forEach(function (t) { | ||
@@ -89,3 +90,3 @@ var a = t.a; | ||
this.vid = new types_1.Id(); | ||
(0, shared_1.invalidate)(this.subs, 3, false); | ||
(0, shared_1.invalidateSubs)(this, false); | ||
} | ||
@@ -107,8 +108,6 @@ } | ||
} | ||
var ti = deps.length; // this.pdi++; | ||
// deps[ti] = { a, v: vid, t: am }; // literal is faster than class | ||
deps.push({ a: a, v: vid, t: am }); | ||
a.m = mark; | ||
a.ti = ti; | ||
a.ti = deps.length; | ||
a.readFlag = true; | ||
deps.push({ a: a, v: vid, t: am }); // literal is faster than class | ||
}; | ||
@@ -122,4 +121,2 @@ DerivedAtom.prototype.dispose = function () { | ||
runtime_1.runtime.addEffect({ actualize: onBUO }); | ||
// temp hack | ||
// this.deps.length = this.pdi; | ||
this.deps.forEach(function (t) { return (0, shared_1.removeAtom)(t.a, _this); }); | ||
@@ -126,0 +123,0 @@ this.deps.length = 0; |
@@ -36,3 +36,3 @@ "use strict"; | ||
this.vid = new types_1.Id(); | ||
(0, shared_1.invalidate)(this.subs, 3, true); | ||
(0, shared_1.invalidateSubs)(this, true); | ||
}; | ||
@@ -39,0 +39,0 @@ ValueAtom.prototype.actualize = function () { }; |
@@ -52,3 +52,3 @@ "use strict"; | ||
ea.state = 3; | ||
(0, shared_1.invalidate)(ea.subs, 3, false); | ||
(0, shared_1.invalidateSubs)(ea, false); | ||
runtime_1.runtime.addEffect(ea); | ||
@@ -55,0 +55,0 @@ runtime_1.runtime.runEffects(); |
@@ -7,2 +7,2 @@ export declare const removeAtom: (a: any, self: unknown) => void; | ||
export declare function eachar(a: any, fn: any): boolean; | ||
export declare function invalidate(as: any, s: any, iv: any): void; | ||
export declare function invalidateSubs(atom: any, iv: any, s?: number): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.invalidate = exports.eachar = exports.eacha = exports.each = exports.reportError = exports.useAtom = exports.removeAtom = void 0; | ||
exports.invalidateSubs = exports.eachar = exports.eacha = exports.each = exports.reportError = exports.useAtom = exports.removeAtom = void 0; | ||
var runtime_1 = require("./runtime"); | ||
@@ -48,8 +48,9 @@ var removeAtom = function (a, self) { | ||
exports.eachar = eachar; | ||
function invalidate(as, s, iv) { | ||
as.forEach(function (_, a) { | ||
function invalidateSubs(atom, iv, s) { | ||
if (s === void 0) { s = 3; } | ||
atom.subs.forEach(function (a) { | ||
if (iv && a.state === 4) { | ||
if (a.isEffect) | ||
runtime_1.runtime.addEffect(a); | ||
a.state = 1; | ||
a.state = 5; | ||
return; | ||
@@ -62,5 +63,5 @@ } | ||
runtime_1.runtime.addEffect(a); | ||
a.subs.size && invalidate(a.subs, 2, iv); | ||
a.subs.size && invalidateSubs(a, iv, 2); | ||
}); | ||
} | ||
exports.invalidate = invalidate; | ||
exports.invalidateSubs = invalidateSubs; |
{ | ||
"name": "@dhmk/atom", | ||
"version": "2.0.1-test.7", | ||
"version": "2.0.1-test.8", | ||
"description": "Lightweight mobx-like observable values, computed values and side-effects", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
77970
2177