diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-06-11 17:50:54 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2024-06-11 18:24:57 +0100 |
commit | 044ebd053d484827ec58a707d80fda9952966fce (patch) | |
tree | be1fd0fb6f2f51de47e1c0ec356641cb5309814c /src/client-runtime.ffi.mjs | |
parent | c627d12f3f1e787a1e5dfee34d0fc13a2f60d152 (diff) | |
download | lustre-044ebd053d484827ec58a707d80fda9952966fce.tar.gz lustre-044ebd053d484827ec58a707d80fda9952966fce.zip |
:zap: Skip render if model is reference equal to last update.
Diffstat (limited to 'src/client-runtime.ffi.mjs')
-rw-r--r-- | src/client-runtime.ffi.mjs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/client-runtime.ffi.mjs b/src/client-runtime.ffi.mjs index 49c65a7..562f9c4 100644 --- a/src/client-runtime.ffi.mjs +++ b/src/client-runtime.ffi.mjs @@ -6,7 +6,7 @@ import { ForceModel, } from "./lustre/internals/runtime.mjs"; import { morph } from "./vdom.ffi.mjs"; -import { Ok, Error, isEqual } from "./gleam.mjs"; +import { Ok, Error } from "./gleam.mjs"; export class LustreClientApplication { #root = null; @@ -86,24 +86,26 @@ export class LustreClientApplication { #tick() { this.#flush_queue(); - const vdom = this.#view(this.#model); - const dispatch = (handler) => (e) => { - const result = handler(e); + if (this.#didUpdate) { + const vdom = this.#view(this.#model); + const dispatch = (handler) => (e) => { + const result = handler(e); - if (result instanceof Ok) { - this.send(new Dispatch(result[0])); - } - }; + if (result instanceof Ok) { + this.send(new Dispatch(result[0])); + } + }; - this.#didUpdate = false; - this.#root = morph(this.#root, vdom, dispatch, this.#isComponent); + this.#didUpdate = false; + this.#root = morph(this.#root, vdom, dispatch, this.#isComponent); + } } #flush_queue(iterations = 0) { while (this.#queue.length) { const [next, effects] = this.#update(this.#model, this.#queue.shift()); - this.#didUpdate ||= !isEqual(this.#model, next); + this.#didUpdate ||= this.#model === next; this.#model = next; this.#effects = this.#effects.concat(effects.all.toArray()); } |