balderdashy / mast

UI conventions built on top of Backbone.JS
MIT License
81 stars 14 forks source link

route middleware #33

Open mikermcneil opened 12 years ago

mikermcneil commented 12 years ago

There is logic that should be performed before every route, on on the very first route.

These should probably have a filesystem convention, whether that's to put them in a file in the /mast/routes directory or in the top level /mast dir.

Tentative spec:

Mast.beforeEachRoute(fullRoute,arguments*) {

}
Mast.beforeFirstRoute(fullRoute,arguments*) {

}

Where arguments* are standard Backbone route arguments, e.g.: #/:arg1/:arg2 and fullRoute is the complete route string.

mikermcneil commented 11 years ago

Proper middleware is a better bet-- should come back to this as far as normalizing a reusable client-side router for running sails on the client as well at some point down the road @sgress454 what do you think?

mikermcneil commented 11 years ago

Synchronous middleware

FRAMEWORK.define('Toggle', function () {
  return {

    // Verify that the toggle is enabled
    // if so, flip its active state,
    // then prevent the event from bubbling up
    click: [ 'checkEnabled', 'toggle', '.' ],

    // If you return something falsey (or don't return), the chain ends
    // otherwise, the middleware chain continues
    checkEnabled: function () {
      return ! this.disabled;
    },

    // Toggle the active class
    // (all shorthand returns true)
    toggle: '! .active'
  };
});