aboutsummaryrefslogtreecommitdiff
path: root/src/element.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-27 16:27:06 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-27 16:27:06 +0100
commitb7a3b1b81ed85c95ca8183407971aed724e3b9b2 (patch)
tree19067c7fa1e23bc3152c4292599753d96abc9767 /src/element.ts
parenta1795c9d8c0c88caa65a340a786fe432ce95ee59 (diff)
downloadjshelper-b7a3b1b81ed85c95ca8183407971aed724e3b9b2.tar
jshelper-b7a3b1b81ed85c95ca8183407971aed724e3b9b2.tar.bz2
jshelper-b7a3b1b81ed85c95ca8183407971aed724e3b9b2.tar.zst
fix some bugs where a node was freed twice
Diffstat (limited to 'src/element.ts')
-rw-r--r--src/element.ts16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/element.ts b/src/element.ts
index 51bf42f..6f2a28d 100644
--- a/src/element.ts
+++ b/src/element.ts
@@ -76,30 +76,40 @@ function e_apply<K extends keyof HTMLElementTagNameMap, C extends EEl<K>>(el: HT
return () => { }
}
if (typeof c == "string") {
- el.append(c)
+ const node = document.createTextNode(c)
+ el.insertBefore(node, redo?.before ?? null)
return () => {
- el.textContent = ""
+ const p = node.nextSibling as (HTMLElement | void);
+ el.removeChild(node)
+ return { before: p ?? undefined }
}
}
else if (c instanceof HTMLElement) {
el.insertBefore(c, redo?.before ?? null)
return () => {
const p = c.nextSibling as (HTMLElement | void);
+
//@ts-ignore wubbel
const child_undo: undefined | (() => void) = c["jsh_undo"]
+ //@ts-ignore wubbel
+ c["jsh_undo"] = () => alert("double freeā„¢ detected")
if (child_undo) child_undo()
el.removeChild(c)
+
return { before: p ?? undefined }
}
}
else if (c instanceof OVar) {
let undo_last: () => RedoParams | void;
// TODO if nested, this is a memory leak (only partially fixed)
- return c.onchangeinit(val => {
+ const abort = c.onchangeinit(val => {
let redo_param = undefined;
if (undo_last) redo_param = undo_last()
undo_last = e_apply(el, val, redo_param ?? undefined)
})
+ return () => {
+ abort(); undo_last()
+ }
}
else return apply_opts(el, c) ?? (() => { })
}