Skip to content

Instantly share code, notes, and snippets.

@vitkarpov
Created February 5, 2016 17:40
Show Gist options
  • Save vitkarpov/82564d28a0890813a209 to your computer and use it in GitHub Desktop.
Save vitkarpov/82564d28a0890813a209 to your computer and use it in GitHub Desktop.
jBlocks: example of usage
// somewhere in my program, when DOM is ready...
var counter = jBlocks.get(document.querySelector('.js-counter'));
// use event to react on what happens during lifecycle
counter.on('changed', function() {
console.log('hello, world!');
});
// ... when user clicks on inc button
// log => 'hello, world!'
// log => 3, cause the counter has been increased
counter.getCurrentValue();
// ... then I decided to decrease it using API
counter.dec();
// log => 2
counter.getCurrentValue();
// If I remove nodes from DOM, instance should be destroyed
counter.destroy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment