feat: properly destroy objects on disconnect from dom

This commit is contained in:
Björn Fromme
2025-02-11 08:16:30 +01:00
parent 2655b83242
commit 69abf8d49a
4 changed files with 26 additions and 9 deletions
+5 -1
View File
@@ -7,7 +7,7 @@ export default class extends Controller {
static targets = ['item', 'handle']
connect() {
new Sortable(this.element, {
this.sortable = new Sortable(this.element, {
item: '[data-sortable-target="item"]',
handle: '[data-sortable-target="handle"]',
onEnd: e => {
@@ -31,4 +31,8 @@ export default class extends Controller {
body: JSON.stringify({ ordering: ordering })
})
}
disconnect() {
this.sortable.destroy()
}
}