Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Allow before and after filters to be created by chaining together declarations #131

merged 1 commit into from Jan 17, 2014


None yet
2 participants

redking commented Jan 17, 2014

Controller before and after filters must be declared in the following way

controller.before('action1', filterA);
controller.before('action1', filterB);
controller.before('action1', filterC);

controller.before('action2', filterA);
controller.before('action2', filterB);

In cases where a controller has many actions and many filters, it would be nice if we could declare filters by chaining the declarations together

 .before('action1', filterA)
 .before('action1', filterB)
 .before('action1', filterC);

 .before('action2', filterA)
 .before('action2', filterB);

This makes the code a little easier to read, and encourages developers to arrange filters into distinct ordered blocks, rather than as code that could be inserted anywhere in the controller.

To support this, I've made two small changes to controller.js, and added a single test to each of the filter test suites, which should be sufficient to test the syntax.

jaredhanson added a commit that referenced this pull request Jan 17, 2014

Merge pull request #131 from redking/filter-chaining
Allow before and after filters to be created by chaining together declarations

@jaredhanson jaredhanson merged commit a677d66 into jaredhanson:master Jan 17, 2014

1 check failed

default The Travis CI build could not complete due to an error

jaredhanson commented Jan 17, 2014

Love it, thanks! Merged and published to npm as locomotive 0.4.1.

@redking redking deleted the redking:filter-chaining branch Jan 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment