Code Monkey home page Code Monkey logo

backbone-route-filter's People

Contributors

fantactuka avatar unindented avatar unsingefou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hakee jackieshiq

backbone-route-filter's Issues

Filters should be inheritable

var ApplicationController = Backbone.Router.extend({
  before: {
    '*any': '_logRoute'
  },

  _logRoute: function() {
    ...
  }
});


var PostsController = ApplicationController.extend({
  before: {
    '*any-post': '_checkAuth'
  },

  _checkAuth: function() {
    ...
  }
});

PostsController before filter should also have '*any': '_logRoute' inherited

docs: how to run test

Add note about how to run test.

I think karma config needs to be updated now.

JASMINE and JASMINE_ADAPTER are not supported anymore.

The before filter does not stop if it finds more than one match

In backbone routes, the router stops matching in case it found a match. In case of the filter, it matched all the filters possible. For eg. If i have to match 'login' and then '*any', it will execute both the filter functions. Is there a way to stop the execution at the first match and not proceed.

Add support for AMD

I have a RequireJS project and I encountered a situation where Backbone is loaded asynchronously via RequireJS after backbone-route-filter expects it to be available. If there is a way to load an AMD dependency before its non-AMD dependant, I haven't found it.

On that note, I've thrown together a quick way to make backbone-route-filter AMD compatible here. If you like, I can test this and open a pull request in a few days.

Thanks for the library!

before filters with ajax request

Taking from the example below, lets say the checkAuthorization is making a ajax request to check the authorization.

Since ajax is asynchronous, I cannot return from checkAuthorization until the ajax is done.

How do i handle such cases?

var Router = Backbone.Router.extend({
  routes: {
    'users': 'usersList',
    'users/:id': 'userShow',
    'account/sign-in': 'signIn'
  },

  before: {
    // Using instance methods
    'users(:/id)': 'checkAuthorization',

    // Using inline filter definition
    '*any': function(fragment, args) {
      console.log('Atempting to load ' + fragment + ' with arguments: ', args);
    }
  },

  after: {
    // Google analytics tracking
    // After filter will be triggered only if all before filters passed and action was triggered,
    // so you'll only track pages that was displayed to user
    '*any': function(fragment) {
      goog._trackPageview(fragment);
    }
  },

  checkAuthorization: function(fragment, args) {
    if (!this._isSignedIn) {

      // Going to sign-in page
      this.signIn();

      // Preventing current route from being handled
      return false;
    }
  }
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.