fluidstate
Advanced tools
Comparing version 0.0.10 to 0.0.11
10
nodes.js
@@ -86,8 +86,14 @@ "use strict"; | ||
const createEffect = (calculate, perform) => { | ||
const effectId = {}; | ||
const effectId = Symbol(); | ||
let isInitial = true; | ||
let isEffectScheduled = false; | ||
const computed = createComputed(() => { | ||
const computedValue = calculate(); | ||
updateManager.addEffect(effectId, () => perform(computedValue)); | ||
isEffectScheduled = updateManager.addEffect(effectId, isInitial, () => perform(computedValue)); | ||
return computedValue; | ||
}); | ||
isInitial = false; | ||
if (!isEffectScheduled) { | ||
perform(computed.inert.get()); | ||
} | ||
return () => { | ||
@@ -94,0 +100,0 @@ dependenciesManager.disableComputed(computed); |
{ | ||
"name": "fluidstate", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Library for fine-grained reactivity state management", | ||
@@ -5,0 +5,0 @@ "repository": "https://gitlab.com/fluidstate/fluidstate", |
@@ -10,4 +10,4 @@ import { DependenciesManager } from "./dependencies-manager"; | ||
batch: (update: () => void) => void; | ||
addEffect: (effectId: object, perform: () => void) => void; | ||
cancelEffect: (effectId: object) => void; | ||
addEffect: (effectId: symbol, isInitial: boolean, perform: () => void) => boolean; | ||
cancelEffect: (effectId: symbol) => void; | ||
triggerUpdate: ({ shouldResolveImmediatelyAfterBatch, }?: { | ||
@@ -14,0 +14,0 @@ shouldResolveImmediatelyAfterBatch?: boolean | undefined; |
@@ -161,5 +161,11 @@ "use strict"; | ||
}; | ||
const addEffect = (effectId, perform) => { | ||
const addEffect = (effectId, isInitial, perform) => { | ||
if (!isUpdateInProgress()) { | ||
perform(); | ||
// The following condition is just in case of a possible future refactor; | ||
// currently can't think of a situation where it may happen | ||
if (!isInitial) { | ||
perform(); | ||
return true; | ||
} | ||
return false; | ||
} else { | ||
@@ -171,2 +177,3 @@ cancelEffect(effectId); | ||
}); | ||
return true; | ||
} | ||
@@ -173,0 +180,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
205290
2048