marko
Version:
UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.
141 lines (109 loc) • 2.41 kB
JavaScript
;
// eslint-disable-next-line no-constant-binary-expression
class ServerComponent {
constructor(id, input, out, typeName, customEvents, scope) {
this.id = id;
this.X_ = customEvents;
this.Y_ = scope;
this.typeName = typeName;
this.Z_ = undefined; // Used to keep track of bubbling DOM events for components rendered on the server
this._a_ = 0;
this.onCreate(input, out);
this._b_ = this.onInput(input, out) || input;
if (this.P_ === undefined) {
this.P_ = this._b_;
}
this.onRender(out);
}
set input(newInput) {
this.P_ = newInput;
}
get input() {
return this.P_;
}
set state(newState) {
this.A_ = newState;
}
get state() {
return this.A_;
}
get aE_() {
return this.A_;
}
elId(nestedId) {
var id = this.id;
if (nestedId == null) {
return id;
} else {
if (typeof nestedId !== "string") {
// eslint-disable-next-line no-constant-condition
nestedId = String(nestedId);
}
if (nestedId.indexOf("#") === 0) {
id = "#" + id;
nestedId = nestedId.substring(1);
}
return id + "-" + nestedId;
}
}
onCreate() {}
onInput() {}
onRender() {}
isDestroyed() {
return false;
}
setState(name, value) {
if (typeof name == "object") {
if (this.A_) {
Object.assign(this.A_, name);
} else {
this.A_ = name;
}
} else {
this.A_[name] = value;
}
}
setStateDirty(name, value) {
if (typeof name == "object") {
if (this.A_) {
Object.assign(this.A_, name);
} else {
this.A_ = name;
}
} else {
this.A_[name] = value;
}
}
replaceState(newState) {
this.A_ = newState;
}
subscribeTo() {
notImplemented("subscribeTo");
}
emit() {
notImplemented("emit");
}
getEl() {
notImplemented("getEl");
}
getEls() {
notImplemented("getEls");
}
getComponent() {
notImplemented("getComponent");
}
getComponents() {
notImplemented("getComponents");
}
forceUpdate() {
notImplemented("forceUpdate");
}
update() {
notImplemented("update");
}
}
ServerComponent.prototype.getElId = ServerComponent.prototype.elId;
module.exports = ServerComponent;
function notImplemented(name) {
throw new Error(name + " method not supported during SSR.");
}