Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions addons/website/static/src/core/colibri.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ export class Colibri {
for (let cleanup of this.cleanups.reverse()) {
cleanup();
}
this.cleanups = [];
for (let [el, ev, fn, options] of this.handlers) {
el.removeEventListener(ev, fn, options);
}
this.handlers = [];
this.classMap.clear();
this.interaction.destroy();
this.interaction.isDestroyed = true;
Expand Down
9 changes: 9 additions & 0 deletions addons/website/static/src/core/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export class Interaction {
});
}

waitForTimeout(fn, delay) {
setTimeout(() => {
if (!this.isDestroyed) {
fn();
this.updateDOM();
}
}, delay)
}

updateDOM() {
this.__colibri__.scheduleUpdate();
}
Expand Down
20 changes: 20 additions & 0 deletions addons/website/static/tests/core/website_core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,23 @@ test("wait for translation before starting interactions", async () => {
await animationFrame();
expect(started).toBe(true);
});


test("starting interactions twice should only actually do it once", async () => {
let n = 0;
class Test extends Interaction {
static selector = ".test";

setup() {
n++;
}
}

const { core } = await startInteraction(Test, `<div class="test"></div>`);

expect(n).toBe(1);
core.startInteractions();
await animationFrame();
expect(n).toBe(1);
});