Minor refactoring: abstract away from direct usage of .get

This commit is contained in:
Tony Garnock-Jones 2018-10-21 13:33:18 +01:00
parent 1c831ad152
commit 9bc38ac6ff
1 changed files with 16 additions and 10 deletions

View File

@ -40,8 +40,22 @@ function Handler(cachedCaptures) {
this.callbacks = Immutable.Set();
}
function classOf(v) {
if (v instanceof Struct.Structure) {
return v.meta;
} else if (v instanceof Immutable.List) {
return v.size;
} else {
throw new Error("Assertion contains unsupported data type: " + v.toString());
}
}
function step(v, index) {
return v.get(index);
}
function projectPath(v, path) {
path.forEach((index) => { v = v.get(index); return true; });
path.forEach((index) => { v = step(v, index); return true; });
return v;
}
@ -49,14 +63,6 @@ function projectPaths(v, paths) {
return paths.map((path) => { return projectPath(v, path) });
}
function classOf(v) {
if (v instanceof Struct.Structure) {
return v.meta;
} else {
return v.size;
}
}
Node.prototype.extend = function(skeleton) {
function walkNode(path, node, popCount, index, skeleton) {
if (skeleton === null) {
@ -159,7 +165,7 @@ Node.prototype.modify = function(outerValue, m_cont, m_leaf, m_handler) {
let i = selector.popCount;
while (i--) { mutable.pop(); }
});
let nextValue = nextStack.first().get(selector.index);
let nextValue = step(nextStack.first(), selector.index);
let cls = classOf(nextValue);
let nextNode = table.get(cls, false);
if (nextNode) {