bulma-carousel icon indicating copy to clipboard operation
bulma-carousel copied to clipboard

Remove carousel method. How to release memory?

Open TotallWAR opened this issue 3 years ago • 5 comments

There is method attach to init carousel but is there method to remove all event listeners etc?

TotallWAR avatar Aug 11 '20 09:08 TotallWAR

@TotallWAR you can use something like this

bCarousel = bulmaCarousel.attach('.carousel', {
     infinite: true,
     navigation: false,
     pagination: false,
     slidesToShow: 2,
     navigationSwipe: true,
});
bCarousel.destroy();

panevski avatar Nov 16 '20 14:11 panevski

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?

gentilmente avatar Mar 09 '22 18:03 gentilmente

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 avatar Apr 09 '22 01:04 adminy

@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;
  }
},

gentilmente avatar Apr 12 '22 19:04 gentilmente

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:

  1. Define a state, which is the input
  2. 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.
  3. don't write features, write utilities, takes in A to give out B, don't build systems, build utilities, they will truly be helpful

adminy avatar Apr 23 '22 22:04 adminy