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 {
|
): T {
|
||||||
const obj: S & Partial<T> = baseObject;
|
const obj: S & Partial<T> = baseObject;
|
||||||
let calculated = false;
|
let calculated = false;
|
||||||
|
let calculating = false;
|
||||||
function calculateObj(): T {
|
function calculateObj(): T {
|
||||||
if (!calculated) {
|
if (!calculated) {
|
||||||
|
if (calculating) {
|
||||||
|
throw new Error("Cyclical dependency detected. Cannot evaluate lazy proxy.");
|
||||||
|
}
|
||||||
|
calculating = true;
|
||||||
Object.assign(obj, objectFunc.call(obj, obj));
|
Object.assign(obj, objectFunc.call(obj, obj));
|
||||||
calculated = true;
|
calculated = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue