fluidstate-preact
Advanced tools
Comparing version 0.0.14 to 0.0.15
64
hoc.js
@@ -25,30 +25,48 @@ "use strict"; | ||
// and in a way that preserves hook order | ||
const stopEffect = (0, _onceRef.useOnceRef)(() => api.createEffect(() => { | ||
// This subscribes to renderControl, which allows us | ||
// to rerun computed at the right time | ||
api.get(renderControl.current); | ||
if (data.current.isWithinRender) { | ||
data.current.result = Component(...argsRef.current); | ||
} else { | ||
// When not within render context, we shouldn't rerun | ||
// Component render. Instead, we simply ask Preact to rerender | ||
if (data.current.isInitialized) { | ||
return true; | ||
const effect = (0, _onceRef.useOnceRef)(() => { | ||
let dependencies = new Set(); | ||
const computed = api.createComputed(() => { | ||
// This subscribes to renderControl, which allows us | ||
// to rerun computed at the right time | ||
api.get(renderControl.current); | ||
if (data.current.isWithinRender) { | ||
data.current.result = Component(...argsRef.current); | ||
dependencies = new Set(computed.dependencies); | ||
} else { | ||
data.current.isInitialized = true; | ||
// Getting dependencies to preserve the same dependency list | ||
for (const dependency of dependencies) { | ||
api.get(dependency); | ||
} | ||
// When not within render context, we shouldn't rerun | ||
// Component render. Instead, we simply ask Preact to rerender | ||
if (data.current.isInitialized) { | ||
return true; | ||
} else { | ||
data.current.isInitialized = true; | ||
} | ||
} | ||
} | ||
return false; | ||
}, shouldRerender => { | ||
if (shouldRerender) { | ||
rerender(Symbol()); | ||
// @ts-ignore | ||
if (0 && _testCounter.testCounter.increaseCount) { | ||
_testCounter.testCounter.increaseCount(); | ||
return false; | ||
}); | ||
const stopEffect = api.createEffect(() => api.get(computed), shouldRerender => { | ||
if (shouldRerender) { | ||
rerender(Symbol()); | ||
// @ts-ignore | ||
if (0 && _testCounter.testCounter.increaseCount) { | ||
_testCounter.testCounter.increaseCount(); | ||
} | ||
} | ||
} | ||
})); | ||
}); | ||
return { | ||
computed, | ||
stopEffect | ||
}; | ||
}); | ||
(0, _hooks.useEffect)(() => { | ||
return () => { | ||
stopEffect.current(); | ||
const { | ||
computed, | ||
stopEffect | ||
} = effect.current; | ||
api.disableComputed(computed); | ||
stopEffect(); | ||
}; | ||
@@ -55,0 +73,0 @@ }, []); |
{ | ||
"name": "fluidstate-preact", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Library for using fine-grained reactivity state management library fluidstate in Preact", | ||
@@ -5,0 +5,0 @@ "repository": "https://gitlab.com/fluidstate/fluidstate-preact", |
Sorry, the diff of this file is not supported yet
36777
254