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

ftlabs/fruitmachine-bindall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published