Created
February 26, 2020 23:12
-
-
Save punmechanic/0b74985191b3afd43edbf2b4cf57819e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function expandAllRefs( | |
rootDoc, | |
currentValue = rootDoc, | |
update = cannotUpdateRootNode | |
) { | |
// This is definitely a sin | |
// Boy, I would hate to find out the performance of this in deeply nested code | |
for (const key of Object.keys(currentValue)) { | |
const value = currentValue[key]; | |
if (isRef(key)) { | |
update(expandRef(rootDoc, value)); | |
continue; | |
} | |
// We do not attempt to resolve values for non-objects. | |
if (typeof value !== "object") { | |
continue; | |
} | |
const nextUpdate = nextValue => { | |
currentValue[key] = nextValue; | |
}; | |
return expandAllRefs(rootDoc, value, nextUpdate); | |
} | |
return rootDoc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment