aboutsummaryrefslogtreecommitdiff
path: root/src/client-runtime.ffi.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client-runtime.ffi.mjs')
-rw-r--r--src/client-runtime.ffi.mjs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/client-runtime.ffi.mjs b/src/client-runtime.ffi.mjs
index 51c2eef..ecca48f 100644
--- a/src/client-runtime.ffi.mjs
+++ b/src/client-runtime.ffi.mjs
@@ -1,5 +1,10 @@
import { ElementNotFound, NotABrowser } from "./lustre.mjs";
-import { Dispatch, Shutdown } from "./lustre/internals/runtime.mjs";
+import {
+ Dispatch,
+ Shutdown,
+ Debug,
+ ForceModel,
+} from "./lustre/internals/runtime.mjs";
import { morph } from "./vdom.ffi.mjs";
import { Ok, Error, isEqual } from "./gleam.mjs";
@@ -58,6 +63,11 @@ export class LustreClientApplication {
return;
}
+ case action instanceof Debug: {
+ this.#debug(action[0]);
+ return;
+ }
+
default:
return;
}
@@ -114,6 +124,26 @@ export class LustreClientApplication {
}
}
+ #debug(action) {
+ switch (true) {
+ case action instanceof ForceModel: {
+ const vdom = this.#view(this.#model);
+ const dispatch = (handler) => (e) => {
+ const result = handler(e);
+
+ if (result instanceof Ok) {
+ this.send(new Dispatch(result[0]));
+ }
+ };
+
+ this.#queue = [];
+ this.#effects = [];
+ this.#didUpdate = false;
+ this.#root = morph(this.#root, vdom, dispatch, this.#isComponent);
+ }
+ }
+ }
+
#shutdown() {
this.#root.remove();
this.#root = null;