Alter prettyTrie to allow customised rendering of success-values

This commit is contained in:
Tony Garnock-Jones 2016-05-19 13:13:28 -04:00
parent e806e91baa
commit 4aabe422fe
1 changed files with 9 additions and 4 deletions

View File

@ -797,16 +797,21 @@ function instantiateProjection(p, obj) {
} }
} }
function prettyTrie(m, initialIndent) { function prettyTrie(m, optionsOpt) {
var acc = []; var acc = [];
walk(initialIndent || 0, m); var options = optionsOpt || {};
walk(options.initialIndent || 0, m);
return acc.join(''); return acc.join('');
function walk(i, m) { function walk(i, m) {
if (m instanceof $Success) { if (m instanceof $Success) {
var v = m.value; var v = m.value;
if (Immutable.Set.isSet(v)) { v = v.toArray(); } if ('prettySuccess' in options) {
acc.push(" {" + JSON.stringify(v) + "}"); acc.push(" " + options.prettySuccess(v));
} else {
if (Immutable.Set.isSet(v)) { v = v.toArray(); }
acc.push(" {" + JSON.stringify(v) + "}");
}
return; return;
} }