-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathctx.js
More file actions
33 lines (33 loc) · 759 Bytes
/
Copy pathctx.js
File metadata and controls
33 lines (33 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Ctx {
constructor(template) {
this._temp = "";
this._parentTemp = `return @temp;`;
this._defaultCom = null;
this._com = null;
this._b = window.Babel;
this._babelpresets = ["react"];
this.updateTemplate(template);
}
_transpile() {
return this._b.transform(this._temp, {
presets: this._babelpresets,
}).code;
}
_generateCom() {
this._com = this._temp
? Function(this._parentTemp.replace("@temp", this._transpile()))()
: this._defaultCom;
}
updateTemplate(template) {
template = template || "";
if (template !== this._temp) {
this._temp = template;
this._generateCom();
}
return this;
}
getComponent() {
return this._com;
}
}
export default Ctx;