diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-04-16 22:19:43 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2024-04-16 22:19:43 +0100 |
commit | 7a145f639ddbc18ba2f4810eeed2ea6e08edb29a (patch) | |
tree | add02d3303b2b2cc16202dfcb08a6155d7f2e277 /src/client-runtime.ffi.mjs | |
parent | 5d5b513449017118134a32571dceba754ca1c4f5 (diff) | |
download | lustre-7a145f639ddbc18ba2f4810eeed2ea6e08edb29a.tar.gz lustre-7a145f639ddbc18ba2f4810eeed2ea6e08edb29a.zip |
:sparkles: Add a new 'ForceModel' debug action to experiment with time-travel debugging.
Diffstat (limited to 'src/client-runtime.ffi.mjs')
-rw-r--r-- | src/client-runtime.ffi.mjs | 32 |
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; |