<filename>.cache/f02a08f453a0539d814670f539b309af.json
{"dependencies":[{"name":"../Simple","loc":{"line":3,"column":23}},{"name":"../Dom/SimpleElement","loc":{"line":4,"column":30}},{"name":"../Utils/Types","loc":{"line":5,"column":22}}],"generated":{"js":"\"use strict\";\nexports.__esModule = true;\nvar Simple_1 = require(\"../Simple\");\nvar SimpleElement_1 = require(\"../Dom/SimpleElement\");\nvar Types_1 = require(\"../Utils/Types\");\n/**\n * A renderer is only in charge of its node and all children nodes\n */\nvar Render = /** @class */ (function () {\n    function Render(simple) {\n        this.simple = simple;\n    }\n    /**\n     * Construct tree from children nodes\n     * @return {SimpleElement} [description]\n     */\n    Render.prototype.constructTree = function () {\n        var children = this.simple.render();\n        var el = this.simple.el;\n        el.appendChild(children);\n        return el;\n    };\n    /**\n     * Render the tree\n     */\n    Render.prototype.init = function () {\n        this.data = this.simple.getData();\n        this.checkIfSimpleAndRender();\n        this.checkIfStringAndRender();\n        this.checkIfObjectAndRender();\n        this.checkIfArrayAndRender();\n    };\n    /**\n     * Check if its an object and render\n     */\n    Render.prototype.checkIfObjectAndRender = function () {\n        if (Types_1[\"default\"].IsObject(this.data)) {\n            this.simple.el = SimpleElement_1[\"default\"].Create('div');\n            var keys = Object.keys(this.data);\n            for (var i = 0; i < keys.length; i++) {\n                var child = this.data[keys[i]];\n                var simple = new Simple_1[\"default\"]({ data: child });\n                this.simple.addChild(simple);\n            }\n        }\n    };\n    /**\n     * Check if the data is an array and render each\n     * child\n     */\n    Render.prototype.checkIfArrayAndRender = function () {\n        if (Types_1[\"default\"].IsArray(this.data)) {\n            var ul = new Simple_1[\"default\"]({ type: 'ul' });\n            for (var i = 0; i < this.data.length; i++) {\n                var li = new Simple_1[\"default\"]({ type: 'li' });\n                var child = new Simple_1[\"default\"]({ data: this.data[i] });\n                li.addChild(child);\n                ul.addChild(li);\n            }\n            this.simple.addChild(ul);\n        }\n    };\n    /**\n     * Check if data is a string and set the values\n     */\n    Render.prototype.checkIfStringAndRender = function () {\n        if (Types_1[\"default\"].IsString(this.data)) {\n            var matched = this.data.match(/__SIMPLE__::([0-9]+)/g);\n            if (!matched) {\n                return this.simple.appendString(this.data);\n            }\n            this.replaceKeyWithValue(matched);\n            this.simple.el.appendString(this.data);\n        }\n    };\n    /**\n     * Replace key with value\n     * @param {string[]} matched [description]\n     */\n    Render.prototype.replaceKeyWithValue = function (matched) {\n        for (var i = 0; i < matched.length; i++) {\n            var match = matched[i];\n            var simple = Simple_1[\"default\"].__getFromCache(match);\n            if (!simple)\n                continue;\n            var value = simple.el.getValue();\n            var regex = new RegExp(match, 'g');\n            this.data = this.data.replace(regex, value);\n        }\n    };\n    /**\n     * Check if a simple object and render\n     */\n    Render.prototype.checkIfSimpleAndRender = function () {\n        if (this.data instanceof Simple_1[\"default\"]) {\n            var children = this.data.render();\n            this.simple.addChild(this.data);\n        }\n    };\n    return Render;\n}());\nexports[\"default\"] = Render;\n"},"hash":"de633096bc1a1bd2d367f23b8318cce5"}