Skip to content

Commit

Permalink
feat(history-service): make async-ssr-manager dependency optional (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahrradflucht authored and unstubbable committed Jan 11, 2019
1 parent b349021 commit 9e8be1e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
2 changes: 0 additions & 2 deletions docs/guides/sharing-the-browser-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ registers it at the Feature Service registry.
In the browser:

```js
import {defineAsyncSsrManager} from '@feature-hub/async-ssr-manager';
import {FeatureServiceRegistry} from '@feature-hub/core';
import {
defineHistoryService,
Expand All @@ -122,7 +121,6 @@ const rootLocationTransformer = createRootLocationTransformer({
});

const featureServiceDefinitions = [
defineAsyncSsrManager(undefined),
defineHistoryService(rootLocationTransformer)
];

Expand Down
6 changes: 1 addition & 5 deletions packages/demos/src/history-service/integrator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {defineAsyncSsrManager} from '@feature-hub/async-ssr-manager';
import {FeatureAppManager, FeatureServiceRegistry} from '@feature-hub/core';
import {defineHistoryService} from '@feature-hub/history-service';
import {FeatureAppContainer} from '@feature-hub/react';
Expand All @@ -11,10 +10,7 @@ import {rootLocationTransformer} from './root-location-transformer';
const featureServiceRegistry = new FeatureServiceRegistry();

featureServiceRegistry.registerFeatureServices(
[
defineAsyncSsrManager(undefined),
defineHistoryService(rootLocationTransformer)
],
[defineHistoryService(rootLocationTransformer)],
'demo:integrator'
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('defineHistoryService', () => {

expect(historyServiceDefinition.id).toBe('s2:history');

expect(historyServiceDefinition.dependencies).toEqual({
expect(historyServiceDefinition.dependencies).toBeUndefined();
expect(historyServiceDefinition.optionalDependencies).toEqual({
's2:async-ssr-manager': '^1.0'
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/history-service/src/define-history-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export function defineHistoryService(
rootLocationTransformer: RootLocationTransformer
): FeatureServiceProviderDefinition<
undefined,
{'s2:async-ssr-manager': AsyncSsrManagerV1}
{'s2:async-ssr-manager': AsyncSsrManagerV1 | undefined}
> {
return {
id: 's2:history',
dependencies: {'s2:async-ssr-manager': '^1.0'},
optionalDependencies: {'s2:async-ssr-manager': '^1.0'},

create: (env): SharedHistoryService => {
const {serverRequest} = env.featureServices['s2:async-ssr-manager'];
const asyncSsrManager = env.featureServices['s2:async-ssr-manager'];

const historyMultiplexers = createHistoryMultiplexers(
rootLocationTransformer,
serverRequest
asyncSsrManager && asyncSsrManager.serverRequest
);

return {
Expand Down

0 comments on commit 9e8be1e

Please sign in to comment.