Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Latest commit

 

History

History
60 lines (46 loc) · 1.54 KB

README.md

File metadata and controls

60 lines (46 loc) · 1.54 KB

fruitmachine-bindAll

A fruitmachine helper that binds all the methods in fruitmachine modules to each instance.

Example

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 ...

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)

Why isn't this the default behaviour of fruitmachine?

Because we believe it isn't always needed (and sometimes isn't expected).

Author

Contributors

Credits and collaboration

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.