Skip to content

Bindable: Simple dependency injection for browser based javascript.

License

Notifications You must be signed in to change notification settings

modeset/bindable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bindable

Light weight dependency injection for client side components. Looks for all DOM elements with a data-bindable attribute, stores references within a registry and instantiates their respective classes.

WIP

  • Cleanup docs and describe a little more behind bindable (i.e. local bindables, etc.)
  • Link to Jed's presentation
  • Wrap more tests around bindable's setup
  • Create packages for Bower and Component

Install

Describe this

Usage

As a class making use of the Bindable registry:

var ToggleGroup = (function() {
  function ToggleGroup(el) {
    this.el = el
  }

  ToggleGroup.prototype.dispose = function() {
    // Clean up your mess
  };

  return ToggleGroup

})();
Bindable.register('toggle-group', ToggleGroup);

As markup instantiating a class that is registered with Bindable:

<nav data-bindable="toggle-group">...</nav>

Bindable is created after the page has loaded

var bindable
window.addEventListener('DOMContentLoaded', function() {
  bindable = new Bindable().bindAll()
  // ...
});

API

#bindAll

Binds all elements on the page with a data-bindable attribute with it's respective class.

var bindable = new Bindable()
bindable.bindAll()

#bind

TODO: Describe This!!!!

#getRefs

Returns a listing of all bindable objects on the page.

var bindable = new utensils.Bindable()
bindable.bindAll()
var binded = bindable.getRefs()

#dispose

Calls the dispose method on all bindable objects and cleans out the instance of Bindable.

var bindable = new utensils.Bindable()
bindable.bindAll()
bindable.dispose()

Bindable.getClass

Static method for returning a class instance out of the registry from a key.

var object = Bindable.getClass('key')

Bindable.register

Manually add a bindable object to the registry by passing a key and a class instance.

Bindable.register('my_class', new MyClass())

About

Bindable: Simple dependency injection for browser based javascript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published