Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Cona extends HTMLElement {
private _ev: Map<EffectFunction, any>;
private _sr?: ShadowRoot | null = undefined;
private _t?: number | null = undefined;
private _ck = new Set<string>();

/* LifecycleMethods */
public setup?(): void;
Expand Down Expand Up @@ -70,6 +71,7 @@ export class Cona extends HTMLElement {
}

disconnectedCallback() {
this._clearValues();
this.onUnmounted?.();
}

Expand All @@ -81,6 +83,7 @@ export class Cona extends HTMLElement {
*/
private _update(shouldShallowCompareProps = false) {
if (shouldShallowCompareProps && this._shadowCompareObject(this._op, this.props)) return;
this._clearValues();
const renderString = this.render?.(this._render.bind(this));
const { body } = new DOMParser().parseFromString(
renderString || "",
Expand Down Expand Up @@ -157,6 +160,7 @@ export class Cona extends HTMLElement {
if (s.endsWith("=")) {
if (/(p:|on|ref).*$/.test(s)) {
const key = Math.random().toString(36);
this._ck.add(valueString);

Cona._c[key] =
typeof currentValue === "function"
Expand Down Expand Up @@ -285,4 +289,16 @@ export class Cona extends HTMLElement {
{},
);
}

/**
* Clears values that get replaced into the template string, bound to events,
* and used as references.
*/
private _clearValues() {
for (const key of this._ck) {
delete Cona._c[key];
}

this._ck.clear();
}
}