feat: feature/mvp-sprint-1 Made createDependancies more efficient
This commit is contained in:
parent
52f604e2d4
commit
df3f7bbef6
@ -36,12 +36,36 @@ export const Thingtime = (props) => {
|
|||||||
const contentEditableRef = React.useRef(null)
|
const contentEditableRef = React.useRef(null)
|
||||||
const editValueRef = React.useRef({})
|
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 childrenRef = React.useRef([])
|
||||||
|
|
||||||
const [thingDep, setThingDep] = React.useState(childrenRef.current)
|
const [thingDep, setThingDep] = React.useState(childrenRef.current)
|
||||||
|
|
||||||
const createDependancies = () => {
|
const createDependancies = () => {
|
||||||
// push all children into childrenRef.current
|
// 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 {
|
try {
|
||||||
const values = Object.values(props?.thing)
|
const values = Object.values(props?.thing)
|
||||||
// if childrenRef.current does not shallow equal values then replace with array of values
|
// 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(() => {
|
React.useEffect(() => {
|
||||||
setUuid(Math.random().toString(36).substring(7))
|
createDependancies()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const thing = React.useMemo(() => {
|
const thing = React.useMemo(() => {
|
||||||
|
@ -53,8 +53,8 @@ export const safe = (props) => {
|
|||||||
|
|
||||||
export const getThingtime = () => {
|
export const getThingtime = () => {
|
||||||
try {
|
try {
|
||||||
return window?.thingtime || globalThis?.thingtime
|
return window?.meta || globalThis?.meta
|
||||||
} catch {
|
} catch {
|
||||||
return globalThis?.thingtime
|
return globalThis?.meta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ export default function App() {
|
|||||||
// limiter
|
// limiter
|
||||||
const setThingtime = (glob) => {
|
const setThingtime = (glob) => {
|
||||||
try {
|
try {
|
||||||
glob.thingtime = {
|
glob.meta = {
|
||||||
tmp: {},
|
tmp: {},
|
||||||
subscribers: {},
|
subscribers: {},
|
||||||
state: {},
|
state: {},
|
||||||
|
Loading…
Reference in New Issue
Block a user