From df3f7bbef6c19824d7bf7f0ca2a0ea3f02d825fd Mon Sep 17 00:00:00 2001 From: Nikolaj Frey Date: Wed, 9 Aug 2023 13:10:00 +1000 Subject: [PATCH] feat: feature/mvp-sprint-1 Made createDependancies more efficient --- remix/app/components/Thingtime/Thingtime.tsx | 41 ++++++++++++-------- remix/app/functions/safe.tsx | 4 +- remix/app/root.tsx | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/remix/app/components/Thingtime/Thingtime.tsx b/remix/app/components/Thingtime/Thingtime.tsx index 8250d2a..573a885 100644 --- a/remix/app/components/Thingtime/Thingtime.tsx +++ b/remix/app/components/Thingtime/Thingtime.tsx @@ -36,12 +36,36 @@ export const Thingtime = (props) => { const contentEditableRef = React.useRef(null) const editValueRef = React.useRef({}) + const depth = React.useMemo(() => { + return props?.depth || 1 + }, [props?.depth]) + + const pl = React.useMemo(() => { + return props?.pl || [4, 6] + }, [props?.pl]) + + const pr = React.useMemo(() => { + return props?.pr || (depth === 1 ? [4, 6] : 0) + }, [props?.pr, depth]) + + // will only run on the client + React.useEffect(() => { + setUuid(Math.random().toString(36).substring(7)) + }, []) + const childrenRef = React.useRef([]) const [thingDep, setThingDep] = React.useState(childrenRef.current) const createDependancies = () => { // push all children into childrenRef.current + + try { + window.meta.things.db["createDependancies"] = + window.meta.things.db["createDependancies"] || 0 + window.meta.things.db["createDependancies"]++ + } catch {} + try { const values = Object.values(props?.thing) // if childrenRef.current does not shallow equal values then replace with array of values @@ -59,23 +83,8 @@ export const Thingtime = (props) => { } } - createDependancies() - - const depth = React.useMemo(() => { - return props?.depth || 1 - }, [props?.depth]) - - const pl = React.useMemo(() => { - return props?.pl || [4, 6] - }, [props?.pl]) - - const pr = React.useMemo(() => { - return props?.pr || (depth === 1 ? [4, 6] : 0) - }, [props?.pr, depth]) - - // will only run on the client React.useEffect(() => { - setUuid(Math.random().toString(36).substring(7)) + createDependancies() }, []) const thing = React.useMemo(() => { diff --git a/remix/app/functions/safe.tsx b/remix/app/functions/safe.tsx index 6ed1ee6..f3f6faa 100644 --- a/remix/app/functions/safe.tsx +++ b/remix/app/functions/safe.tsx @@ -53,8 +53,8 @@ export const safe = (props) => { export const getThingtime = () => { try { - return window?.thingtime || globalThis?.thingtime + return window?.meta || globalThis?.meta } catch { - return globalThis?.thingtime + return globalThis?.meta } } diff --git a/remix/app/root.tsx b/remix/app/root.tsx index e21c531..c1f48d5 100644 --- a/remix/app/root.tsx +++ b/remix/app/root.tsx @@ -60,7 +60,7 @@ export default function App() { // limiter const setThingtime = (glob) => { try { - glob.thingtime = { + glob.meta = { tmp: {}, subscribers: {}, state: {},