Skip to content

Commit

Permalink
Revert "Add browser history provider to fusion-plugin-react-router (#738
Browse files Browse the repository at this point in the history
)"

This reverts commit 698e000.
  • Loading branch information
chrisdothtml committed Apr 21, 2020
1 parent 698e000 commit 5a6d085
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 122 deletions.
37 changes: 0 additions & 37 deletions fusion-plugin-react-router/README.md
Expand Up @@ -174,23 +174,6 @@ app.register(GetStaticContextToken, (ctx: Context) => {
});
```

##### `BrowserHistoryToken`

```js
import {BrowserHistoryToken} from 'fusion-plugin-react-router';
```

Token for exposing the browser's history to providers. See "Accessing History" below for more.


##### `browserHistoryPlugin`

```jsx
import {browserHistoryPlugin} from 'fusion-plugin-react-router';
```

Plugin for exposing the browser's history to providers. See "Accessing History" below for more.

---

#### Routing Events and Timing Metrics
Expand Down Expand Up @@ -237,26 +220,6 @@ app.register(createPlugin({
}));
```

Alternatively, you can access the history on the browser using `BrowserHistoryToken` and `browserHistoryPlugin`.

```js
import {createPlugin} from 'fusion-core';
import {BrowserHistoryToken, browserHistoryPlugin} from 'fusion-plugin-react-router';

app.register(BrowserHistoryToken, browserHistoryPlugin);
app.register(createPlugin({
deps: {
history: BrowserHistoryToken
},
provides: ({history}) => {
// ...
}
}))
```

This is useful if you want to get the browser's history within a provider.


#### Router

Configures a router and acts as a React context provider for routing concerns. The plugin already provides `<Router>` in the middleware for your application.
Expand Down
47 changes: 0 additions & 47 deletions fusion-plugin-react-router/__tests__/plugin.js
Expand Up @@ -19,8 +19,6 @@ import RouterPlugin, {
RouterProviderToken,
RouterToken,
GetStaticContextToken,
BrowserHistoryToken,
browserHistoryPlugin,
} from '../src/plugin';

const addRoutePrefix = (ctx, next) => {
Expand Down Expand Up @@ -414,51 +412,6 @@ if (__BROWSER__) {
const simulator = setup(app);
await simulator.render('/');
});

test('Browser History Provider', async () => {
const element = <div />;

const app = getApp(element);
const UniversalEvents = getMockEvents({
title: '/',
page: '/',
});

let middlewareHistory;
let providerHistory;

app.register(UniversalEventsToken, UniversalEvents);
app.register(BrowserHistoryToken, browserHistoryPlugin);
app.register(
createPlugin({
deps: {
history: BrowserHistoryToken,
},
provides({history}) {
expect(history).toBeTruthy();
providerHistory = history;
},
})
);

app.middleware(
{
router: RouterToken,
},
({router}) => (ctx, next) => {
const {history} = router.from(ctx);
expect(history).toBeTruthy();
middlewareHistory = history;
return next();
}
);
const simulator = setup(app);
await simulator.render('/');

expect(middlewareHistory).toBe(providerHistory);

cleanup();
});
}

function getMockEvents({
Expand Down
10 changes: 1 addition & 9 deletions fusion-plugin-react-router/src/index.js
Expand Up @@ -10,8 +10,6 @@ import plugin, {
RouterProviderToken,
RouterToken,
GetStaticContextToken,
BrowserHistoryToken,
browserHistoryPlugin,
} from './plugin';
import * as server from './server';
import * as browser from './browser';
Expand All @@ -22,13 +20,7 @@ declare var __BROWSER__: Boolean;

export default plugin;

export {
RouterProviderToken,
RouterToken,
GetStaticContextToken,
BrowserHistoryToken,
browserHistoryPlugin,
};
export {RouterProviderToken, RouterToken, GetStaticContextToken};

export const BrowserRouter = __BROWSER__
? browser.BrowserRouter
Expand Down
30 changes: 1 addition & 29 deletions fusion-plugin-react-router/src/plugin.js
Expand Up @@ -18,7 +18,6 @@ import {
unescape,
memoize,
RouteTagsToken,
RoutePrefixToken,
} from 'fusion-core';
import type {Token, Context, FusionPlugin} from 'fusion-core';

Expand Down Expand Up @@ -64,33 +63,6 @@ type PluginDepsType = {
// Preserve browser history instance across HMR
let browserHistory;

function getBrowserHistory(basename = '') {
// Note that for a given client, the route prefix is static.
// That makes it safe to do this caching.
if (__BROWSER__) {
if (!browserHistory || (__DEV__ && typeof window.jsdom !== 'undefined')) {
browserHistory = createBrowserHistory({basename});
}
}
return browserHistory;
}

export const BrowserHistoryToken = createToken<RouterHistoryType>(
'BrowserHistory'
);

type BrowserHistoryDepsType = {
prefix: typeof RoutePrefixToken.optional,
};

export const browserHistoryPlugin = createPlugin<
BrowserHistoryDepsType,
RouterHistoryType
>({
deps: {prefix: RoutePrefixToken.optional},
provides: ({prefix}) => getBrowserHistory(prefix || ''),
});

const plugin: FusionPlugin<PluginDepsType, HistoryWrapperType> = createPlugin({
deps: {
emitter: UniversalEventsToken.optional,
Expand Down Expand Up @@ -202,7 +174,7 @@ const plugin: FusionPlugin<PluginDepsType, HistoryWrapperType> = createPlugin({
!browserHistory ||
(__DEV__ && typeof window.jsdom !== 'undefined')
) {
browserHistory = getBrowserHistory(ctx.prefix);
browserHistory = createBrowserHistory({basename: ctx.prefix});
}
// Expose the history object
myAPI.history = browserHistory;
Expand Down

0 comments on commit 5a6d085

Please sign in to comment.