fluidstate
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,28 @@ | ||
export { createApi } from "./api"; | ||
export { createReactiveApi } from "./reactive-api"; | ||
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; | ||
batch: (update: () => void) => void; | ||
configure: (newConfiguration: Partial<import("./types").Configuration>) => void; | ||
createCustomObserved: <T_3>(inert: import("./types").InertControl<T_3>) => import("./types").Observed<T_3>; | ||
createEmptyObserved: () => import("./types").Observed<void>; | ||
createObserved: <T_4>(value: T_4) => import("./types").Observed<T_4>; | ||
createCustomComputed: <T_5>(inert: import("./types").InertControl<T_5>, getCalculate: () => () => T_5) => 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; | ||
}; | ||
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, batch: (update: () => void) => 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 }; | ||
export { configure, batch, createEffect, createReactive, getInert, getReactive, getComputedKeys, }; |
25
index.js
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.configure = exports.batch = void 0; | ||
Object.defineProperty(exports, "createApi", { | ||
@@ -13,2 +14,3 @@ enumerable: true, | ||
}); | ||
exports.createReactive = exports.createEffect = void 0; | ||
Object.defineProperty(exports, "createReactiveApi", { | ||
@@ -20,4 +22,27 @@ enumerable: true, | ||
}); | ||
exports.getReactive = exports.getInert = exports.getComputedKeys = exports.defaultReactiveApi = exports.defaultApi = void 0; | ||
var _api = require("./api"); | ||
var _reactiveApi = require("./reactive-api"); | ||
const defaultApi = (0, _api.createApi)(); | ||
exports.defaultApi = defaultApi; | ||
const defaultReactiveApi = (0, _reactiveApi.createReactiveApi)(defaultApi); | ||
exports.defaultReactiveApi = defaultReactiveApi; | ||
const { | ||
configure, | ||
batch | ||
} = defaultApi; | ||
exports.batch = batch; | ||
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; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "fluidstate", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Library for fine-grained reactivity state management", | ||
@@ -5,0 +5,0 @@ "repository": "https://gitlab.com/guitarino/fluidstate", |
@@ -8,3 +8,4 @@ import { Api } from "./api"; | ||
getInert: <T_2 extends object>(proxy: T_2) => T_2 | null; | ||
getComputedKeys: <T_3>(object: T_3) => Set<string | symbol>; | ||
createEffect: CreateEffect; | ||
}; |
@@ -27,3 +27,9 @@ "use strict"; | ||
}; | ||
const getProxy = something => { | ||
/** | ||
* Given an inert object that has a reactive wrapper / proxy, return its reactive | ||
* wrapper / proxy. If the object doesn't have the reactive wrapper / proxy, | ||
* null is returned | ||
*/ | ||
const getReactive = something => { | ||
if (isProxySet.has(something)) { | ||
@@ -39,2 +45,6 @@ return something; | ||
}; | ||
/** | ||
* Given a reactive object / wrapper / proxy, return its original inert object | ||
*/ | ||
const getInert = proxy => { | ||
@@ -46,5 +56,14 @@ return proxyInertMap.get(proxy) ?? null; | ||
}; | ||
const createProxy = something => { | ||
/** | ||
* Creates a reactive wrapper (proxy) around any object. Arrays, sets, maps and | ||
* regular objects are natively supported. Effects / computed properties that access | ||
* items of these objects (such as keys, values, etc) automaticlaly subscribe to | ||
* them. The reactive wrapper does not create a clone of the object - the original | ||
* object is still used for all storage and is changed as changes are made to the | ||
* reactive wrapper | ||
*/ | ||
const createReactive = something => { | ||
if ((0, _reactiveUtils.isObject)(something)) { | ||
const proxy = getProxy(something); | ||
const proxy = getReactive(something); | ||
if (proxy) { | ||
@@ -86,7 +105,15 @@ return proxy; | ||
const proxyApi = { | ||
createProxy, | ||
getProxy, | ||
createProxy: createReactive, | ||
getProxy: getReactive, | ||
ensureInert, | ||
observeAny | ||
}; | ||
/** | ||
* 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 | ||
*/ | ||
const createEffect = (calculate, perform) => { | ||
@@ -99,6 +126,18 @@ return api.createEffect(() => { | ||
}; | ||
/** | ||
* Given an object, get its computed keys. If a non-reactive object is provided, | ||
* get keys that would become computed if object was to become reactive | ||
*/ | ||
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: createProxy, | ||
getReactive: getProxy, | ||
createReactive, | ||
getReactive, | ||
getInert, | ||
getComputedKeys, | ||
createEffect | ||
@@ -105,0 +144,0 @@ }; |
@@ -26,2 +26,3 @@ import { Api } from "./api"; | ||
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 {}; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.testData = exports.observeReactiveObject = exports.createReactiveObject = void 0; | ||
exports.testData = exports.observeReactiveObject = exports.getProxyComputedKeys = exports.createReactiveObject = void 0; | ||
var _nodes = require("./nodes"); | ||
@@ -173,3 +173,3 @@ var _reactiveUtils = require("./reactive-utils"); | ||
const observeReactiveObject = (proxyApi, proxy) => { | ||
const keys = new Set([...Reflect.ownKeys(proxy), ...(0, _reactiveUtils.getAllGetterKeys)(proxyApi.ensureInert(proxy))]); | ||
const keys = new Set([...Reflect.ownKeys(proxy), ...getProxyComputedKeys(proxyApi, proxy)]); | ||
for (const key of keys) { | ||
@@ -180,2 +180,6 @@ proxyApi.observeAny(proxy[key]); | ||
exports.observeReactiveObject = observeReactiveObject; | ||
const getProxyComputedKeys = (proxyApi, proxy) => { | ||
return (0, _reactiveUtils.getAllGetterKeys)(proxyApi.ensureInert(proxy)); | ||
}; | ||
exports.getProxyComputedKeys = getProxyComputedKeys; | ||
//# sourceMappingURL=reactive-object.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
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
191326
1873