diff options
Diffstat (limited to 'src/element.ts')
-rw-r--r-- | src/element.ts | 16 |
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) ?? (() => { }) } |