2023-06-29 23:41:06 +00:00
|
|
|
export const safe = props => {
|
2023-06-29 11:39:40 +00:00
|
|
|
// do not render more than the limit of things to prevent infinite loops
|
2023-06-29 23:41:06 +00:00
|
|
|
const thingtime = getThingtime()
|
|
|
|
|
|
|
|
const uuid = props?.uuid
|
|
|
|
|
2023-06-29 11:39:40 +00:00
|
|
|
try {
|
|
|
|
if (
|
2023-06-29 23:41:06 +00:00
|
|
|
typeof thingtime?.things?.count === 'number' &&
|
|
|
|
thingtime?.things?.count >= thingtime?.things?.limit
|
2023-06-29 11:39:40 +00:00
|
|
|
) {
|
2023-06-29 23:41:06 +00:00
|
|
|
console.error(
|
|
|
|
'[codex] Maximum things reached',
|
|
|
|
thingtime?.things?.count,
|
|
|
|
thingtime?.things?.limit
|
|
|
|
)
|
2023-06-29 11:39:40 +00:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
} catch (err) {
|
2023-06-29 23:41:06 +00:00
|
|
|
console.error('[codex] Error in Thingtime.tsx checking maximum things', err)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!thingtime?.things?.db?.[uuid]) {
|
|
|
|
thingtime.things.db[uuid] = {
|
|
|
|
count: 1
|
|
|
|
}
|
|
|
|
thingtime.things.count++
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// empty
|
2023-06-29 11:39:40 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 23:41:06 +00:00
|
|
|
try {
|
|
|
|
if (props?.depth >= thingtime?.things?.maxDepth) {
|
|
|
|
console.error(
|
|
|
|
'[codex] Reached max depth',
|
|
|
|
props?.depth,
|
|
|
|
thingtime?.things?.maxDepth
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
return props?.children
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getThingtime = () => {
|
|
|
|
try {
|
|
|
|
return window?.thingtime || globalThis?.thingtime
|
|
|
|
} catch {
|
|
|
|
return globalThis?.thingtime
|
|
|
|
}
|
2023-06-29 11:39:40 +00:00
|
|
|
}
|