diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-08-19 22:51:13 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-08-19 22:51:13 +0100 |
commit | fc4ab365375128421b95b2faff1b529818963785 (patch) | |
tree | d2e528954084b62c4bf585fb308661a1cd50c3eb | |
parent | ffc607ad1caf4683a63e405c609a9c48b2ce418e (diff) | |
download | lustre-fc4ab365375128421b95b2faff1b529818963785.tar.gz lustre-fc4ab365375128421b95b2faff1b529818963785.zip |
:zap: Trade expensive 'instanceof' checks for fast duck typed ones in vdom diffing.
-rw-r--r-- | lib/src/runtime.ffi.mjs | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/src/runtime.ffi.mjs b/lib/src/runtime.ffi.mjs index 36b6f4a..0994231 100644 --- a/lib/src/runtime.ffi.mjs +++ b/lib/src/runtime.ffi.mjs @@ -1,26 +1,21 @@ -import { element, namespaced, text } from "./lustre/element.mjs"; import { List, Empty } from "./gleam.mjs"; import { Some, None } from "../gleam_stdlib/gleam/option.mjs"; -const Element = element("").constructor; -const ElementNs = namespaced("", "").constructor; -const Text = text("").constructor; - export function morph(prev, curr, parent) { - if (curr instanceof ElementNs) + if (curr[3]) return prev?.nodeType === 1 && prev.nodeName === curr[0].toUpperCase() && prev.namespaceURI === curr[3] ? morphElement(prev, curr, curr[3], parent) : createElement(prev, curr, curr[3], parent); - if (curr instanceof Element) { + if (curr[2]) { return prev?.nodeType === 1 && prev.nodeName === curr[0].toUpperCase() ? morphElement(prev, curr, null, parent) : createElement(prev, curr, null, parent); } - if (curr instanceof Text) { + if (curr[0]) { return prev?.nodeType === 3 ? morphText(prev, curr) : createText(prev, curr); |