Skip to content

Commit

Permalink
feat(all): reset Feature Service versions to 0.1 (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
clebert authored Jan 11, 2019
1 parent b05808a commit 78a145f
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 61 deletions.
16 changes: 8 additions & 8 deletions packages/async-ssr-manager/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import mockConsole from 'jest-mock-console';
import {
AsyncSsrManagerConfig,
AsyncSsrManagerV1,
AsyncSsrManagerV0,
ServerRequest,
defineAsyncSsrManager
} from '..';
Expand Down Expand Up @@ -41,10 +41,10 @@ describe('defineAsyncSsrManager', () => {
});

describe('#create', () => {
it('creates a shared Feature Service containing version 1.0', () => {
it('creates a shared Feature Service containing version 0.1', () => {
const sharedAsyncSsrManager = asyncSsrManagerDefinition.create(mockEnv);

expect(sharedAsyncSsrManager['1.0']).toBeDefined();
expect(sharedAsyncSsrManager['0.1']).toBeDefined();
});

for (const invalidConfig of [null, {timeout: false}]) {
Expand All @@ -63,13 +63,13 @@ describe('defineAsyncSsrManager', () => {
}
});

describe('AsyncSsrManagerV1', () => {
let asyncSsrManagerBinder: FeatureServiceBinder<AsyncSsrManagerV1>;
describe('AsyncSsrManagerV0', () => {
let asyncSsrManagerBinder: FeatureServiceBinder<AsyncSsrManagerV0>;

beforeEach(() => {
asyncSsrManagerBinder = asyncSsrManagerDefinition.create(mockEnv)[
'1.0'
] as FeatureServiceBinder<AsyncSsrManagerV1>;
'0.1'
] as FeatureServiceBinder<AsyncSsrManagerV0>;
});

it('exposes a serverRequest', () => {
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('defineAsyncSsrManager', () => {
asyncSsrManagerBinder = asyncSsrManagerDefinition.create({
config: undefined,
featureServices: {}
})['1.0'] as FeatureServiceBinder<AsyncSsrManagerV1>;
})['0.1'] as FeatureServiceBinder<AsyncSsrManagerV0>;
});

it('logs a warning', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/async-ssr-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export interface AsyncSsrManagerConfig {
readonly timeout?: number;
}

export interface AsyncSsrManagerV1 {
export interface AsyncSsrManagerV0 {
readonly serverRequest: ServerRequest | undefined;

renderUntilCompleted(render: () => string): Promise<string>;
rerenderAfter(promise: Promise<unknown>): void;
}

interface SharedAsyncSsrManager extends SharedFeatureService {
readonly '1.0': FeatureServiceBinder<AsyncSsrManagerV1>;
readonly '0.1': FeatureServiceBinder<AsyncSsrManagerV0>;
}

export function defineAsyncSsrManager(
Expand All @@ -40,7 +40,7 @@ export function defineAsyncSsrManager(
const asyncSsrManager = new AsyncSsrManager(serverRequest, timeout);

return {
'1.0': () => ({featureService: asyncSsrManager})
'0.1': () => ({featureService: asyncSsrManager})
};
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/async-ssr-manager/src/internal/async-ssr-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AsyncSsrManagerV1, ServerRequest} from '..';
import {AsyncSsrManagerV0, ServerRequest} from '..';
import {setTimeoutAsync} from './set-timeout-async';

async function renderingTimeout(timeout: number): Promise<never> {
Expand All @@ -7,7 +7,7 @@ async function renderingTimeout(timeout: number): Promise<never> {
throw Error(`Got rendering timeout after ${timeout} ms.`);
}

export class AsyncSsrManager implements AsyncSsrManagerV1 {
export class AsyncSsrManager implements AsyncSsrManagerV0 {
private readonly rerenderPromises = new Set<Promise<unknown>>();

public constructor(
Expand Down
6 changes: 3 additions & 3 deletions packages/demos/src/async-ssr-manager/feature-app.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {Card, Label} from '@blueprintjs/core';
import {AsyncSsrManagerV1} from '@feature-hub/async-ssr-manager';
import {AsyncSsrManagerV0} from '@feature-hub/async-ssr-manager';
import {FeatureAppDefinition} from '@feature-hub/core';
import {ReactFeatureApp} from '@feature-hub/react';
import * as React from 'react';

const featureAppDefinition: FeatureAppDefinition<
ReactFeatureApp,
undefined,
{'s2:async-ssr-manager': AsyncSsrManagerV1}
{'s2:async-ssr-manager': AsyncSsrManagerV0}
> = {
id: 'test:hello-world',

dependencies: {
's2:async-ssr-manager': '^1.0'
's2:async-ssr-manager': '^0.1'
},

create: env => {
Expand Down
6 changes: 3 additions & 3 deletions packages/demos/src/async-ssr-manager/integrator.node.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AsyncSsrManagerV1,
AsyncSsrManagerV0,
defineAsyncSsrManager
} from '@feature-hub/async-ssr-manager';
import {FeatureAppManager, FeatureServiceRegistry} from '@feature-hub/core';
Expand All @@ -15,7 +15,7 @@ export default async function renderMainHtml(port: number): Promise<string> {
const integratorDefinition = {
id: 'demos:integrator',
dependencies: {
's2:async-ssr-manager': '1.0'
's2:async-ssr-manager': '^0.1'
}
};

Expand All @@ -30,7 +30,7 @@ export default async function renderMainHtml(port: number): Promise<string> {

const asyncSsrManager = featureServices[
's2:async-ssr-manager'
] as AsyncSsrManagerV1;
] as AsyncSsrManagerV0;

const featureAppManager = new FeatureAppManager(featureServiceRegistry, {
moduleLoader: loadCommonJsModule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {FeatureAppDefinition} from '@feature-hub/core';
import {HistoryServiceV1} from '@feature-hub/history-service';
import {HistoryServiceV0} from '@feature-hub/history-service';
import {ReactFeatureApp} from '@feature-hub/react';
import * as React from 'react';
import {HistoryConsumer} from './history-consumer';

export const historyConsumerDefinition: FeatureAppDefinition<
ReactFeatureApp,
undefined,
{'s2:history': HistoryServiceV1}
{'s2:history': HistoryServiceV0}
> = {
id: 'test:history-consumer',

dependencies: {
's2:history': '^1.0'
's2:history': '^0.1'
},

create: ({featureServices, idSpecifier}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

// tslint:disable:no-non-null-assertion

import {AsyncSsrManagerV1, ServerRequest} from '@feature-hub/async-ssr-manager';
import {AsyncSsrManagerV0, ServerRequest} from '@feature-hub/async-ssr-manager';
import {
FeatureServiceBinder,
FeatureServiceBinding,
FeatureServiceEnvironment
} from '@feature-hub/core';
import {History} from 'history';
import {
HistoryServiceV1,
HistoryServiceV0,
RootLocationTransformer,
defineHistoryService
} from '..';
Expand All @@ -22,7 +22,7 @@ describe('HistoryService#create (on Node.js)', () => {
let createHistoryServiceBinder: (
serverRequest: ServerRequest | undefined,
rootLocationTransformer?: RootLocationTransformer
) => FeatureServiceBinder<HistoryServiceV1>;
) => FeatureServiceBinder<HistoryServiceV0>;

let consoleWarnSpy: jest.SpyInstance;

Expand All @@ -31,24 +31,24 @@ describe('HistoryService#create (on Node.js)', () => {
consoleWarnSpy.mockImplementation(jest.fn());

createHistoryServiceBinder = (serverRequest: ServerRequest | undefined) => {
const mockAsyncSsrManager: Partial<AsyncSsrManagerV1> = {serverRequest};
const mockAsyncSsrManager: Partial<AsyncSsrManagerV0> = {serverRequest};

const mockEnv: FeatureServiceEnvironment<
undefined,
{'s2:async-ssr-manager': AsyncSsrManagerV1}
{'s2:async-ssr-manager': AsyncSsrManagerV0}
> = {
config: undefined,
featureServices: {
's2:async-ssr-manager': mockAsyncSsrManager as AsyncSsrManagerV1
's2:async-ssr-manager': mockAsyncSsrManager as AsyncSsrManagerV0
}
};

const sharedHistoryService = defineHistoryService(
testRootLocationTransformer
).create(mockEnv);

return sharedHistoryService['1.1'] as FeatureServiceBinder<
HistoryServiceV1
return sharedHistoryService['0.1'] as FeatureServiceBinder<
HistoryServiceV0
>;
};
});
Expand All @@ -58,10 +58,10 @@ describe('HistoryService#create (on Node.js)', () => {
});

describe('#createStaticHistory()', () => {
let historyBinding1: FeatureServiceBinding<HistoryServiceV1>;
let historyBinding2: FeatureServiceBinding<HistoryServiceV1>;
let historyService1: HistoryServiceV1;
let historyService2: HistoryServiceV1;
let historyBinding1: FeatureServiceBinding<HistoryServiceV0>;
let historyBinding2: FeatureServiceBinding<HistoryServiceV0>;
let historyService1: HistoryServiceV0;
let historyService2: HistoryServiceV0;
let history1: History;
let history2: History;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// tslint:disable:no-non-null-assertion

import {AsyncSsrManagerV1} from '@feature-hub/async-ssr-manager';
import {AsyncSsrManagerV0} from '@feature-hub/async-ssr-manager';
import {
FeatureServiceBinder,
FeatureServiceBinding,
FeatureServiceEnvironment
} from '@feature-hub/core';
import {History} from 'history';
import {HistoryServiceV1, defineHistoryService} from '..';
import {HistoryServiceV0, defineHistoryService} from '..';
import {testRootLocationTransformer} from '../internal/test-root-location-transformer';

const simulateOnPopState = (state: unknown, url: string) => {
Expand All @@ -34,7 +34,7 @@ describe('defineHistoryService', () => {

describe('#create', () => {
let createHistoryServiceBinder: () => FeatureServiceBinder<
HistoryServiceV1
HistoryServiceV0
>;

let pushStateSpy: jest.SpyInstance;
Expand All @@ -50,7 +50,7 @@ describe('defineHistoryService', () => {
consoleWarnSpy = jest.spyOn(console, 'warn');
consoleWarnSpy.mockImplementation(jest.fn());

const mockAsyncSsrManager: Partial<AsyncSsrManagerV1> = {
const mockAsyncSsrManager: Partial<AsyncSsrManagerV0> = {
serverRequest: {
path: '/example',
cookies: {},
Expand All @@ -60,11 +60,11 @@ describe('defineHistoryService', () => {

const mockEnv: FeatureServiceEnvironment<
undefined,
{'s2:async-ssr-manager': AsyncSsrManagerV1}
{'s2:async-ssr-manager': AsyncSsrManagerV0}
> = {
config: undefined,
featureServices: {
's2:async-ssr-manager': mockAsyncSsrManager as AsyncSsrManagerV1
's2:async-ssr-manager': mockAsyncSsrManager as AsyncSsrManagerV0
}
};

Expand All @@ -73,8 +73,8 @@ describe('defineHistoryService', () => {
testRootLocationTransformer
).create(mockEnv);

return sharedHistoryService['1.1'] as FeatureServiceBinder<
HistoryServiceV1
return sharedHistoryService['0.1'] as FeatureServiceBinder<
HistoryServiceV0
>;
};
});
Expand All @@ -94,8 +94,8 @@ describe('defineHistoryService', () => {
});

describe('#createBrowserHistory()', () => {
let historyBinding1: FeatureServiceBinding<HistoryServiceV1>;
let historyBinding2: FeatureServiceBinding<HistoryServiceV1>;
let historyBinding1: FeatureServiceBinding<HistoryServiceV0>;
let historyBinding2: FeatureServiceBinding<HistoryServiceV0>;
let history1: History;
let history2: History;

Expand Down
12 changes: 6 additions & 6 deletions packages/history-service/src/define-history-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AsyncSsrManagerV1} from '@feature-hub/async-ssr-manager';
import {AsyncSsrManagerV0} from '@feature-hub/async-ssr-manager';
import {
FeatureServiceBinder,
FeatureServiceProviderDefinition,
Expand All @@ -7,24 +7,24 @@ import {
import * as history from 'history';
import {RootLocationTransformer} from './create-root-location-transformer';
import {createHistoryMultiplexers} from './internal/create-history-multiplexers';
import {createHistoryServiceV1Binder} from './internal/create-history-service-v1-binder';
import {createHistoryServiceV0Binder} from './internal/create-history-service-v0-binder';

export interface HistoryServiceV1 {
export interface HistoryServiceV0 {
staticRootLocation: history.Location;

createBrowserHistory(): history.History;
createStaticHistory(): history.History;
}

interface SharedHistoryService extends SharedFeatureService {
readonly '1.1': FeatureServiceBinder<HistoryServiceV1>;
readonly '0.1': FeatureServiceBinder<HistoryServiceV0>;
}

export function defineHistoryService(
rootLocationTransformer: RootLocationTransformer
): FeatureServiceProviderDefinition<
undefined,
{'s2:async-ssr-manager': AsyncSsrManagerV1 | undefined}
{'s2:async-ssr-manager': AsyncSsrManagerV0 | undefined}
> {
return {
id: 's2:history',
Expand All @@ -39,7 +39,7 @@ export function defineHistoryService(
);

return {
'1.1': createHistoryServiceV1Binder(historyMultiplexers)
'0.1': createHistoryServiceV0Binder(historyMultiplexers)
};
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {FeatureServiceBinder, FeatureServiceBinding} from '@feature-hub/core';
import * as history from 'history';
import {HistoryServiceV1} from '../define-history-service';
import {HistoryServiceV0} from '../define-history-service';
import {BrowserConsumerHistory} from './browser-consumer-history';
import {HistoryMultiplexers} from './create-history-multiplexers';
import {StaticConsumerHistory} from './static-consumer-history';

export function createHistoryServiceV1Binder(
export function createHistoryServiceV0Binder(
historyMultiplexers: HistoryMultiplexers
): FeatureServiceBinder<HistoryServiceV1> {
return (consumerUid: string): FeatureServiceBinding<HistoryServiceV1> => {
): FeatureServiceBinder<HistoryServiceV0> {
return (consumerUid: string): FeatureServiceBinding<HistoryServiceV0> => {
let browserConsumerHistory: BrowserConsumerHistory | undefined;
let staticConsumerHistory: history.History | undefined;

const featureService: HistoryServiceV1 = {
const featureService: HistoryServiceV0 = {
createBrowserHistory: () => {
if (browserConsumerHistory) {
console.warn(
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/__tests__/feature-app-loader.node.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// tslint:disable:no-implicit-dependencies

import {AsyncSsrManagerV1} from '@feature-hub/async-ssr-manager';
import {AsyncSsrManagerV0} from '@feature-hub/async-ssr-manager';
import {
AsyncValue,
FeatureAppDefinition,
Expand All @@ -14,7 +14,7 @@ import {shallow} from 'enzyme';
import * as React from 'react';
import {FeatureAppLoader} from '..';

interface MockAsyncSsrManager extends AsyncSsrManagerV1 {
interface MockAsyncSsrManager extends AsyncSsrManagerV0 {
rerenderAfter: ((promise: Promise<unknown>) => void) & jest.Mock;
}

Expand Down
Loading

0 comments on commit 78a145f

Please sign in to comment.