1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 11:04:00 +03:00

Use a term-to-DOM wrapper function.

This commit is contained in:
Rob Rix 2015-10-23 20:23:53 -04:00
parent 38ec0850c2
commit e152b0084c

View File

@ -80,6 +80,11 @@
return this; return this;
} }
/// Term -> String -> DOM
function termToDOM(term, source) {
return rangeAndSyntaxToDOM(term.range, term.unwrap, source, function(term) { return termToDOM(term, source); });
}
/// Range -> Syntax a -> String, (a -> DOM) -> DOM /// Range -> Syntax a -> String, (a -> DOM) -> DOM
function rangeAndSyntaxToDOM(range, syntax, source, recur) { function rangeAndSyntaxToDOM(range, syntax, source, recur) {
recur = recur || function (term) { return rangeAndSyntaxToDOM(term.range, term.unwrap, source); } recur = recur || function (term) { return rangeAndSyntaxToDOM(term.range, term.unwrap, source); }
@ -131,7 +136,7 @@
var element; var element;
if (model instanceof Term) { if (model instanceof Term) {
element = rangeAndSyntaxToDOM(model.range, model.unwrap, source, function(child) { return toDOM(child, stateName, source); }); element = rangeAndSyntaxToDOM(model.range, model.unwrap, source);
} }
if (model instanceof Diff) { if (model instanceof Diff) {
@ -141,7 +146,7 @@
element.classList.add("pure"); element.classList.add("pure");
element.appendChild(toDOM(model.pure[stateName], stateName, source)); element.appendChild(toDOM(model.pure[stateName], stateName, source));
} else if(model.roll != null) { } else if(model.roll != null) {
element = rangeAndSyntaxToDOM(model.roll.extract[stateName], model.roll.unwrap, source, function(child) { return toDOM(child, stateName, source); }); element = rangeAndSyntaxToDOM(model.roll.extract[stateName], model.roll.unwrap, source);
element.classList.add("diff"); element.classList.add("diff");
element.classList.add("roll"); element.classList.add("roll");
} }
@ -216,8 +221,8 @@
var diff = diffFromJSON(json.diff); var diff = diffFromJSON(json.diff);
var mapped = diff.map(function(value) { var mapped = diff.map(function(value) {
return { return {
before: value.before != null ? toDOM(value.before, "before", json["before"]) : document.createTextNode(""), before: value.before != null ? termToDOM(value.before, "before", json["before"]) : document.createTextNode(""),
after: value.after != null ? toDOM(value.after, "after", json["after"]) : document.createTextNode(""), after: value.after != null ? termToDOM(value.after, "after", json["after"]) : document.createTextNode(""),
}; };
}); });
document.getElementById("before").appendChild(toDOM(mapped, "before", json["before"])); document.getElementById("before").appendChild(toDOM(mapped, "before", json["before"]));