Skip to content

Commit d77de24

Browse files
committed
attach changeListener to ajax (to properly destroy event listener)
1 parent f620a3d commit d77de24

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

src/ajax.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ export class AjaxHandle extends AjaxUtil {
587587
context.html(payload);
588588
this.ajax.bind(context);
589589
}
590+
context = null;
590591
}
591592

592593
next(operations) {

src/ajaxdestroy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class AjaxDestroy extends Parser {
1717
console.warn('ts.ajax bound but no destroy method defined: ' + instance.constructor.name);
1818
}
1919
}
20+
node._ajax_attached = null; // remove class instances from memory
2021
}
2122

2223
let attrs = this.node_attrs(node);

src/listener.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,17 @@ export function create_listener(event, base=null) {
7474
if (!elem) {
7575
throw 'No element found';
7676
}
77-
ts.ajax.attach(this, elem);
7877
this.elem = elem;
7978
this.event = event;
8079
this.trigger_event = this.trigger_event.bind(this);
8180
this.elem.on(this.event, this.trigger_event);
81+
82+
// attach to ts.ajax
83+
let native_elem = elem[0];
84+
if (native_elem._ajax_attached === undefined) {
85+
native_elem._ajax_attached = [];
86+
}
87+
native_elem._ajax_attached.push(this);
8288
}
8389

8490
trigger_event(evt) {

treibstoff/bundle/treibstoff.bundle.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ var ts = (function (exports, $) {
565565
console.warn('ts.ajax bound but no destroy method defined: ' + instance.constructor.name);
566566
}
567567
}
568+
node._ajax_attached = null;
568569
}
569570
let attrs = this.node_attrs(node);
570571
if (attrs['ajax:bind']) {
@@ -1278,6 +1279,7 @@ var ts = (function (exports, $) {
12781279
context.html(payload);
12791280
this.ajax.bind(context);
12801281
}
1282+
context = null;
12811283
}
12821284
next(operations) {
12831285
if (!operations || !operations.length) {
@@ -1552,11 +1554,15 @@ var ts = (function (exports, $) {
15521554
if (!elem) {
15531555
throw 'No element found';
15541556
}
1555-
ts.ajax.attach(this, elem);
15561557
this.elem = elem;
15571558
this.event = event;
15581559
this.trigger_event = this.trigger_event.bind(this);
15591560
this.elem.on(this.event, this.trigger_event);
1561+
let native_elem = elem[0];
1562+
if (native_elem._ajax_attached === undefined) {
1563+
native_elem._ajax_attached = [];
1564+
}
1565+
native_elem._ajax_attached.push(this);
15601566
}
15611567
trigger_event(evt) {
15621568
this.trigger(`on_${event}`, evt);

treibstoff/bundle/treibstoff.bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)