UNPKG

gentyl

Version:

A Generator That You'll Love

75 lines (74 loc) 2.6 kB
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var uuid = require('uuid'); var Gentyl; (function (Gentyl) { function isBundle(object) { return object instanceof Object && "form" in object && "state" in object && "node" in object; } Gentyl.isBundle = isBundle; var ObjectFunctionCache = (function () { function ObjectFunctionCache() { this.functions = {}; } ObjectFunctionCache.prototype.storeFunction = function (func) { var name = (["", 'anonymous', undefined].indexOf(func.name) == -1) ? func.name : uuid.v1(); this.functions[name] = func; return name; }; ObjectFunctionCache.prototype.recoverFunction = function (id) { return this.functions[id]; }; return ObjectFunctionCache; }()); var liveCache = new ObjectFunctionCache(); function deformulate(fromNode) { var preform = { f: fromNode.form.resolver, c: fromNode.form.carrier, m: fromNode.form.ctxmode }; var exForm = {}; for (var k in preform) { var val = preform[k]; if (val instanceof Function) { exForm[k] = liveCache.storeFunction(val); } else { exForm[k] = val; } } return exForm; } Gentyl.deformulate = deformulate; function reformulate(formRef) { var recovered = {}; for (var k in formRef) { recovered[k] = liveCache.recoverFunction(formRef[k]); } return recovered; } Gentyl.reformulate = reformulate; var Reconstruction = (function (_super) { __extends(Reconstruction, _super); function Reconstruction(bundle) { function debundle(bundle) { if (isBundle(bundle)) { return new Reconstruction(bundle); } else { return bundle; } } var node = Gentyl.Util.typeCaseSplitF(debundle)(bundle.node); var form = Gentyl.reformulate(bundle.form); var state = bundle.state; _super.call(this, node, form, state); } return Reconstruction; }(Gentyl.ResolutionNode)); Gentyl.Reconstruction = Reconstruction; })(Gentyl || (Gentyl = {}));