fluidstate
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -22,5 +22,2 @@ "use strict"; | ||
const { | ||
set, | ||
notify, | ||
get, | ||
createCustomObserved, | ||
@@ -35,5 +32,5 @@ createObserved, | ||
return { | ||
set, | ||
notify, | ||
get, | ||
set: updateManager.set, | ||
notify: updateManager.notify, | ||
get: updateManager.get, | ||
configure, | ||
@@ -40,0 +37,0 @@ getConfiguration, |
import { DependenciesManager } from "./dependencies-manager"; | ||
import { Computed, CreateEffect, InertControl, LifeCycle, Node, Observed } from "./types"; | ||
import { Computed, CreateEffect, InertControl, LifeCycle, Observed } from "./types"; | ||
import { UpdateManager } from "./update-manager"; | ||
@@ -11,12 +11,9 @@ export declare const isNode: (value: unknown) => value is Computed<unknown> | Observed<unknown>; | ||
export declare const createNodesApi: (dependenciesManager: DependenciesManager, updateManager: UpdateManager) => { | ||
set: <T>(node: Node<T>, newValue: T) => void; | ||
notify: <T_1>(node: Node<T_1>) => void; | ||
get: <T_2>(node: Node<T_2>) => T_2; | ||
createCustomObserved: <T_3>(inert: InertControl<T_3>, lifeCycle?: LifeCycle) => Observed<T_3>; | ||
createCustomComputed: <T_4>(inert: InertControl<T_4>, getCalculate: () => () => T_4, lifeCycle?: LifeCycle) => Computed<T_4>; | ||
createObserved: <T_5>(value: T_5) => Observed<T_5>; | ||
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_6>(calculate: () => T_6) => Computed<T_6>; | ||
createComputed: <T_3>(calculate: () => T_3) => Computed<T_3>; | ||
createEffect: CreateEffect; | ||
stopAllEffects: () => void; | ||
}; |
12
nodes.js
@@ -50,11 +50,2 @@ "use strict"; | ||
const effectComputedRefs = new Set(); | ||
const set = (node, newValue) => { | ||
updateManager.set(node, newValue); | ||
}; | ||
const notify = node => { | ||
updateManager.notify(node); | ||
}; | ||
const get = node => { | ||
return updateManager.get(node); | ||
}; | ||
const createCustomObserved = (inert, lifeCycle) => { | ||
@@ -129,5 +120,2 @@ const observed = { | ||
return { | ||
set, | ||
notify, | ||
get, | ||
createCustomObserved, | ||
@@ -134,0 +122,0 @@ createCustomComputed, |
{ | ||
"name": "fluidstate", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "Library for fine-grained reactivity state management", | ||
@@ -5,0 +5,0 @@ "repository": "https://gitlab.com/fluidstate/fluidstate", |
@@ -9,2 +9,3 @@ "use strict"; | ||
var _reactiveCleanupUtils = require("./reactive-cleanup-utils"); | ||
var _reactiveUtils = require("./reactive-utils"); | ||
const scheduleContextCleanup = (0, _reactiveCleanupUtils.debounceCleanup)(context => { | ||
@@ -31,50 +32,17 @@ if (context.markedForDeletion.length) { | ||
}); | ||
const createItemLifeCycle = (context, p) => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.items.add(p); | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.items.delete(p); | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
const createKeysLifeCycle = context => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.keys = true; | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.keys = false; | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
const createLengthLifeCycle = context => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.length = true; | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.length = false; | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
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 readItem = (context, p) => { | ||
@@ -81,0 +49,0 @@ let observed = context.reactive.items[p]; |
@@ -9,2 +9,3 @@ "use strict"; | ||
var _reactiveCleanupUtils = require("./reactive-cleanup-utils"); | ||
var _reactiveUtils = require("./reactive-utils"); | ||
const scheduleContextCleanup = (0, _reactiveCleanupUtils.debounceCleanup)(context => { | ||
@@ -24,50 +25,17 @@ if (context.markedForDeletion.size) { | ||
}); | ||
const createKeysLifeCycle = (context, key) => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.keys.add(key); | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.keys.delete(key); | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
const createValuesLifeCycle = (context, key) => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.values.add(key); | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.values.delete(key); | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
const createSizeLifeCycle = context => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.size = true; | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.size = false; | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
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; | ||
}); | ||
const notifyKey = (context, key) => { | ||
@@ -74,0 +42,0 @@ if (!context) { |
@@ -20,34 +20,12 @@ "use strict"; | ||
}); | ||
const createValueLifeCycle = (context, p) => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.values.add(p); | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.values.delete(p); | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
const createKeysLifeCycle = context => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.keys = true; | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.keys = false; | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
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) => { | ||
@@ -54,0 +32,0 @@ let node = context.reactive.values[p]; |
@@ -9,2 +9,3 @@ "use strict"; | ||
var _reactiveCleanupUtils = require("./reactive-cleanup-utils"); | ||
var _reactiveUtils = require("./reactive-utils"); | ||
const scheduleContextCleanup = (0, _reactiveCleanupUtils.debounceCleanup)(context => { | ||
@@ -20,34 +21,12 @@ if (context.markedForDeletion.size) { | ||
}); | ||
const createItemLifeCycle = (context, item) => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.items.add(item); | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.items.delete(item); | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
const createSizeLifeCycle = context => { | ||
const markForDeletion = () => { | ||
context.markedForDeletion.size = true; | ||
scheduleContextCleanup(context); | ||
}; | ||
markForDeletion(); | ||
return { | ||
onDerivedChanged(node) { | ||
if (node.derived.size > 0) { | ||
context.markedForDeletion.size = false; | ||
} else { | ||
markForDeletion(); | ||
} | ||
} | ||
}; | ||
}; | ||
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; | ||
}); | ||
const notifyItem = (context, item) => { | ||
@@ -54,0 +33,0 @@ if (!context) { |
@@ -0,1 +1,2 @@ | ||
import { LifeCycle } from "./types"; | ||
export declare const isObject: <T>(value: T) => value is T & object; | ||
@@ -10,1 +11,2 @@ 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,3 +6,4 @@ "use strict"; | ||
}); | ||
exports.isObject = exports.getDescriptor = exports.getAllGetterKeys = void 0; | ||
exports.isObject = exports.getDescriptor = exports.getCreateLifeCycle = exports.getAllGetterKeys = void 0; | ||
var _nodes = require("./nodes"); | ||
const isObject = value => { | ||
@@ -43,2 +44,48 @@ 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 |
@@ -13,2 +13,3 @@ export type ProxyApi = { | ||
export type LifeCycle = { | ||
isDerived: boolean; | ||
onDerivedChanged: (node: Node<unknown>) => void; | ||
@@ -15,0 +16,0 @@ }; |
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
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
215711
2174