feat: feature/mvp-sprint-1 Made createDependancies more efficient

This commit is contained in:
Nikolaj Frey 2023-08-09 13:10:00 +10:00
parent 52f604e2d4
commit df3f7bbef6
3 changed files with 28 additions and 19 deletions

View File

@ -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(() => {

View File

@ -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
}
}

View File

@ -60,7 +60,7 @@ export default function App() {
// limiter
const setThingtime = (glob) => {
try {
glob.thingtime = {
glob.meta = {
tmp: {},
subscribers: {},
state: {},