A fruitmachine helper that binds all the methods in fruitmachine modules to each instance.
npm install fruitmachine-bindallA fruitmachine helper that binds all the methods in fruitmachine modules to each instance.
``js`
var Apple = fruitmachine.define({
name: 'apple',
initialize: function() {
this.onButtonClick = this.onButtonClick.bind(this);
},
setup: function() {
this.el.addEventListener('click', this.onButtonClick);
},
onButtonClick: function() {
this.fire('buttonclick');
},
teardown: function() {
this.el.removeEventListener('click', this.onButtonClick);
}
});
... simplies to this ...
`js``
var Apple = fruitmachine.define({
name: 'apple',
helpers: [require('fruitmachine-bindall')],
setup: function() {
this.el.addEventListener('click', this.onButtonClick);
},
onButtonClick: function() {
this.fire('buttonclick');
},
teardown: function() {
this.el.removeEventListener('click', this.onButtonClick);
}
});
(This makes more of an impact as modules become more complex)
- Wilson Page - @wilsonpage
- Wilson Page - @wilsonpage
- Matt Andrews - @matthew-andrews
All open source code released by FT Labs is licenced under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request. Enjoy...