# barf

> async before and after filters for Backbone.Router

Latest version **1.0.3** (published 2014-03-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install barf
pnpm add barf
yarn add barf
bun add barf
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2014-03-10 |
| First published | 2014-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | svnlto |
| Keywords | bacbkone, async, before, after, filter |

## Links

- npm: https://www.npmjs.com/package/barf
- Repository: https://github.com/svnlto/barf
- Issues: https://github.com/svnlto/barf/issues
- npm.io page: https://npm.io/package/barf

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2014-03-10
- 1.0.2 — 2014-03-03
- 1.0.1 — 2014-03-03

## README

# Barf - Backbone Async Route Filter

Backbone Async Route Filter - Express style async route filters.

## Installation

```js
  npm install barf
```

or if you're into bower

```js
  bower install --save barf
```

## Usage

```js

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

---
_Source: https://npm.io/package/barf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
