mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-11-24 17:31:47 +00:00
Throw error if lazy proxies get cyclical
This commit is contained in:
parent
36fa4ece65
commit
81058e10b4
1 changed files with 5 additions and 0 deletions
|
@ -36,8 +36,13 @@ export function createLazyProxy<T extends object, S extends T>(
|
|||
): T {
|
||||
const obj: S & Partial<T> = baseObject;
|
||||
let calculated = false;
|
||||
let calculating = false;
|
||||
function calculateObj(): T {
|
||||
if (!calculated) {
|
||||
if (calculating) {
|
||||
throw new Error("Cyclical dependency detected. Cannot evaluate lazy proxy.");
|
||||
}
|
||||
calculating = true;
|
||||
Object.assign(obj, objectFunc.call(obj, obj));
|
||||
calculated = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue