You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
define([
|
|
'/common/hyperjson.js',
|
|
'/common/hyperscript.js'
|
|
], function (hyperjson, hyperscript) {
|
|
// complain if you don't find the required APIs
|
|
if (!(hyperjson && hyperscript)) { throw new Error(); }
|
|
|
|
// Generate a matrix of conversions
|
|
/*
|
|
convert.dom.to.hjson, convert.hjson.to.dom,
|
|
convert.dom.to.vdom, convert.vdom.to.dom,
|
|
|
|
and of course, identify functions in case you try to
|
|
convert a datatype to itself
|
|
*/
|
|
var convert = (function () {
|
|
var Self = function (x) {
|
|
return x;
|
|
},
|
|
methods = {
|
|
dom:{
|
|
dom: Self,
|
|
hjson: hyperjson.fromDOM
|
|
},
|
|
hjson:{
|
|
hjson: Self,
|
|
dom: function (H) {
|
|
// hyperjson.fromDOM,
|
|
return hyperjson.callOn(H, hyperscript);
|
|
}
|
|
}
|
|
},
|
|
convert = {};
|
|
Object.keys(methods).forEach(function (method) {
|
|
convert[method] = { to: methods[method] };
|
|
});
|
|
return convert;
|
|
}());
|
|
|
|
convert.core = {
|
|
hyperjson: hyperjson,
|
|
hyperscript: hyperscript
|
|
};
|
|
return convert;
|
|
});
|