New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fluidstate

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluidstate - npm Package Compare versions

Comparing version 0.0.17 to 0.0.18

collector.d.ts

95

index.d.ts

@@ -1,46 +0,34 @@

import { createApi } from "./api";
import { createReactiveApi } from "./reactive-api";
declare const defaultApi: {
set: <T>(node: import("./types").Node<T>, newValue: T) => void;
notify: <T_1>(node: import("./types").Node<T_1>) => void;
get: <T_2>(node: import("./types").Node<T_2>) => T_2;
configure: (newConfiguration: Partial<import("./types").Configuration>) => void;
getConfiguration: () => import("./types").Configuration;
createCustomObserved: <T_3>(inert: import("./types").InertControl<T_3>, lifeCycle?: import("./types").LifeCycle | undefined) => import("./types").Observed<T_3>;
createObserved: <T_4>(value: T_4) => import("./types").Observed<T_4>;
createEmptyObserved: () => import("./types").Observed<void>;
createCustomComputed: <T_5>(inert: import("./types").InertControl<T_5>, getCalculate: () => () => T_5, lifeCycle?: import("./types").LifeCycle | undefined) => import("./types").Computed<T_5>;
createComputed: <T_6>(calculate: () => T_6) => import("./types").Computed<T_6>;
createEffect: import("./types").CreateEffect;
disableComputed: (node: import("./types").Computed<unknown>) => void;
batch: (update: () => void) => void;
triggerUpdate: ({ shouldResolveImmediatelyAfterBatch, }?: {
shouldResolveImmediatelyAfterBatch?: boolean | undefined;
}) => void;
stopAllEffects: () => void;
};
declare const defaultReactiveApi: {
createReactive: <T>(something: T) => T;
getReactive: <T_1 extends object>(something: T_1) => T_1 | null;
getInert: <T_2 extends object>(proxy: T_2) => T_2 | null;
getComputedKeys: <T_3>(object: T_3) => Set<string | symbol>;
createEffect: import("./types").CreateEffect;
};
declare const configure: (newConfiguration: Partial<import("./types").Configuration>) => void, getConfiguration: () => import("./types").Configuration, batch: (update: () => void) => void, triggerUpdate: ({ shouldResolveImmediatelyAfterBatch, }?: {
shouldResolveImmediatelyAfterBatch?: boolean | undefined;
}) => void, stopAllEffects: () => void;
declare const createEffect: import("./types").CreateEffect, createReactive: <T>(something: T) => T, getInert: <T extends object>(proxy: T) => T | null, getReactive: <T extends object>(something: T) => T | null, getComputedKeys: <T>(object: T) => Set<string | symbol>;
export { createApi, createReactiveApi };
export { defaultApi, defaultReactiveApi };
import { stopAllReactions } from "./nodes";
import { createReaction, createReactive, getComputedKeys, getInert, getReactive } from "./reactive-api";
import { batch, triggerUpdate } from "./scheduler";
import { SchedulerConfig, customizeSchedulerConfig, getCurrentSchedulerConfig, resetSchedulerConfig } from "./scheduler-config";
import { ReactionStop } from "./types";
export {
/**
* Configure default behavior of `fluidstate`
* Type of the reaction cleanup function returned from `createReaction`
*/
configure,
ReactionStop,
/**
* Get current configuration of the default `fluidstate` instance
* Type of the scheduler configuration
*/
getConfiguration,
SchedulerConfig,
/**
* Given a function, run it, while preventing recalculations and effects until
* Function that allows customizing scheduler timing. There is 2 functions
* to customize: `schedule` and `cancel`. `schedule` takes a function `triggerUpdate`
* that should be called at some point in order to trigger the value update and
* propagate changes to reactions. It may return any kind of ID, and that ID will be
* passed to `cancel` in order to cancel the update
*/
customizeSchedulerConfig,
/**
* Get current scheduler configuration
*/
getCurrentSchedulerConfig,
/**
* Reset scheduler configuration back to default. The default scheduler config defers
* recalculations and reactions to the end of the event loop
*/
resetSchedulerConfig,
/**
* Given a function, run it, while preventing recalculations and reactions until
* the function finished running

@@ -50,23 +38,23 @@ */

/**
* Triggers an update to all computed properties and runs effects. If called
* during batching, update will happen after the batch is finished (or ignored
* if the option is overridden). Update triggering will also be ignored in case
* a current update is already in progress
* Triggers an update to all computed properties and runs reactions. Update triggering
* will be ignored in case an update is already in progress or if the batching is in
* progress
*/
triggerUpdate,
/**
* Create a reactive effect, consisting of reactive and inert parts. Reactive
* part subscribes to all properties that are accessed in it or are returned.
* Inert part takes the value returned from reactive part and can safely
* perform any effect - property access in the inert part will not trigger
* any subscriptions
* Create a reaction, consisting of a reactive calculation and an inert effect.
* Reactive part subscribes to all properties that are accessed in it or are returned.
* Inert part takes the value returned from the reactive part and can safely
* perform any effect - accessing reactive values in the inert part will not trigger
* subscription to those reactive values
*/
createEffect,
createReaction,
/**
* Stops all effects that were created but not stopped yet
* Stops all reactions that were created but not stopped yet. Uses WeakRefs to store
* reactions to prevent memory leaks
*/
stopAllEffects,
stopAllReactions,
/**
* Creates a reactive wrapper (proxy) around any object. Arrays, sets, maps and
* regular objects are natively supported. Effects / computed properties that access
* regular objects are natively supported. Reactions / computed properties that access
* items of these objects (such as keys, values, etc) automatically subscribe to

@@ -79,3 +67,4 @@ * them. The reactive wrapper does not create a clone of the object - the original

/**
* Given a reactive object / wrapper / proxy, return its original inert object
* Given a reactive object / wrapper / proxy, return its original inert object. If
* the provided object is not reactive, null is returned
*/

@@ -82,0 +71,0 @@ getInert,

@@ -6,47 +6,85 @@ "use strict";

});
exports.configure = exports.batch = void 0;
Object.defineProperty(exports, "createApi", {
Object.defineProperty(exports, "ReactionStop", {
enumerable: true,
get: function () {
return _api.createApi;
return _types.ReactionStop;
}
});
exports.createReactive = exports.createEffect = void 0;
Object.defineProperty(exports, "createReactiveApi", {
Object.defineProperty(exports, "SchedulerConfig", {
enumerable: true,
get: function () {
return _reactiveApi.createReactiveApi;
return _schedulerConfig.SchedulerConfig;
}
});
exports.triggerUpdate = exports.stopAllEffects = exports.getReactive = exports.getInert = exports.getConfiguration = exports.getComputedKeys = exports.defaultReactiveApi = exports.defaultApi = void 0;
var _api = require("./api");
Object.defineProperty(exports, "batch", {
enumerable: true,
get: function () {
return _scheduler.batch;
}
});
Object.defineProperty(exports, "createReaction", {
enumerable: true,
get: function () {
return _reactiveApi.createReaction;
}
});
Object.defineProperty(exports, "createReactive", {
enumerable: true,
get: function () {
return _reactiveApi.createReactive;
}
});
Object.defineProperty(exports, "customizeSchedulerConfig", {
enumerable: true,
get: function () {
return _schedulerConfig.customizeSchedulerConfig;
}
});
Object.defineProperty(exports, "getComputedKeys", {
enumerable: true,
get: function () {
return _reactiveApi.getComputedKeys;
}
});
Object.defineProperty(exports, "getCurrentSchedulerConfig", {
enumerable: true,
get: function () {
return _schedulerConfig.getCurrentSchedulerConfig;
}
});
Object.defineProperty(exports, "getInert", {
enumerable: true,
get: function () {
return _reactiveApi.getInert;
}
});
Object.defineProperty(exports, "getReactive", {
enumerable: true,
get: function () {
return _reactiveApi.getReactive;
}
});
Object.defineProperty(exports, "resetSchedulerConfig", {
enumerable: true,
get: function () {
return _schedulerConfig.resetSchedulerConfig;
}
});
Object.defineProperty(exports, "stopAllReactions", {
enumerable: true,
get: function () {
return _nodes.stopAllReactions;
}
});
Object.defineProperty(exports, "triggerUpdate", {
enumerable: true,
get: function () {
return _scheduler.triggerUpdate;
}
});
var _nodes = require("./nodes");
var _reactiveApi = require("./reactive-api");
const defaultApi = (0, _api.createApi)();
exports.defaultApi = defaultApi;
const defaultReactiveApi = (0, _reactiveApi.createReactiveApi)(defaultApi);
exports.defaultReactiveApi = defaultReactiveApi;
const {
configure,
getConfiguration,
batch,
triggerUpdate,
stopAllEffects
} = defaultApi;
exports.stopAllEffects = stopAllEffects;
exports.triggerUpdate = triggerUpdate;
exports.batch = batch;
exports.getConfiguration = getConfiguration;
exports.configure = configure;
const {
createEffect,
createReactive,
getInert,
getReactive,
getComputedKeys
} = defaultReactiveApi;
exports.getComputedKeys = getComputedKeys;
exports.getReactive = getReactive;
exports.getInert = getInert;
exports.createReactive = createReactive;
exports.createEffect = createEffect;
var _scheduler = require("./scheduler");
var _schedulerConfig = require("./scheduler-config");
var _types = require("./types");
//# sourceMappingURL=index.js.map

@@ -1,18 +0,9 @@

import { DependenciesManager } from "./dependencies-manager";
import { Computed, CreateEffect, InertControl, LifeCycle, Observed } from "./types";
import { UpdateManager } from "./update-manager";
export declare const isNode: (value: unknown) => value is Computed<unknown> | Observed<unknown>;
export declare const isObserved: (value: unknown) => value is Observed<unknown>;
export declare const isComputed: (value: unknown) => value is Computed<unknown>;
export declare const createDefaultInertControl: <T>(value: T) => InertControl<T>;
export declare const emptyInertControl: InertControl<void>;
export declare const createDefaultCalculateControl: <T>(calculate: () => T) => () => () => T;
export declare const createNodesApi: (dependenciesManager: DependenciesManager, updateManager: UpdateManager) => {
createCustomObserved: <T>(inert: InertControl<T>, lifeCycle?: LifeCycle) => Observed<T>;
createCustomComputed: <T_1>(inert: InertControl<T_1>, getCalculate: () => () => T_1, lifeCycle?: LifeCycle) => Computed<T_1>;
createObserved: <T_2>(value: T_2) => Observed<T_2>;
createEmptyObserved: () => Observed<void>;
createComputed: <T_3>(calculate: () => T_3) => Computed<T_3>;
createEffect: CreateEffect;
stopAllEffects: () => void;
};
import { Computed, Observed, Node, CreateReaction } from "./types";
export declare const get: <T>(node: Node<T>) => T;
export declare const set: <T>(node: Node<T>, value: T) => void;
export declare const createObserved: <T>(value: T) => Observed<T>;
export declare const initializeAsObserved: <T>(observed: Observed<T>) => void;
export declare const createComputed: <T>(calculate: () => T) => Computed<T>;
export declare const initializeAsComputed: <T>(computed: Computed<T>) => void;
export declare const createCoreReaction: CreateReaction;
export declare const stopAllReactions: () => void;

@@ -6,125 +6,140 @@ "use strict";

});
exports.isObserved = exports.isNode = exports.isComputed = exports.emptyInertControl = exports.createNodesApi = exports.createDefaultInertControl = exports.createDefaultCalculateControl = void 0;
const observedSet = new WeakSet();
const computedSet = new WeakSet();
const isNode = value => {
return isObserved(value) || isComputed(value);
exports.stopAllReactions = exports.set = exports.initializeAsObserved = exports.initializeAsComputed = exports.get = exports.createObserved = exports.createCoreReaction = exports.createComputed = void 0;
var _collector = require("./collector");
var _dependencies = require("./dependencies");
var _effects = require("./effects");
var _scheduler = require("./scheduler");
var _types = require("./types");
var _utils = require("./utils");
let checkingDependencyChangedCount = 0;
const reactionWeakRefs = new Set();
const get = node => {
(0, _scheduler.triggerUpdate)();
const derived = _collector.collector.collectDependency(node);
if (derived && (0, _utils.isComputed)(derived)) {
(0, _dependencies.addComputedDependency)(derived, node);
}
if (!isCheckingDependenciesChanged()) {
const reaction = _collector.collector.getReaction();
if (reaction) {
if ((0, _utils.isComputed)(node) && node.reactions.size === 0) {
(0, _scheduler.setUpdateStatus)(node, _types.UpdateStatus.Changed);
}
(0, _dependencies.addReactionDependency)(reaction, node);
}
}
if ((0, _utils.isComputed)(node)) {
return calculateComputedValue(node);
}
return node.value;
};
exports.isNode = isNode;
const isObserved = value => {
return observedSet.has(value);
exports.get = get;
const calculateComputedValue = computed => {
if ((0, _scheduler.getUpdateStatus)(computed) === _types.UpdateStatus.MaybeChanged) {
(0, _scheduler.setUpdateStatus)(computed, isAnyDependencyChanged(computed) ? _types.UpdateStatus.Changed : _types.UpdateStatus.Unchanged);
}
const updateStatus = (0, _scheduler.getUpdateStatus)(computed);
if (updateStatus === _types.UpdateStatus.Unchanged || updateStatus === _types.UpdateStatus.ChangedCached) {
return computed.value;
}
const newValue = (0, _dependencies.calculateComputed)(computed);
let isValueChanged = !Object.is(computed.value, newValue);
computed.value = newValue;
if (isValueChanged) {
(0, _scheduler.setUpdateStatus)(computed, _types.UpdateStatus.ChangedCached);
} else {
(0, _scheduler.setUpdateStatus)(computed, _types.UpdateStatus.Unchanged);
}
return computed.value;
};
exports.isObserved = isObserved;
const isComputed = value => {
return computedSet.has(value);
const isCheckingDependenciesChanged = () => {
return checkingDependencyChangedCount > 0;
};
exports.isComputed = isComputed;
const createDefaultInertControl = value => {
return {
get() {
return value;
},
set(newValue) {
value = newValue;
},
equal(newValue) {
return Object.is(value, newValue);
const isAnyDependencyChanged = computed => {
checkingDependencyChangedCount++;
try {
for (const dependency of computed.dependencies) {
if ((0, _utils.isComputed)(dependency) && (0, _scheduler.getUpdateStatus)(dependency) === _types.UpdateStatus.MaybeChanged) {
calculateComputedValue(dependency);
}
const updateStatus = (0, _scheduler.getUpdateStatus)(dependency);
if (updateStatus === _types.UpdateStatus.Changed || updateStatus === _types.UpdateStatus.ChangedCached) {
return true;
}
}
};
};
exports.createDefaultInertControl = createDefaultInertControl;
const emptyInertControl = {
get() {},
set(_newValue) {},
equal(_newValue) {
return true;
return false;
} finally {
checkingDependencyChangedCount--;
}
};
exports.emptyInertControl = emptyInertControl;
const createDefaultCalculateControl = calculate => {
return () => calculate;
const set = (node, value) => {
(0, _scheduler.scheduleNodeUpdate)(node, value);
};
exports.createDefaultCalculateControl = createDefaultCalculateControl;
const createNodesApi = (dependenciesManager, updateManager) => {
const computedStopEffectMap = new WeakMap();
const effectComputedRefs = new Set();
const createCustomObserved = (inert, lifeCycle) => {
const observed = {
derived: new Set(),
inert,
lifeCycle
};
observedSet.add(observed);
return observed;
exports.set = set;
const createObserved = value => {
const observed = {
type: _types.ReactiveType.Observed,
computeds: new Set(),
reactions: new Set(),
value
};
const createCustomComputed = (inert, getCalculate, lifeCycle) => {
const computed = {
getCalculate,
dependencies: new Set(),
derived: new Set(),
inert,
lifeCycle
};
computedSet.add(computed);
computed.inert.set(dependenciesManager.calculateValueAndDependencies(computed));
return computed;
initializeAsObserved(observed);
return observed;
};
exports.createObserved = createObserved;
const initializeAsObserved = observed => {
(0, _scheduler.setUpdateStatus)(observed, _types.UpdateStatus.Unchanged);
(0, _scheduler.setUpdateIndex)(observed, -1);
};
exports.initializeAsObserved = initializeAsObserved;
const createComputed = calculate => {
const computed = {
type: _types.ReactiveType.Computed,
value: null,
dependencies: new Set(),
calculate,
computeds: new Set(),
reactions: new Set()
};
const createObserved = value => {
return createCustomObserved(createDefaultInertControl(value));
initializeAsComputed(computed);
return computed;
};
exports.createComputed = createComputed;
const initializeAsComputed = computed => {
(0, _scheduler.setUpdateStatus)(computed, _types.UpdateStatus.Changed);
(0, _scheduler.setUpdateIndex)(computed, -1);
_dependencies.becomeNonReactiveListeners.set(computed, () => (0, _dependencies.removeAllComputedDependencies)(computed));
_dependencies.becomeReactiveListeners.set(computed, () => (0, _dependencies.addAllComputedDependencies)(computed));
};
exports.initializeAsComputed = initializeAsComputed;
const createCoreReaction = (calculate, effect) => {
const reaction = {
type: _types.ReactiveType.Reaction,
dependencies: new Set(),
calculate,
effect
};
const createEmptyObserved = () => {
return createCustomObserved(emptyInertControl);
};
const createComputed = calculate => {
return createCustomComputed(createDefaultInertControl(null), createDefaultCalculateControl(calculate));
};
const createEffect = (calculate, perform) => {
const effectId = Symbol();
let isInitial = true;
let isEffectScheduled = false;
const computed = createComputed(() => {
const computedValue = calculate();
isEffectScheduled = updateManager.addEffect(effectId, isInitial, () => perform(computedValue));
return computedValue;
});
const effectComputedRef = new WeakRef(computed);
effectComputedRefs.add(effectComputedRef);
isInitial = false;
if (!isEffectScheduled) {
perform(computed.inert.get());
const reactionRef = new WeakRef(reaction);
reactionWeakRefs.add(reactionRef);
(0, _scheduler.runReaction)(reaction, new Set());
(0, _effects.performEffects)();
let isStopped = false;
return () => {
if (!isStopped) {
(0, _dependencies.disableReaction)(reaction);
reactionWeakRefs.delete(reactionRef);
}
let isStopped = false;
const stopEffect = () => {
if (isStopped) {
return;
}
isStopped = true;
dependenciesManager.disableComputed(computed);
updateManager.cancelEffect(effectId);
effectComputedRefs.delete(effectComputedRef);
computedStopEffectMap.delete(computed);
};
computedStopEffectMap.set(computed, stopEffect);
return stopEffect;
};
const stopAllEffects = () => {
for (const effectComputedRef of effectComputedRefs) {
const effectComputed = effectComputedRef.deref();
const stopEffect = !effectComputed ? undefined : computedStopEffectMap.get(effectComputed);
if (stopEffect) {
stopEffect();
}
};
exports.createCoreReaction = createCoreReaction;
const stopAllReactions = () => {
for (const reactionRef of reactionWeakRefs) {
const maybeReaction = reactionRef.deref();
if (maybeReaction) {
(0, _dependencies.disableReaction)(maybeReaction);
}
};
return {
createCustomObserved,
createCustomComputed,
createObserved,
createEmptyObserved,
createComputed,
createEffect,
stopAllEffects
};
}
reactionWeakRefs.clear();
};
exports.createNodesApi = createNodesApi;
exports.stopAllReactions = stopAllReactions;
//# sourceMappingURL=nodes.js.map
{
"name": "fluidstate",
"version": "0.0.17",
"version": "0.0.18",
"description": "Library for fine-grained reactivity state management",

@@ -5,0 +5,0 @@ "repository": "https://gitlab.com/fluidstate/fluidstate",

@@ -1,10 +0,6 @@

import { Api } from "./api";
import { CreateEffect } from "./types";
export type ReactiveApi = ReturnType<typeof createReactiveApi>;
export declare const createReactiveApi: (api: Api) => {
createReactive: <T>(something: T) => T;
getReactive: <T_1 extends object>(something: T_1) => T_1 | null;
getInert: <T_2 extends object>(proxy: T_2) => T_2 | null;
getComputedKeys: <T_3>(object: T_3) => Set<string | symbol>;
createEffect: CreateEffect;
};
import { CreateReaction } from "./types";
export declare const getReactive: <T extends object>(something: T) => T | null;
export declare const getInert: <T extends object>(proxy: T) => T | null;
export declare const createReactive: <T>(something: T) => T;
export declare const createReaction: CreateReaction;
export declare const getComputedKeys: <T>(object: T) => Set<string | symbol>;

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

});
exports.createReactiveApi = void 0;
exports.getReactive = exports.getInert = exports.getComputedKeys = exports.createReactive = exports.createReaction = void 0;
var _reactiveArray = require("./reactive-array");

@@ -13,100 +13,96 @@ var _reactiveMap = require("./reactive-map");

var _reactiveUtils = require("./reactive-utils");
const createReactiveApi = api => {
// We don't necessarily have to strongly connect inert object to its proxy.
// If the user gives up all references to the proxy, it is fine to let it
// drop. It can be recreated if the user re-creates the proxy. This approach
// enables us to use `createProxy` recursively without worrying about having
// the proxy exist forever on the inert object
const inertProxyMap = new WeakMap();
const proxyInertMap = new WeakMap();
const isProxySet = new WeakSet();
const setProxy = (inertObject, proxy) => {
inertProxyMap.set(inertObject, new WeakRef(proxy));
proxyInertMap.set(proxy, inertObject);
isProxySet.add(proxy);
return proxy;
};
const getReactive = something => {
if (isProxySet.has(something)) {
return something;
} else {
const proxy = inertProxyMap.get(something)?.deref();
if (proxy) {
return proxy;
}
var _nodes = require("./nodes");
// We don't necessarily have to strongly connect inert object to its proxy.
// If the user gives up all references to the proxy, it is fine to let it
// drop. It can be recreated if the user re-creates the proxy. This approach
// enables us to use `createProxy` recursively without worrying about having
// the proxy exist forever on the inert object
const inertProxyMap = new WeakMap();
const proxyInertMap = new WeakMap();
const isProxySet = new WeakSet();
const setProxy = (inertObject, proxy) => {
inertProxyMap.set(inertObject, new WeakRef(proxy));
proxyInertMap.set(proxy, inertObject);
isProxySet.add(proxy);
return proxy;
};
const getReactive = something => {
if (isProxySet.has(something)) {
return something;
} else {
const proxy = inertProxyMap.get(something)?.deref();
if (proxy) {
return proxy;
}
return null;
};
const getInert = proxy => {
return proxyInertMap.get(proxy) ?? null;
};
const ensureInert = something => {
return (0, _reactiveUtils.isObject)(something) && getInert(something) || something;
};
const createReactive = something => {
if ((0, _reactiveUtils.isObject)(something)) {
const proxy = getReactive(something);
if (proxy) {
return proxy;
}
}
return null;
};
exports.getReactive = getReactive;
const getInert = proxy => {
return proxyInertMap.get(proxy) ?? null;
};
exports.getInert = getInert;
const ensureInert = something => {
return (0, _reactiveUtils.isObject)(something) && getInert(something) || something;
};
const createReactive = something => {
if ((0, _reactiveUtils.isObject)(something)) {
const proxy = getReactive(something);
if (proxy) {
return proxy;
}
if (Array.isArray(something)) {
const proxy = (0, _reactiveArray.createReactiveArray)(api, proxyApi, something);
}
if (Array.isArray(something)) {
const proxy = (0, _reactiveArray.createReactiveArray)(proxyApi, something);
return setProxy(something, proxy);
} else if ((0, _reactiveUtils.isObject)(something)) {
if (something instanceof Set) {
const proxy = (0, _reactiveSet.createReactiveSet)(proxyApi, something);
return setProxy(something, proxy);
} else if ((0, _reactiveUtils.isObject)(something)) {
if (something instanceof Set) {
const proxy = (0, _reactiveSet.createReactiveSet)(api, proxyApi, something);
return setProxy(something, proxy);
} else if (something instanceof Map) {
const proxy = (0, _reactiveMap.createReactiveMap)(api, proxyApi, something);
return setProxy(something, proxy);
} else {
const proxy = (0, _reactiveObject.createReactiveObject)(api, proxyApi, something);
return setProxy(something, proxy);
}
}
return something;
};
const observeAny = something => {
if (!(0, _reactiveUtils.isObject)(something)) {
return;
}
if (Array.isArray(something)) {
(0, _reactiveArray.observeReactiveArray)(proxyApi, something);
} else if (something instanceof Set) {
(0, _reactiveSet.observeReactiveSet)(proxyApi, something);
} else if (something instanceof Map) {
(0, _reactiveMap.observeReactiveMap)(proxyApi, something);
const proxy = (0, _reactiveMap.createReactiveMap)(proxyApi, something);
return setProxy(something, proxy);
} else {
(0, _reactiveObject.observeReactiveObject)(proxyApi, something);
const proxy = (0, _reactiveObject.createReactiveObject)(proxyApi, something);
return setProxy(something, proxy);
}
};
const proxyApi = {
createProxy: createReactive,
getProxy: getReactive,
ensureInert,
observeAny
};
const createEffect = (calculate, perform) => {
return api.createEffect(() => {
const result = calculate();
observeAny(result);
return result;
}, perform);
};
const getComputedKeys = object => {
if ((0, _reactiveUtils.isObject)(object) && !Array.isArray(object) && !(object instanceof Set) && !(object instanceof Map)) {
return (0, _reactiveObject.getProxyComputedKeys)(proxyApi, object);
}
return new Set();
};
return {
createReactive,
getReactive,
getInert,
getComputedKeys,
createEffect
};
}
return something;
};
exports.createReactiveApi = createReactiveApi;
exports.createReactive = createReactive;
const observeAny = something => {
if (!(0, _reactiveUtils.isObject)(something)) {
return;
}
if (Array.isArray(something)) {
(0, _reactiveArray.observeReactiveArray)(proxyApi, something);
} else if (something instanceof Set) {
(0, _reactiveSet.observeReactiveSet)(proxyApi, something);
} else if (something instanceof Map) {
(0, _reactiveMap.observeReactiveMap)(proxyApi, something);
} else {
(0, _reactiveObject.observeReactiveObject)(proxyApi, something);
}
};
const proxyApi = {
createProxy: createReactive,
getProxy: getReactive,
ensureInert,
observeAny
};
const createReaction = (calculate, effect) => {
return (0, _nodes.createCoreReaction)(() => {
const result = calculate();
observeAny(result);
return result;
}, effect);
};
exports.createReaction = createReaction;
const getComputedKeys = object => {
if ((0, _reactiveUtils.isObject)(object) && !Array.isArray(object) && !(object instanceof Set) && !(object instanceof Map)) {
return (0, _reactiveObject.getProxyComputedKeys)(proxyApi, object);
}
return new Set();
};
exports.getComputedKeys = getComputedKeys;
//# sourceMappingURL=reactive-api.js.map

@@ -1,18 +0,10 @@

import { Api } from "./api";
import { Observed, ProxyApi } from "./types";
type Reactive = {
length?: Observed<void>;
items: Array<Observed<void> | undefined>;
keys?: Observed<void>;
length?: Observed<null>;
items: Array<Observed<null> | undefined>;
keys?: Observed<null>;
};
type MarkedForDeletion = {
length: boolean;
items: Set<number>;
keys: boolean;
};
type Context = {
api: Api;
proxyApi: ProxyApi;
reactive: Reactive;
markedForDeletion: MarkedForDeletion;
getProxy: () => Array<unknown>;

@@ -26,4 +18,4 @@ };

};
export declare const createReactiveArray: <T extends unknown[]>(api: Api, proxyApi: ProxyApi, inertArr: T) => T;
export declare const createReactiveArray: <T extends unknown[]>(proxyApi: ProxyApi, inertArr: T) => T;
export declare const observeReactiveArray: <T extends unknown[]>(proxyApi: ProxyApi, proxy: T) => void;
export {};

@@ -7,64 +7,59 @@ "use strict";

exports.testData = exports.observeReactiveArray = exports.createReactiveArray = void 0;
var _collector = require("./collector");
var _nodes = require("./nodes");
var _reactiveCleanupUtils = require("./reactive-cleanup-utils");
var _reactiveUtils = require("./reactive-utils");
const scheduleContextCleanup = (0, _reactiveCleanupUtils.debounceCleanup)(context => {
if (context.markedForDeletion.length) {
delete context.reactive.length;
context.markedForDeletion.length = false;
}
if (context.markedForDeletion.keys) {
delete context.reactive.keys;
context.markedForDeletion.keys = false;
}
for (const index of context.markedForDeletion.items) {
context.reactive.items[index] = undefined;
}
context.markedForDeletion.items.clear();
let index = context.reactive.items.length - 1;
for (; index >= 0; index--) {
if (context.reactive.items[index]) {
break;
var _scheduler = require("./scheduler");
const cleanupLength = reactive => {
reactive.length = undefined;
};
const cleanupItem = (reactive, p) => {
reactive.items[p] = undefined;
let index = reactive.items.length - 1;
if (`${p}` === `${index}`) {
for (; index >= 0; index--) {
if (reactive.items[index]) {
break;
}
}
reactive.items.length = index + 1;
}
context.reactive.items.splice(index + 1);
});
const createItemLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, (context, p) => {
context.markedForDeletion.items.add(p);
}, (context, p) => {
context.markedForDeletion.items.delete(p);
});
const createKeysLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, context => {
context.markedForDeletion.keys = true;
}, context => {
context.markedForDeletion.keys = false;
});
const createLengthLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, context => {
context.markedForDeletion.length = true;
}, context => {
context.markedForDeletion.length = false;
});
};
const cleanupKeys = reactive => {
reactive.keys = undefined;
};
const readItem = (context, p) => {
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.items[p];
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createItemLifeCycle(context, p));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupItem(context.reactive, p));
context.reactive.items[p] = observed;
}
context.api.get(observed);
(0, _nodes.get)(observed);
};
const readLength = context => {
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.length;
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createLengthLifeCycle(context));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupLength(context.reactive));
context.reactive.length = observed;
}
context.api.get(observed);
(0, _nodes.get)(observed);
};
const readKeys = context => {
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.keys;
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createKeysLifeCycle(context));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupKeys(context.reactive));
context.reactive.keys = observed;
}
context.api.get(observed);
(0, _nodes.get)(observed);
};

@@ -74,3 +69,3 @@ const notifyItem = (context, p) => {

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -81,3 +76,3 @@ };

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -88,3 +83,3 @@ };

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -116,3 +111,3 @@ };

if (result) {
context.api.batch(() => {
(0, _scheduler.batch)(() => {
if (isChanged && p !== "length") {

@@ -144,3 +139,3 @@ notifyItem(context, p);

if (result) {
context.api.batch(() => {
(0, _scheduler.batch)(() => {
if (isChanged && p !== "length") {

@@ -170,5 +165,4 @@ notifyItem(context, p);

exports.testData = testData;
const createReactiveArray = (api, proxyApi, inertArr) => {
const createReactiveArray = (proxyApi, inertArr) => {
const context = {
api,
proxyApi,

@@ -178,7 +172,2 @@ reactive: {

},
markedForDeletion: {
length: false,
items: new Set(),
keys: false
},
getProxy: () => proxy

@@ -185,0 +174,0 @@ };

@@ -1,18 +0,10 @@

import { Api } from "./api";
import { Observed, ProxyApi } from "./types";
type Reactive = {
keys: Map<unknown, Observed<void>>;
values: Map<unknown, Observed<void>>;
size?: Observed<void>;
keys: Map<unknown, Observed<null>>;
values: Map<unknown, Observed<null>>;
size?: Observed<null>;
};
type MarkedForDeletion = {
keys: Set<unknown>;
values: Set<unknown>;
size: boolean;
};
type Context = {
api: Api;
proxyApi: ProxyApi;
reactive: Reactive;
markedForDeletion: MarkedForDeletion;
getProxy: () => Map<unknown, unknown>;

@@ -26,4 +18,4 @@ };

};
export declare const createReactiveMap: <T extends Map<unknown, unknown>>(api: Api, proxyApi: ProxyApi, inertMap: T) => T;
export declare const createReactiveMap: <T extends Map<unknown, unknown>>(proxyApi: ProxyApi, inertMap: T) => T;
export declare const observeReactiveMap: <T extends Map<unknown, unknown>>(proxyApi: ProxyApi, proxy: T) => void;
export {};

@@ -7,34 +7,15 @@ "use strict";

exports.testData = exports.observeReactiveMap = exports.createReactiveMap = void 0;
var _collector = require("./collector");
var _nodes = require("./nodes");
var _reactiveCleanupUtils = require("./reactive-cleanup-utils");
var _reactiveUtils = require("./reactive-utils");
const scheduleContextCleanup = (0, _reactiveCleanupUtils.debounceCleanup)(context => {
if (context.markedForDeletion.size) {
delete context.reactive.size;
context.markedForDeletion.size = false;
}
for (const key of context.markedForDeletion.keys) {
context.reactive.keys.delete(key);
}
for (const key of context.markedForDeletion.values) {
context.reactive.values.delete(key);
}
context.markedForDeletion.keys.clear();
context.markedForDeletion.values.clear();
});
const createKeysLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, (context, key) => {
context.markedForDeletion.keys.add(key);
}, (context, key) => {
context.markedForDeletion.keys.delete(key);
});
const createValuesLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, (context, key) => {
context.markedForDeletion.values.add(key);
}, (context, key) => {
context.markedForDeletion.values.delete(key);
});
const createSizeLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, context => {
context.markedForDeletion.size = true;
}, context => {
context.markedForDeletion.size = false;
});
var _scheduler = require("./scheduler");
const cleanupKey = (reactive, key) => {
reactive.keys.delete(key);
};
const cleanupValue = (reactive, key) => {
reactive.values.delete(key);
};
const cleanupSize = reactive => {
reactive.size = undefined;
};
const notifyKey = (context, key) => {

@@ -46,3 +27,3 @@ if (!context) {

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -56,3 +37,3 @@ };

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -66,3 +47,3 @@ };

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -74,8 +55,12 @@ };

}
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.keys.get(key);
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createKeysLifeCycle(context, key));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupKey(context.reactive, key));
context.reactive.keys.set(key, observed);
}
context.api.get(observed);
(0, _nodes.get)(observed);
};

@@ -86,8 +71,12 @@ const readValue = (context, key) => {

}
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.values.get(key);
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createValuesLifeCycle(context, key));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupValue(context.reactive, key));
context.reactive.values.set(key, observed);
}
context.api.get(observed);
(0, _nodes.get)(observed);
};

@@ -98,8 +87,12 @@ const readSize = context => {

}
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.size;
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createSizeLifeCycle(context));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupSize(context.reactive));
context.reactive.size = observed;
}
context.api.get(observed);
(0, _nodes.get)(observed);
};

@@ -162,3 +155,3 @@ const createReactiveMapProxyHandler = fullContext => ({

Map.prototype.set.call(self, keyInert, valueInert);
context.api.batch(() => {
(0, _scheduler.batch)(() => {
if (!itemAlreadyExists) {

@@ -182,3 +175,3 @@ notifyKey(context, keyInert);

if (result) {
context.api.batch(() => {
(0, _scheduler.batch)(() => {
notifyKey(context, keyInert);

@@ -196,3 +189,3 @@ if (isValueChanged) {

const isAlreadyEmpty = self.size === 0;
context.api.batch(() => {
(0, _scheduler.batch)(() => {
Map.prototype.forEach.call(self, key => {

@@ -248,5 +241,4 @@ const isValueChanged = !Object.is(Map.prototype.get.call(self, key), undefined);

exports.testData = testData;
const createReactiveMap = (api, proxyApi, inertMap) => {
const createReactiveMap = (proxyApi, inertMap) => {
const context = {
api,
proxyApi,

@@ -257,7 +249,2 @@ reactive: {

},
markedForDeletion: {
keys: new Set(),
values: new Set(),
size: false
},
getProxy: () => proxy

@@ -264,0 +251,0 @@ };

@@ -1,18 +0,11 @@

import { Api } from "./api";
import { Computed, Observed, ProxyApi } from "./types";
type Reactive = {
values: {
[k: string | symbol | number]: Observed<void> | Computed<unknown>;
[k: string | symbol | number]: Observed<null> | Computed<unknown>;
};
keys?: Observed<void>;
keys?: Observed<null>;
};
type MarkedForDeletion = {
values: Set<string | symbol | number>;
keys: boolean;
};
type Context = {
api: Api;
proxyApi: ProxyApi;
reactive: Reactive;
markedForDeletion: MarkedForDeletion;
getProxy: () => object;

@@ -26,5 +19,5 @@ };

};
export declare const createReactiveObject: <T extends object>(api: Api, proxyApi: ProxyApi, inertObject: T) => T;
export declare const createReactiveObject: <T extends object>(proxyApi: ProxyApi, inertObject: T) => T;
export declare const observeReactiveObject: <T extends object>(proxyApi: ProxyApi, proxy: T) => void;
export declare const getProxyComputedKeys: <T extends object>(proxyApi: ProxyApi, proxy: T) => Set<string | symbol>;
export {};

@@ -7,53 +7,50 @@ "use strict";

exports.testData = exports.observeReactiveObject = exports.getProxyComputedKeys = exports.createReactiveObject = void 0;
var _collector = require("./collector");
var _dependencies = require("./dependencies");
var _nodes = require("./nodes");
var _reactiveCleanupUtils = require("./reactive-cleanup-utils");
var _reactiveUtils = require("./reactive-utils");
const scheduleContextCleanup = (0, _reactiveCleanupUtils.debounceCleanup)(context => {
if (context.markedForDeletion.keys) {
delete context.reactive.keys;
context.markedForDeletion.keys = false;
var _scheduler = require("./scheduler");
var _utils = require("./utils");
const cleanupValue = (reactive, p) => {
const maybeComputed = reactive.values[p];
if ((0, _utils.isComputed)(maybeComputed)) {
(0, _dependencies.disableComputed)(maybeComputed);
}
for (const key of context.markedForDeletion.values) {
const node = context.reactive.values[key];
delete context.reactive.values[key];
if ((0, _nodes.isComputed)(node)) {
context.api.disableComputed(node);
}
}
context.markedForDeletion.values.clear();
});
const createValueLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, (context, p) => {
context.markedForDeletion.values.add(p);
}, (context, p) => {
context.markedForDeletion.values.delete(p);
});
const createKeysLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, context => {
context.markedForDeletion.keys = true;
}, context => {
context.markedForDeletion.keys = false;
});
const readComputedValue = (context, p, computed) => {
delete reactive.values[p];
};
const cleanupKeys = reactive => {
reactive.keys = undefined;
};
const readComputedValue = (context, p, calculate) => {
let node = context.reactive.values[p];
if (!node || !(0, _nodes.isComputed)(node)) {
if (!node || !(0, _utils.isComputed)(node)) {
const proxy = context.getProxy();
node = context.api.createCustomComputed((0, _nodes.createDefaultInertControl)(null), (0, _nodes.createDefaultCalculateControl)(computed.bind(proxy)), createValueLifeCycle(context, p));
node = (0, _reactiveUtils.createCleanupComputed)(calculate.bind(proxy), () => cleanupValue(context.reactive, p));
context.reactive.values[p] = node;
}
return context.api.get(node);
return (0, _nodes.get)(node);
};
const readObservedValue = (context, p) => {
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let node = context.reactive.values[p];
if (!node || !(0, _nodes.isObserved)(node)) {
node = context.api.createCustomObserved(_nodes.emptyInertControl, createValueLifeCycle(context, p));
if (!node || !(0, _utils.isObserved)(node)) {
node = (0, _reactiveUtils.createCleanupObserved)(() => cleanupValue(context.reactive, p));
context.reactive.values[p] = node;
}
context.api.get(node);
(0, _nodes.get)(node);
};
const readKeys = context => {
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let node = context.reactive.keys;
if (!node) {
node = context.api.createCustomObserved(_nodes.emptyInertControl, createKeysLifeCycle(context));
node = (0, _reactiveUtils.createCleanupObserved)(() => cleanupKeys(context.reactive));
context.reactive.keys = node;
}
context.api.get(node);
(0, _nodes.get)(node);
};

@@ -63,3 +60,3 @@ const notifyValue = (context, p) => {

if (node) {
context.api.notify(node);
(0, _scheduler.notify)(node);
}

@@ -70,3 +67,3 @@ };

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -78,3 +75,3 @@ };

let result;
context.api.batch(() => {
(0, _scheduler.batch)(() => {
result = Reflect.apply(target, thisArg, argArray);

@@ -113,3 +110,3 @@ });

if (result) {
context.api.batch(() => {
(0, _scheduler.batch)(() => {
if (isChanged) {

@@ -141,3 +138,3 @@ notifyValue(context, p);

if (result) {
context.api.batch(() => {
(0, _scheduler.batch)(() => {
if (isChanged) {

@@ -165,5 +162,4 @@ notifyValue(context, p);

exports.testData = testData;
const createReactiveObject = (api, proxyApi, inertObject) => {
const createReactiveObject = (proxyApi, inertObject) => {
const context = {
api,
proxyApi,

@@ -173,6 +169,2 @@ reactive: {

},
markedForDeletion: {
values: new Set(),
keys: false
},
getProxy: () => proxy

@@ -179,0 +171,0 @@ };

@@ -1,16 +0,9 @@

import { Api } from "./api";
import { Observed, ProxyApi } from "./types";
type Reactive = {
items: Map<unknown, Observed<void>>;
size?: Observed<void>;
items: Map<unknown, Observed<null>>;
size?: Observed<null>;
};
type MarkedForDeletion = {
items: Set<unknown>;
size: boolean;
};
type Context = {
api: Api;
proxyApi: ProxyApi;
reactive: Reactive;
markedForDeletion: MarkedForDeletion;
getProxy: () => Set<unknown>;

@@ -24,4 +17,4 @@ };

};
export declare const createReactiveSet: <T extends Set<unknown>>(api: Api, proxyApi: ProxyApi, inertSet: T) => T;
export declare const createReactiveSet: <T extends Set<unknown>>(proxyApi: ProxyApi, inertSet: T) => T;
export declare const observeReactiveSet: <T extends Set<unknown>>(proxyApi: ProxyApi, proxy: T) => void;
export {};

@@ -7,25 +7,12 @@ "use strict";

exports.testData = exports.observeReactiveSet = exports.createReactiveSet = void 0;
var _collector = require("./collector");
var _nodes = require("./nodes");
var _reactiveCleanupUtils = require("./reactive-cleanup-utils");
var _reactiveUtils = require("./reactive-utils");
const scheduleContextCleanup = (0, _reactiveCleanupUtils.debounceCleanup)(context => {
if (context.markedForDeletion.size) {
delete context.reactive.size;
context.markedForDeletion.size = false;
}
for (const key of context.markedForDeletion.items) {
context.reactive.items.delete(key);
}
context.markedForDeletion.items.clear();
});
const createItemLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, (context, item) => {
context.markedForDeletion.items.add(item);
}, (context, item) => {
context.markedForDeletion.items.delete(item);
});
const createSizeLifeCycle = (0, _reactiveUtils.getCreateLifeCycle)(scheduleContextCleanup, context => {
context.markedForDeletion.size = true;
}, context => {
context.markedForDeletion.size = false;
});
var _scheduler = require("./scheduler");
const cleanupItem = (reactive, key) => {
reactive.items.delete(key);
};
const cleanupSize = reactive => {
reactive.size = undefined;
};
const notifyItem = (context, item) => {

@@ -37,3 +24,3 @@ if (!context) {

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -47,3 +34,3 @@ };

if (observed) {
context.api.notify(observed);
(0, _scheduler.notify)(observed);
}

@@ -55,8 +42,12 @@ };

}
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.items.get(item);
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createItemLifeCycle(context, item));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupItem(context.reactive, item));
context.reactive.items.set(item, observed);
}
context.api.get(observed);
(0, _nodes.get)(observed);
};

@@ -67,8 +58,12 @@ const readSize = context => {

}
if (!_collector.collector.isCollecting()) {
(0, _scheduler.triggerUpdate)();
return;
}
let observed = context.reactive.size;
if (!observed) {
observed = context.api.createCustomObserved(_nodes.emptyInertControl, createSizeLifeCycle(context));
observed = (0, _reactiveUtils.createCleanupObserved)(() => cleanupSize(context.reactive));
context.reactive.size = observed;
}
context.api.get(observed);
(0, _nodes.get)(observed);
};

@@ -123,3 +118,3 @@ const createReactiveSetProxyHandler = fullContext => ({

if (!itemAlreadyExists) {
context.api.batch(() => {
(0, _scheduler.batch)(() => {
notifyItem(context, valueInert);

@@ -136,3 +131,3 @@ notifySize(context);

if (result) {
context.api.batch(() => {
(0, _scheduler.batch)(() => {
notifyItem(context, valueInert);

@@ -147,3 +142,3 @@ notifySize(context);

const isAlreadyEmpty = self.size === 0;
context.api.batch(() => {
(0, _scheduler.batch)(() => {
Set.prototype.forEach.call(self, value => {

@@ -184,5 +179,4 @@ Set.prototype.delete.call(self, value);

exports.testData = testData;
const createReactiveSet = (api, proxyApi, inertSet) => {
const createReactiveSet = (proxyApi, inertSet) => {
const context = {
api,
proxyApi,

@@ -192,6 +186,2 @@ reactive: {

},
markedForDeletion: {
items: new Set(),
size: false
},
getProxy: () => proxy

@@ -198,0 +188,0 @@ };

@@ -1,2 +0,4 @@

import { LifeCycle } from "./types";
import { Computed, Observed } from "./types";
export declare const createCleanupObserved: (cleanup: () => void) => Observed<null>;
export declare const createCleanupComputed: <T>(calculate: () => T, cleanup: () => void) => Computed<T>;
export declare const isObject: <T>(value: T) => value is T & object;

@@ -11,2 +13,1 @@ export declare const getDescriptor: (inertObject: object, p: string | symbol | number) => {

export declare const getAllGetterKeys: (inertObject: object) => Set<string | symbol>;
export declare const getCreateLifeCycle: <Args extends unknown[]>(scheduleContextCleanup: (context: Args[0]) => void, mark: (...args: Args) => void, clearMark: (...args: Args) => void) => (...args: Args) => LifeCycle;

@@ -6,4 +6,28 @@ "use strict";

});
exports.isObject = exports.getDescriptor = exports.getCreateLifeCycle = exports.getAllGetterKeys = void 0;
exports.isObject = exports.getDescriptor = exports.getAllGetterKeys = exports.createCleanupObserved = exports.createCleanupComputed = void 0;
var _dependencies = require("./dependencies");
var _nodes = require("./nodes");
const appendListener = (listeners, node, listener) => {
const maybeListener = listeners.get(node);
if (maybeListener) {
listeners.set(node, () => {
maybeListener();
listener();
});
} else {
listeners.set(node, listener);
}
};
const createCleanupObserved = cleanup => {
const observed = (0, _nodes.createObserved)(null);
appendListener(_dependencies.becomeNonReactiveListeners, observed, cleanup);
return observed;
};
exports.createCleanupObserved = createCleanupObserved;
const createCleanupComputed = (calculate, cleanup) => {
const computed = (0, _nodes.createComputed)(calculate);
appendListener(_dependencies.becomeNonReactiveListeners, computed, cleanup);
return computed;
};
exports.createCleanupComputed = createCleanupComputed;
const isObject = value => {

@@ -44,48 +68,2 @@ return value && typeof value === "object";

exports.getAllGetterKeys = getAllGetterKeys;
const isDeeplyDerived = node => {
if (node.derived.size === 0) {
return false;
}
for (const derived of node.derived) {
if (!derived.lifeCycle || derived.lifeCycle.isDerived) {
return true;
}
}
return false;
};
const propagateDerivedChanges = computed => {
for (const dependency of computed.dependencies) {
dependency.lifeCycle?.onDerivedChanged(dependency);
}
};
const getCreateLifeCycle = (scheduleContextCleanup, mark, clearMark) => {
return (...args) => {
const markForDeletion = () => {
mark(...args);
scheduleContextCleanup(args[0]);
};
markForDeletion();
let currentIsDerived = false;
return {
get isDerived() {
return currentIsDerived;
},
onDerivedChanged(node) {
const isDerived = isDeeplyDerived(node);
if (currentIsDerived != isDerived) {
currentIsDerived = isDerived;
if (!isDerived) {
markForDeletion();
} else {
clearMark(...args);
}
if ((0, _nodes.isComputed)(node)) {
propagateDerivedChanges(node);
}
}
}
};
};
};
exports.getCreateLifeCycle = getCreateLifeCycle;
//# sourceMappingURL=reactive-utils.js.map

@@ -7,27 +7,35 @@ export type ProxyApi = {

};
export type InertControl<T> = {
get: () => T;
set: (value: T) => void;
equal: (value: T) => boolean;
export declare enum ReactiveType {
Observed = 0,
Reaction = 1,
Computed = 2
}
export declare enum UpdateStatus {
ChangedCached = 0,
Changed = 1,
MaybeChanged = 2,
Unchanged = 3
}
export type Node<T> = Observed<T> | Computed<T>;
export type DerivedNode<T> = Computed<T> | Reaction<T>;
export type Derived<T> = {
dependencies: Set<Node<unknown>>;
calculate: () => T;
};
export type LifeCycle = {
isDerived: boolean;
onDerivedChanged: (node: Node<unknown>) => void;
export type ReactiveValue<T> = {
value: T;
reactions: Set<Reaction<unknown>>;
computeds: Set<Computed<unknown>>;
};
export type Node<T> = {
inert: InertControl<T>;
derived: Set<Computed<unknown>>;
lifeCycle?: LifeCycle;
export type Reaction<T> = Derived<T> & {
type: ReactiveType.Reaction;
effect: (result: T) => void;
};
export type Observed<T> = Node<T>;
export type Computed<T> = Node<T> & {
getCalculate: () => () => T;
dependencies: Set<Node<unknown>>;
export type Observed<T> = ReactiveValue<T> & {
type: ReactiveType.Observed;
};
export type Configuration = {
scheduleFunction: (update: () => void) => any;
cancelFunction: (scheduledId: any) => void;
reactiveCleanupDebounceTime: number;
export type Computed<T> = Derived<T> & ReactiveValue<T> & {
type: ReactiveType.Computed;
};
export type EffectStop = () => void;
export type CreateEffect = <ComputedValue, Result>(calculate: () => ComputedValue, perform: (computedValue: ComputedValue) => Result) => EffectStop;
export type ReactionStop = () => void;
export type CreateReaction = <T>(calculate: () => T, effect: (result: T) => void) => ReactionStop;

@@ -6,2 +6,18 @@ "use strict";

});
exports.UpdateStatus = exports.ReactiveType = void 0;
let ReactiveType;
exports.ReactiveType = ReactiveType;
(function (ReactiveType) {
ReactiveType[ReactiveType["Observed"] = 0] = "Observed";
ReactiveType[ReactiveType["Reaction"] = 1] = "Reaction";
ReactiveType[ReactiveType["Computed"] = 2] = "Computed";
})(ReactiveType || (exports.ReactiveType = ReactiveType = {}));
let UpdateStatus;
exports.UpdateStatus = UpdateStatus;
(function (UpdateStatus) {
UpdateStatus[UpdateStatus["ChangedCached"] = 0] = "ChangedCached";
UpdateStatus[UpdateStatus["Changed"] = 1] = "Changed";
UpdateStatus[UpdateStatus["MaybeChanged"] = 2] = "MaybeChanged";
UpdateStatus[UpdateStatus["Unchanged"] = 3] = "Unchanged";
})(UpdateStatus || (exports.UpdateStatus = UpdateStatus = {}));
//# sourceMappingURL=types.js.map

@@ -1,3 +0,3 @@

export declare function getSetRemoved<T>(previousSet: Set<T>, newSet: Set<T>): Generator<T, void, unknown>;
export declare function getSetAdded<T>(previousSet: Set<T>, newSet: Set<T>): Generator<T, void, unknown>;
export declare const cloneSetToEmpty: <T>(fromSet: Set<T>, emptySet: Set<T>) => void;
import { Observed, Computed, Reaction } from "./types";
export declare const isComputed: <T>(node: Computed<T> | Reaction<T> | Observed<T>) => node is Computed<T>;
export declare const isObserved: <T>(node: Computed<T> | Reaction<T> | Observed<T>) => node is Observed<T>;

@@ -6,25 +6,12 @@ "use strict";

});
exports.cloneSetToEmpty = void 0;
exports.getSetAdded = getSetAdded;
exports.getSetRemoved = getSetRemoved;
function* getSetRemoved(previousSet, newSet) {
for (let previousElement of previousSet) {
if (!newSet.has(previousElement)) {
yield previousElement;
}
}
}
function* getSetAdded(previousSet, newSet) {
for (let newElement of newSet) {
if (!previousSet.has(newElement)) {
yield newElement;
}
}
}
const cloneSetToEmpty = (fromSet, emptySet) => {
for (let fromElement of fromSet) {
emptySet.add(fromElement);
}
exports.isObserved = exports.isComputed = void 0;
var _types = require("./types");
const isComputed = node => {
return node.type === _types.ReactiveType.Computed;
};
exports.cloneSetToEmpty = cloneSetToEmpty;
exports.isComputed = isComputed;
const isObserved = node => {
return node.type === _types.ReactiveType.Observed;
};
exports.isObserved = isObserved;
//# sourceMappingURL=utils.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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