From 2389c61e64cdd586b9ed109a85fd792b0e4a7b36 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 16 Jun 2015 10:40:20 -0400 Subject: [PATCH] [changed] Export history classes 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 --- doc/03 History/BrowserHistory.md | 4 ++-- doc/03 History/HashHistory.md | 6 +++--- modules/BrowserHistory.js | 4 ++-- modules/HashHistory.js | 8 ++++---- modules/__tests__/BrowserHistory-test.js | 2 +- modules/__tests__/HashHistory-test.js | 2 +- modules/__tests__/scrollManagement-test.js | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/03 History/BrowserHistory.md b/doc/03 History/BrowserHistory.md index 072470d7a2..ab2a4673f5 100644 --- a/doc/03 History/BrowserHistory.md +++ b/doc/03 History/BrowserHistory.md @@ -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(( - + {/* ... */} ), document.body); diff --git a/doc/03 History/HashHistory.md b/doc/03 History/HashHistory.md index 77fbc03b7d..e48371935c 100644 --- a/doc/03 History/HashHistory.md +++ b/doc/03 History/HashHistory.md @@ -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(( - + {/* ... */} ), document.body); @@ -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 }); diff --git a/modules/BrowserHistory.js b/modules/BrowserHistory.js index 3eb0a01df4..c611e20de0 100644 --- a/modules/BrowserHistory.js +++ b/modules/BrowserHistory.js @@ -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); @@ -108,4 +108,4 @@ export class BrowserHistory extends DOMHistory { } -export default new BrowserHistory; +export default BrowserHistory; diff --git a/modules/HashHistory.js b/modules/HashHistory.js index 4c01bcc3c9..dc8bbbc399 100644 --- a/modules/HashHistory.js +++ b/modules/HashHistory.js @@ -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(, ...); */ -export class HashHistory extends DOMHistory { +class HashHistory extends DOMHistory { constructor(options={}) { super(options); @@ -170,4 +170,4 @@ export class HashHistory extends DOMHistory { } -export default new HashHistory; +export default HashHistory; diff --git a/modules/__tests__/BrowserHistory-test.js b/modules/__tests__/BrowserHistory-test.js index c15dcba48c..ae65130ce5 100644 --- a/modules/__tests__/BrowserHistory-test.js +++ b/modules/__tests__/BrowserHistory-test.js @@ -2,5 +2,5 @@ import describeHistory from './describeHistory'; import BrowserHistory from '../BrowserHistory'; describe('BrowserHistory', function () { - describeHistory(BrowserHistory); + describeHistory(new BrowserHistory); }); diff --git a/modules/__tests__/HashHistory-test.js b/modules/__tests__/HashHistory-test.js index 3b3457b53f..24ec216b7a 100644 --- a/modules/__tests__/HashHistory-test.js +++ b/modules/__tests__/HashHistory-test.js @@ -2,5 +2,5 @@ import describeHistory from './describeHistory'; import HashHistory from '../HashHistory'; describe('HashHistory', function () { - describeHistory(HashHistory); + describeHistory(new HashHistory); }); diff --git a/modules/__tests__/scrollManagement-test.js b/modules/__tests__/scrollManagement-test.js index d72423b731..012ee5c9c6 100644 --- a/modules/__tests__/scrollManagement-test.js +++ b/modules/__tests__/scrollManagement-test.js @@ -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';