Created
February 5, 2016 17:40
-
-
Save vitkarpov/82564d28a0890813a209 to your computer and use it in GitHub Desktop.
jBlocks: example of usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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