fix: add stubs for some client side component apis

This commit is contained in:
dpiercey 2024-12-30 08:27:52 -07:00 committed by Dylan Piercey
parent 602eaad0a4
commit 4349f959f8
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"marko": patch
---
Add stubs for some client side component apis on the server.

View File

@ -66,8 +66,76 @@ class ServerComponent {
onCreate() {}
onInput() {}
onRender() {}
isDestroyed() {
return false;
}
setState(name, value) {
if (typeof name == "object") {
if (this.___state) {
Object.assign(this.___state, name);
} else {
this.___state = name;
}
} else {
this.___state[name] = value;
}
}
setStateDirty(name, value) {
if (typeof name == "object") {
if (this.___state) {
Object.assign(this.___state, name);
} else {
this.___state = name;
}
} else {
this.___state[name] = value;
}
}
replaceState(newState) {
this.___state = 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.");
}