bulma-carousel
bulma-carousel copied to clipboard
Remove carousel method. How to release memory?
There is method attach
to init carousel but is there method to remove all event listeners etc?
@TotallWAR you can use something like this
bCarousel = bulmaCarousel.attach('.carousel', {
infinite: true,
navigation: false,
pagination: false,
slidesToShow: 2,
navigationSwipe: true,
});
bCarousel.destroy();
As attach returns an array it must be
bCarousel[0].destroy()
but I get
Uncaught TypeError: this.off is not a function
at bulmaCarousel._unbindEvents (VM116 bulma-carousel.js:629)
at bulmaCarousel.destroy (VM116 bulma-carousel.js:863)
any thougths?
Same here:
Uncaught TypeError: this.off is not a function
at bulmaCarousel._unbindEvents (bulma-carousel.js:620:12)
at bulmaCarousel.destroy (bulma-carousel.js:854:12)
at Object.beforeNext (index.js:89:23)
at bulmaSteps.next_step (bulma-steps.js:263:31)
at bulmaSteps.value (bulma-steps.js:207:14)
Also this.node.remove()
is also not a thing.
@adminy, my workarround was
attachCarousel: (elem) => {
carru.instance = bulmaCarousel.attach(elem, {
slidesToScroll: 1,
slidesToShow: 5,
});
},
killCarousel: function (elem) {
if (Array.isArray(carru.instance)) {
elem.replaceChildren();
delete carru.instance;
}
},
Thanks @gentilmente, I needed like 5% from this project, so I just built a small module, that does just what I wanted it to do.
Future libraries:
- Define a state, which is the input
- provide utilities that help transform input state to output state. This is extremely important that its utilities, and not objects taking away the input just to give you a broken promise of what you can do with such state. If its a bulma module, just give the user the css, let it do the js part.
- don't write features, write utilities, takes in A to give out B, don't build systems, build utilities, they will truly be helpful