Keeping the instance running

If inside the hook or the DOM event we need to use a function that does not execute immediately we must use the keepInst() function, it wraps the function that must be executed and returns a callback that when executed executes the involved function:

import { _ } from "bemtv";

const { click$, keepInst, $, template } = _`Counter`({ count: 0 });

click$(() => {
  setTimeout(
    keepInst(() => $.count++),
    1000
  );
});

template`button[Clicked: $count ]`;

Last updated