Skip to content

Commit

Permalink
[changed] Export history classes
Browse files Browse the repository at this point in the history
This commit normalizes the way we export history classes. Instead
of automatically creating a new Browser/HashHistory for people when
they require the module, we just export the class like we do with
History and MemoryHistory.

This gives us a few things:

1) We don't have to explain to people that they need to
   import { HashHistory } in order to create their own HashHistory.

2) We don't require people using CommonJS to
   var HashHistory = require('react-router/lib/HashHistory').default
   which sucks
  • Loading branch information
mjackson committed Jun 16, 2015
1 parent 285a61f commit 2389c61
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions doc/03 History/BrowserHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ Example

```js
import { Router } from 'react-router';
import History from 'react-router/lib/BrowserHistory';
import BrowserHistory from 'react-router/lib/BrowserHistory';

React.render((
<Router history={History}>
<Router history={new BrowserHistory}>
{/* ... */}
</Router>
), document.body);
Expand Down
6 changes: 3 additions & 3 deletions doc/03 History/HashHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Normal usage

```js
import { Router } from 'react-router';
import History from 'react-router/lib/HashHistory';
import HashHistory from 'react-router/lib/HashHistory';

React.render((
<Router history={History}>
<Router history={new HashHistory}>
{/* ... */}
</Router>
), document.body);
Expand All @@ -45,7 +45,7 @@ React.render((
Opting in to the `state` features:

```js
import { HashHistory } from 'react-router/lib/HashHistory';
import HashHistory from 'react-router/lib/HashHistory';

// use the default key which is `_key`
var history = new HashHistory({ queryKey: true });
Expand Down
4 changes: 2 additions & 2 deletions modules/BrowserHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function updateCurrentState(extraState) {
* refreshes if HTML5 history is not available, so URLs are always
* the same across browsers.
*/
export class BrowserHistory extends DOMHistory {
class BrowserHistory extends DOMHistory {

constructor(options) {
super(options);
Expand Down Expand Up @@ -108,4 +108,4 @@ export class BrowserHistory extends DOMHistory {

}

export default new BrowserHistory;
export default BrowserHistory;
8 changes: 4 additions & 4 deletions modules/HashHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ function updateCurrentState(queryKey, extraState) {
* Support for persistence of state across page refreshes is provided using a
* combination of a URL query string parameter and DOM storage. However, this
* support is not enabled by default. In order to use it, create your own
* HashHistory, like this:
* HashHistory.
*
* import { HashHistory } from 'react-router/lib/HashHistory';
* import HashHistory from 'react-router/lib/HashHistory';
* var StatefulHashHistory = new HashHistory({ queryKey: '_key' });
* React.render(<Router history={StatefulHashHistory} .../>, ...);
*/
export class HashHistory extends DOMHistory {
class HashHistory extends DOMHistory {

constructor(options={}) {
super(options);
Expand Down Expand Up @@ -170,4 +170,4 @@ export class HashHistory extends DOMHistory {

}

export default new HashHistory;
export default HashHistory;
2 changes: 1 addition & 1 deletion modules/__tests__/BrowserHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import describeHistory from './describeHistory';
import BrowserHistory from '../BrowserHistory';

describe('BrowserHistory', function () {
describeHistory(BrowserHistory);
describeHistory(new BrowserHistory);
});
2 changes: 1 addition & 1 deletion modules/__tests__/HashHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import describeHistory from './describeHistory';
import HashHistory from '../HashHistory';

describe('HashHistory', function () {
describeHistory(HashHistory);
describeHistory(new HashHistory);
});
2 changes: 1 addition & 1 deletion modules/__tests__/scrollManagement-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import expect from 'expect';
import React, { render } from 'react';
import { HashHistory } from '../HashHistory';
import HashHistory from '../HashHistory';
import { getWindowScrollPosition } from '../DOMUtils';
import Router from '../Router';
import Route from '../Route';
Expand Down

0 comments on commit 2389c61

Please sign in to comment.