1.0.3 • Published 10 years ago

barf v1.0.3

Weekly downloads
10
License
MIT
Repository
github
Last release
10 years ago

Barf - Backbone Async Route Filter

Backbone Async Route Filter - Express style async route filters.

Installation

  npm install barf

or if you're into bower

  bower install --save barf

Usage

module.exports = Backbone.Router.extend({

  routes: {
    'users': 'usersList',
    'users/:id': 'userShow'
  },

  before: {
    // Using instance methods
    'users(/:id)': 'checkAuth',
    
    // Using inline filter definition
    '*any': function (fragment, args, next) {
      console.log('Attempting to load ' + fragment + ' with arguments: ', args);
      next();
    }
  },

  after: {
    // Google analytics tracking
    '*any': function (fragment, args, next) {
      goog._trackPageview(fragment);
      next();
    }
  },

  checkAuth: function (fragment, args, next) {

    // make ajax to check authorisation here.
    $.ajax({
      data: somedata,
      success: function () {
        // if logged in execute next() to move ahead.
        next();
      },
      error: function () {
        //redirect to signIn page.
        Backbone.history.navigate('', {
          trigger: true 
        });
      }
    });
  }
});

LICENSE

MIT

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago