Skip to content

thorlarholm/backbone.advices

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

backbone.advices

Bringing Advices to Backbone.

I always missed "filters" from Railsin Backbone. So I spent a little time adding advices, known from aspect-oriented programming, which acts in a similar way.

The best way to describe backbone.advices, is by showing this example:

Example

var view = Backbone.AdvicesView.extend({

  // Syntax 1
  beforeAdvices: ['ensureQuerystrings'], // -> Getting called before all methods.

  // Syntax 2
  beforeAdvices: [{
    'onBeforeRender' : { only : ['render'] }, //  -> Getting called after render-method.
    'getData' : { except : ['render'] } // -> Getting called after all methods except render-method.
  }],

  afterAdvices: ['handleErrors'], // -> Getting called after all methods.
 
  // Methods
  render: function() {
    // Render Logic
    console.log('render');
  },

  // Advices
  getData: function() {
    console.log('getData');
  }

  handleErrors: function() {
    console.log('handleErrors');
  }

});

About

Bringing Advices to Backbone

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors