Skip to content

Instantly share code, notes, and snippets.

@vitkarpov
Created February 5, 2016 17:18
Show Gist options
  • Save vitkarpov/3313ed676e1cc48559e5 to your computer and use it in GitHub Desktop.
Save vitkarpov/3313ed676e1cc48559e5 to your computer and use it in GitHub Desktop.
Jblocks: an example of declaration
jBlocks.define('counter', {
events: {
'click .js-inc': 'inc',
'click .js-dec': 'dec'
},
methods: {
oninit: function() {
this._currentValue = Number(this.params.initialValue);
},
ondestroy: function() {
this._currentValue = null;
},
/**
* Increases the counter, emits changed event
*/
inc: function() {
this._currentValue++;
this.emit('changed', this._currentValue);
},
/**
* Decreases the counter, emits changed event
*/
dec: function() {
this._currentValue--;
this.emit('changed', this._currentValue);
},
/**
* Returns the current value
* @return {Number}
*/
getCurrentValue: function() {
return this._currentValue;
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment