Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Updates README; removes history.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesplease committed Oct 6, 2014
1 parent 2eea2d2 commit 246718f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 75 deletions.
76 changes: 19 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,39 @@ This library is not an effort to rewrite Backbone.history. As such, some of Hist
over, too. For instance, the order that you specify your callbacks in *still* matters, as this is how `Backbone.History` matches routes.

- [Getting Started](#getting-started)
- [Backwards Compatibility](#backwards-compatibility)
- [History](#history)
- [A Single Point of Entry](#a-single-point-of-entry)
- [The Single Point of Entry](#the-single-point-of-entry)
- [Removed Features](#removed-features)
- [Example Usage](#example-usage)
- [API](#api)
- [history](#history)
- [onNavigate](#onnavigate-routedata-)
- [Removed Features](#removed-features)
- [Accessing the options passed to `route`](#accessing-the-options-passed-to-route)
- [Example Usage](#example-usage)

### Getting Started

#### Backwards Compatibility

This library is backwards compatible with any existing Backbone application. It can even run concurrently
alongside an existing Router.

#### History

Backbone's Router is intimately tied to Backbone.History (more specifically, an instance
of that Class called Backbone.history). With a regular Router you can't specify what instance
of history that you're using, but you can with this one. To use a different instance of History, specify the
`history` property on the Router.
### Getting Started

#### A Single Point of Entry
#### The Single Point of Entry

The API for the Base Router is simple: there's a single callback that gets called when a Route is navigated
to. This callback is a plethora of information you might need, such as parsed query
parameters and whatever object was associated with the callback. This is the location
where you build your abstractions from.

## API
#### Removed features

### `history`
Backbone.BaseRouter does more for you by doing less. The following features were removed from the router.

The instance of `history` to use in conjunction with this Router. Defaults to `Backbone.history`.
- A callback, if specified, is not automatically executed
- No routing-related events are fired

The point of removing these features is that it gives you complete control over the Routing
mechanism. It's simple to add them back in. Or you can change them to be exactly how you
want. Or just leave them out. It's entirely up to you.

#### Example Usage

See the [`examples/`](https://github.com/jmeas/backbone.base-router/tree/updates/examples) directory. There are READMEs for each example.

## API

### `onNavigate( routeData )`

Expand Down Expand Up @@ -112,38 +109,3 @@ The router instance that this route was registered on.
##### `uriFragment`

The URI fragment that was matched.

### Removed features

Backbone.BaseRouter does more for you by doing less. The following features were removed from the router.

- A callback, if specified, is not executed
- Related to the above; the `trigger` option to the `navigate` method no longer exists
- No routing-related events are fired

The point of removing these features is that it gives you complete control over the Routing
mechanism. It's simple to add them back in. Or you can change them to be exactly how you
want. Or just leave them out. It's entirely up to you.

### Accessing the options passed to `route`

As you might already know, you can pass options when you call the `route` method.

```js
myRouter.navigate('some/path', {myOption: true});
```

Backbone Routers do not get these options back. They're sent off to History, which does not
return them. Because this library is *just* a Router, it doesn't let you access those options. However, if you want
these options you can use [Backbone.BaseHistory](https://github.com/jmeas/backbone.base-history) in conjunction
with this library. If you use that library you will receive those options in your `routeData` as a property
called `navOptions`.

```js
var BaseHistory = require('BaseHistory');
myRoute.history = new baseHistory();
```

## Example Usage

See the [`examples/`](https://github.com/jmeas/backbone.base-router/tree/updates/examples) directory. There are READMEs for each example.
5 changes: 1 addition & 4 deletions src/backbone.base-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;

Backbone.BaseRouter = Backbone.Router.extend({

// The instance of history that this Router uses
history: Backbone.history,

// The single point of entry. This is called whenever a
// route is matched. The routeData argument contains lots of
// useful information.
Expand All @@ -36,7 +33,7 @@ Backbone.BaseRouter = Backbone.Router.extend({

// Register a callback with history
var router = this;
this.history.route(route, function(fragment, navOptions) {
Backbone.history.route(route, function(fragment, navOptions) {
var routeParams = router._extractParameters(route, fragment);
var queryString = routeParams.pop();

Expand Down
14 changes: 0 additions & 14 deletions test/unit/base-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ describe('Base Router', function() {
this.sinon.spy(this.router, 'onNavigate');
});

describe('when specifying a different instance of history', function() {
beforeEach(function() {
this.newHistory = { route: this.sinon.stub() };
this.router.history = this.newHistory;
this.sinon.spy(Backbone.history, 'route');
this.router.route('what', true);
});

it('should route on the specified history, not Backbone.history', function() {
expect(Backbone.history.route).to.not.have.been.called;
expect(this.newHistory.route).to.have.been.calledOnce;
});
});

describe('when routing to a matched route with pushState', function() {
beforeEach(function() {
Backbone.history.location = new this.Location('http://example.com/example');
Expand Down

0 comments on commit 246718f

Please sign in to comment.