Skip to content

Instantly share code, notes, and snippets.

@punmechanic
Created February 26, 2020 23:12
Show Gist options
  • Save punmechanic/0b74985191b3afd43edbf2b4cf57819e to your computer and use it in GitHub Desktop.
Save punmechanic/0b74985191b3afd43edbf2b4cf57819e to your computer and use it in GitHub Desktop.
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