From ea9942288c464e23f1d57649f9282a6d2b24fb7a Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Mon, 27 May 2024 15:41:45 +0200 Subject: [PATCH] refactor: simplify the communication for offline caching It should be enough to use isParentCached for knowing when to start recording and remove the cache in the plugin. --- src/PluginWrapper.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/PluginWrapper.js b/src/PluginWrapper.js index 02c05f8bb..899b420ac 100644 --- a/src/PluginWrapper.js +++ b/src/PluginWrapper.js @@ -17,14 +17,9 @@ const LoadingMask = () => { ) } -const CacheableSectionWrapper = ({ - id, - children, - cacheNow, - isParentCached, -}) => { +const CacheableSectionWrapper = ({ id, children, isParentCached }) => { const { startRecording, isCached, remove } = useCacheableSection(id) - + /* useEffect(() => { if (cacheNow) { startRecording({ onError: console.error }) @@ -34,11 +29,15 @@ const CacheableSectionWrapper = ({ // an infinite recording loop as-is (probably need to memoize it) // eslint-disable-next-line react-hooks/exhaustive-deps }, [cacheNow]) - +*/ useEffect(() => { - // Synchronize cache state on load or prop update - // -- a back-up to imperative `removeCachedData` - if (!isParentCached && isCached) { + if (isParentCached && !isCached) { + console.log('LL p: start recording') + startRecording({ onError: console.error }) + } else if (!isParentCached && isCached) { + // Synchronize cache state on load or prop update + // -- a back-up to imperative `removeCachedData` + console.log('LL p: remove cache') remove() } @@ -52,14 +51,13 @@ const CacheableSectionWrapper = ({ ) } CacheableSectionWrapper.propTypes = { - cacheNow: PropTypes.bool, children: PropTypes.node, id: PropTypes.string, isParentCached: PropTypes.bool, } const PluginWrapper = (props) => { - const { onInstallationStatusChange, onPropsReceived, ...otherProps } = props + const { onInstallationStatusChange, ...otherProps } = props const [propsFromParent, setPropsFromParent] = useState(otherProps) const onDataSorted = useCallback( @@ -94,8 +92,6 @@ const PluginWrapper = (props) => { }, [onInstallationStatusChange]) if (propsFromParent) { - onPropsReceived() - return (
{ > { PluginWrapper.propTypes = { onInstallationStatusChange: PropTypes.func, - onPropsReceived: PropTypes.func, } export default PluginWrapper