Skip to content

Instantly share code, notes, and snippets.

@roman01la
Last active September 23, 2015 21:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roman01la/89e9f5a89b4378e04df0 to your computer and use it in GitHub Desktop.
Save roman01la/89e9f5a89b4378e04df0 to your computer and use it in GitHub Desktop.
if (__DEV__) {
window.devtoolsFormatters = window.devtoolsFormatters || [];
window.devtoolsFormatters.push((function() {
/* mori's type check methods */
var checks = [
'isReduceable', 'isSeqable',
'isReversible', 'isCounted', 'isIndexed',
'isSequential', 'isAssociative',
'isCollection', 'isSeq', 'isKeyword',
'isSymbol', 'isMap', 'isSet',
'isList', 'isVector'
];
/* used to distinct between Set & SortedSet, HashMap & SortedMap */
var set = mori.set();
var map = mori.hashMap();
/* Check if x is mori's data structure */
function isMori (x) {
var result = [false, ''];
for (var i = checks.length; i-->0;) {
if (mori[checks[i]](x)) {
result[0] = true;
result[1] = checks[i];
/* distinct between Set & SortedSet, HashMap & SortedMap */
if (checks[i] === 'isSet' &&
set.constructor !== x.constructor) { result[1] = 'isSorterSet'; }
if (checks[i] === 'isMap' &&
map.constructor !== x.constructor) { result[1] = 'isSorterMap'; }
break;
}
}
return result; // [true/false, type]
}
return {
header (x) {
var is = isMori(x);
if (is[0]) {
var o;
try {
o = mori.toJs(x);
}
finally {
return o !== undefined ?
['span', {}, is[1].substring(2, is[1].length),
['object', { object: o }]] :
null;
}
} else { return null; }
},
hasBody() { return false; },
body() { return null; }
};
})());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment