Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dhmk/atom

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dhmk/atom - npm Package Compare versions

Comparing version 2.0.1-test.8 to 2.0.1-test.9

17

esm/atoms/derived.d.ts

@@ -5,18 +5,13 @@ export declare class DerivedAtom {

subs: any;
t: any;
vid: any;
isObserved: any;
state: any;
isEffect: any;
fn: any;
recalc: any;
deps: any;
dit: any;
dt: any;
mark: any;
m: any;
ti: any;
readFlag: any;
pdi: any;
constructor(fn: any, isEffect: any, options: any);
mark: any;
deps: any;
isObserved: any;
isEffect: any;
fn: any;
constructor(fn: any, isEffect?: boolean, options?: any);
actualize(): void;

@@ -23,0 +18,0 @@ track(a: any): void;

@@ -13,6 +13,7 @@ var __assign = (this && this.__assign) || function () {

import { runtime } from "../runtime";
import { useAtom, removeAtom, invalidateSubs, } from "../shared";
import { EID, defaultAtomOptions, Id } from "../types";
import { trackAtom, removeAtom, invalidateSubs } from "../shared";
import { EID, defaultAtomOptions, Id, AtomState } from "../types";
var DerivedAtom = /** @class */ (function () {
function DerivedAtom(fn, isEffect, options) {
if (isEffect === void 0) { isEffect = false; }
this.value = undefined;

@@ -22,20 +23,21 @@ this.options = __assign(__assign({}, defaultAtomOptions), options);

this.vid = EID;
this.state = AtomState.Stale;
this.m = new Id();
this.ti = 0;
this.readFlag = false;
this.mark = EID;
this.deps = [];
this.isObserved = isEffect;
this.state = 3;
this.isEffect = isEffect;
this.fn = fn;
this.recalc = false;
this.deps = [];
this.mark = EID;
this.pdi = 0;
}
DerivedAtom.prototype.actualize = function () {
var _this = this;
if (this.state >= 4) {
var state0 = this.state;
if (state0 === AtomState.Actual)
return;
if (state0 >= AtomState.Computing) {
throw new Error("circular dependency");
}
if (this.state === 1 || this.state === 2) {
if (state0 <= AtomState.PossiblyStale) {
var ok = this.deps.every(function (t) {

@@ -47,9 +49,9 @@ var a = t.a;

if (!ok)
this.state = 3;
this.state = AtomState.Stale;
}
if (this.state === 3) {
// state0 may be outdated below
if (this.state === AtomState.Stale) {
var mark_1 = (this.mark = new Id());
var prevDeps = this.deps;
this.deps = [];
this.pdi = 0;
if (!this.isObserved && runtime.currentAtom) {

@@ -65,3 +67,3 @@ this.isObserved = true;

try {
this.state = 4;
this.state = AtomState.Computing;
nextValue = this.fn();

@@ -92,6 +94,6 @@ }

}
if (this.state === 4)
this.state = 0;
if (this.state === AtomState.Computing)
this.state = AtomState.Actual;
else
this.state = 1;
this.state = AtomState.InvalidatedWhileComputing;
};

@@ -121,3 +123,3 @@ DerivedAtom.prototype.track = function (a) {

this.deps.length = 0;
this.state = 3;
this.state = AtomState.Stale;
}

@@ -127,3 +129,3 @@ };

this.actualize();
useAtom(this);
trackAtom(this);
return this.value;

@@ -130,0 +132,0 @@ };

@@ -12,3 +12,3 @@ var __assign = (this && this.__assign) || function () {

};
import { useAtom, invalidateSubs } from "../shared";
import { trackAtom, invalidateSubs } from "../shared";
import { Id, defaultAtomOptions, EID, } from "../types";

@@ -38,3 +38,3 @@ import { runtime } from "../runtime";

ValueAtom.prototype.get = function () {
useAtom(this);
trackAtom(this);
if (!this.isObserved && runtime.currentAtom) {

@@ -41,0 +41,0 @@ this.isObserved = true;

import { ValueAtom } from "./atoms/value";
import { DerivedAtom } from "./atoms/derived";
import { runtime } from "./runtime";
import { AtomState } from "./types";
import { invalidateSubs } from "./shared";

@@ -15,3 +16,3 @@ import observable from "./observable";

ectrl.invalidate = function () {
ea.state = 3;
ea.state = AtomState.Stale;
invalidateSubs(ea, false);

@@ -18,0 +19,0 @@ runtime.addEffect(ea);

import { ValueAtom } from "../atoms/value";
import { ComputedAtom } from "../atoms/computed";
import { DerivedAtom } from "../atoms/derived";
var AS = Symbol();

@@ -22,3 +22,3 @@ export function as(x) {

var getter_1 = desc.get;
a_1 = new ComputedAtom(function () {
a_1 = new DerivedAtom(function () {
var value = getter_1.call(r);

@@ -25,0 +25,0 @@ if (!initialized_1) {

@@ -0,7 +1,5 @@

import { AtomState } from "./types";
export declare const removeAtom: (a: any, self: unknown) => void;
export declare function useAtom(a: any): void;
export declare function trackAtom(a: any): void;
export declare function reportError(e: unknown): () => never;
export declare function each(it: any, fn: any): boolean;
export declare function eacha(a: any, fn: any, i?: number, s?: any): void;
export declare function eachar(a: any, fn: any): boolean;
export declare function invalidateSubs(atom: any, iv: any, s?: number): void;
export declare function invalidateSubs(atom: any, isValueAtom: any, newState?: AtomState): void;
import { runtime } from "./runtime";
import { AtomState } from "./types";
export var removeAtom = function (a, self) {

@@ -7,3 +8,3 @@ a.subs.delete(self);

};
export function useAtom(a) {
export function trackAtom(a) {
var ca = runtime.currentAtom;

@@ -18,40 +19,18 @@ if (ca)

}
export function each(it, fn) {
while (true) {
var _a = it.next(), done = _a.done, value = _a.value;
if (done)
return true;
if (fn(value) === false)
return false;
}
}
export function eacha(a, fn, i, s) {
if (i === void 0) { i = 0; }
if (s === void 0) { s = a.length; }
while (i < s)
fn(a[i++]);
}
export function eachar(a, fn) {
var i = 0, s = a.length;
while (i < s)
if (fn(a[i++]) === false)
return false;
return true;
}
export function invalidateSubs(atom, iv, s) {
if (s === void 0) { s = 3; }
export function invalidateSubs(atom, isValueAtom, newState) {
if (newState === void 0) { newState = AtomState.Stale; }
atom.subs.forEach(function (a) {
if (iv && a.state === 4) {
if (isValueAtom && a.state === AtomState.Computing) {
if (a.isEffect)
runtime.addEffect(a);
a.state = 5;
a.state = AtomState.InvalidatedAndComputing;
return;
}
if (a.state >= s)
if (a.state >= newState)
return;
a.state = s;
a.state = newState;
if (a.isEffect)
runtime.addEffect(a);
a.subs.size && invalidateSubs(a, iv, 2);
a.subs.size && invalidateSubs(a, isValueAtom, AtomState.PossiblyStale);
});
}

@@ -21,4 +21,7 @@ export declare class Id {

Actual = 0,
PossiblyStale = 1,
Stale = 2
InvalidatedWhileComputing = 1,
PossiblyStale = 2,
Stale = 3,
Computing = 4,
InvalidatedAndComputing = 5
}

@@ -25,0 +28,0 @@ export type Atom = {

@@ -21,4 +21,7 @@ var Id = /** @class */ (function () {

AtomState[AtomState["Actual"] = 0] = "Actual";
AtomState[AtomState["PossiblyStale"] = 1] = "PossiblyStale";
AtomState[AtomState["Stale"] = 2] = "Stale";
AtomState[AtomState["InvalidatedWhileComputing"] = 1] = "InvalidatedWhileComputing";
AtomState[AtomState["PossiblyStale"] = 2] = "PossiblyStale";
AtomState[AtomState["Stale"] = 3] = "Stale";
AtomState[AtomState["Computing"] = 4] = "Computing";
AtomState[AtomState["InvalidatedAndComputing"] = 5] = "InvalidatedAndComputing";
})(AtomState || (AtomState = {}));

@@ -25,0 +28,0 @@ export var defaultAtomOptions = {

@@ -5,18 +5,13 @@ export declare class DerivedAtom {

subs: any;
t: any;
vid: any;
isObserved: any;
state: any;
isEffect: any;
fn: any;
recalc: any;
deps: any;
dit: any;
dt: any;
mark: any;
m: any;
ti: any;
readFlag: any;
pdi: any;
constructor(fn: any, isEffect: any, options: any);
mark: any;
deps: any;
isObserved: any;
isEffect: any;
fn: any;
constructor(fn: any, isEffect?: boolean, options?: any);
actualize(): void;

@@ -23,0 +18,0 @@ track(a: any): void;

@@ -20,2 +20,3 @@ "use strict";

function DerivedAtom(fn, isEffect, options) {
if (isEffect === void 0) { isEffect = false; }
this.value = undefined;

@@ -25,20 +26,21 @@ this.options = __assign(__assign({}, types_1.defaultAtomOptions), options);

this.vid = types_1.EID;
this.state = types_1.AtomState.Stale;
this.m = new types_1.Id();
this.ti = 0;
this.readFlag = false;
this.mark = types_1.EID;
this.deps = [];
this.isObserved = isEffect;
this.state = 3;
this.isEffect = isEffect;
this.fn = fn;
this.recalc = false;
this.deps = [];
this.mark = types_1.EID;
this.pdi = 0;
}
DerivedAtom.prototype.actualize = function () {
var _this = this;
if (this.state >= 4) {
var state0 = this.state;
if (state0 === types_1.AtomState.Actual)
return;
if (state0 >= types_1.AtomState.Computing) {
throw new Error("circular dependency");
}
if (this.state === 1 || this.state === 2) {
if (state0 <= types_1.AtomState.PossiblyStale) {
var ok = this.deps.every(function (t) {

@@ -50,9 +52,9 @@ var a = t.a;

if (!ok)
this.state = 3;
this.state = types_1.AtomState.Stale;
}
if (this.state === 3) {
// state0 may be outdated below
if (this.state === types_1.AtomState.Stale) {
var mark_1 = (this.mark = new types_1.Id());
var prevDeps = this.deps;
this.deps = [];
this.pdi = 0;
if (!this.isObserved && runtime_1.runtime.currentAtom) {

@@ -68,3 +70,3 @@ this.isObserved = true;

try {
this.state = 4;
this.state = types_1.AtomState.Computing;
nextValue = this.fn();

@@ -95,6 +97,6 @@ }

}
if (this.state === 4)
this.state = 0;
if (this.state === types_1.AtomState.Computing)
this.state = types_1.AtomState.Actual;
else
this.state = 1;
this.state = types_1.AtomState.InvalidatedWhileComputing;
};

@@ -124,3 +126,3 @@ DerivedAtom.prototype.track = function (a) {

this.deps.length = 0;
this.state = 3;
this.state = types_1.AtomState.Stale;
}

@@ -130,3 +132,3 @@ };

this.actualize();
(0, shared_1.useAtom)(this);
(0, shared_1.trackAtom)(this);
return this.value;

@@ -133,0 +135,0 @@ };

@@ -40,3 +40,3 @@ "use strict";

ValueAtom.prototype.get = function () {
(0, shared_1.useAtom)(this);
(0, shared_1.trackAtom)(this);
if (!this.isObserved && runtime_1.runtime.currentAtom) {

@@ -43,0 +43,0 @@ this.isObserved = true;

@@ -36,2 +36,3 @@ "use strict";

Object.defineProperty(exports, "runtime", { enumerable: true, get: function () { return runtime_1.runtime; } });
var types_1 = require("./types");
var shared_1 = require("./shared");

@@ -52,3 +53,3 @@ var observable_1 = __importDefault(require("./observable"));

ectrl.invalidate = function () {
ea.state = 3;
ea.state = types_1.AtomState.Stale;
(0, shared_1.invalidateSubs)(ea, false);

@@ -55,0 +56,0 @@ runtime_1.runtime.addEffect(ea);

@@ -5,3 +5,3 @@ "use strict";

var value_1 = require("../atoms/value");
var computed_1 = require("../atoms/computed");
var derived_1 = require("../atoms/derived");
var AS = Symbol();

@@ -27,3 +27,3 @@ function as(x) {

var getter_1 = desc.get;
a_1 = new computed_1.ComputedAtom(function () {
a_1 = new derived_1.DerivedAtom(function () {
var value = getter_1.call(r);

@@ -30,0 +30,0 @@ if (!initialized_1) {

@@ -0,7 +1,5 @@

import { AtomState } from "./types";
export declare const removeAtom: (a: any, self: unknown) => void;
export declare function useAtom(a: any): void;
export declare function trackAtom(a: any): void;
export declare function reportError(e: unknown): () => never;
export declare function each(it: any, fn: any): boolean;
export declare function eacha(a: any, fn: any, i?: number, s?: any): void;
export declare function eachar(a: any, fn: any): boolean;
export declare function invalidateSubs(atom: any, iv: any, s?: number): void;
export declare function invalidateSubs(atom: any, isValueAtom: any, newState?: AtomState): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.invalidateSubs = exports.eachar = exports.eacha = exports.each = exports.reportError = exports.useAtom = exports.removeAtom = void 0;
exports.invalidateSubs = exports.reportError = exports.trackAtom = exports.removeAtom = void 0;
var runtime_1 = require("./runtime");
var types_1 = require("./types");
var removeAtom = function (a, self) {

@@ -11,3 +12,3 @@ a.subs.delete(self);

exports.removeAtom = removeAtom;
function useAtom(a) {
function trackAtom(a) {
var ca = runtime_1.runtime.currentAtom;

@@ -17,3 +18,3 @@ if (ca)

}
exports.useAtom = useAtom;
exports.trackAtom = trackAtom;
function reportError(e) {

@@ -25,44 +26,19 @@ return function () {

exports.reportError = reportError;
function each(it, fn) {
while (true) {
var _a = it.next(), done = _a.done, value = _a.value;
if (done)
return true;
if (fn(value) === false)
return false;
}
}
exports.each = each;
function eacha(a, fn, i, s) {
if (i === void 0) { i = 0; }
if (s === void 0) { s = a.length; }
while (i < s)
fn(a[i++]);
}
exports.eacha = eacha;
function eachar(a, fn) {
var i = 0, s = a.length;
while (i < s)
if (fn(a[i++]) === false)
return false;
return true;
}
exports.eachar = eachar;
function invalidateSubs(atom, iv, s) {
if (s === void 0) { s = 3; }
function invalidateSubs(atom, isValueAtom, newState) {
if (newState === void 0) { newState = types_1.AtomState.Stale; }
atom.subs.forEach(function (a) {
if (iv && a.state === 4) {
if (isValueAtom && a.state === types_1.AtomState.Computing) {
if (a.isEffect)
runtime_1.runtime.addEffect(a);
a.state = 5;
a.state = types_1.AtomState.InvalidatedAndComputing;
return;
}
if (a.state >= s)
if (a.state >= newState)
return;
a.state = s;
a.state = newState;
if (a.isEffect)
runtime_1.runtime.addEffect(a);
a.subs.size && invalidateSubs(a, iv, 2);
a.subs.size && invalidateSubs(a, isValueAtom, types_1.AtomState.PossiblyStale);
});
}
exports.invalidateSubs = invalidateSubs;

@@ -21,4 +21,7 @@ export declare class Id {

Actual = 0,
PossiblyStale = 1,
Stale = 2
InvalidatedWhileComputing = 1,
PossiblyStale = 2,
Stale = 3,
Computing = 4,
InvalidatedAndComputing = 5
}

@@ -25,0 +28,0 @@ export type Atom = {

@@ -24,4 +24,7 @@ "use strict";

AtomState[AtomState["Actual"] = 0] = "Actual";
AtomState[AtomState["PossiblyStale"] = 1] = "PossiblyStale";
AtomState[AtomState["Stale"] = 2] = "Stale";
AtomState[AtomState["InvalidatedWhileComputing"] = 1] = "InvalidatedWhileComputing";
AtomState[AtomState["PossiblyStale"] = 2] = "PossiblyStale";
AtomState[AtomState["Stale"] = 3] = "Stale";
AtomState[AtomState["Computing"] = 4] = "Computing";
AtomState[AtomState["InvalidatedAndComputing"] = 5] = "InvalidatedAndComputing";
})(AtomState = exports.AtomState || (exports.AtomState = {}));

@@ -28,0 +31,0 @@ exports.defaultAtomOptions = {

{
"name": "@dhmk/atom",
"version": "2.0.1-test.8",
"version": "2.0.1-test.9",
"description": "Lightweight mobx-like observable values, computed values and side-effects",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc