Skip to content

Commit

Permalink
feat(core): retain FeatureApp type in FeatureAppDefinition (#214)
Browse files Browse the repository at this point in the history
The `featureAppDefinition` argument provided to `getFeatureAppDefinition`
knows the type of the `FeatureApp`. Retain this type information by
providing it to the returned `FeatureAppScope`.
  • Loading branch information
fahrradflucht authored and clebert committed Jan 2, 2019
1 parent 130b1ab commit 91b205d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions packages/core/src/feature-app-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export interface FeatureAppDefinition<

export type ModuleLoader = (url: string) => Promise<unknown>;

export interface FeatureAppScope {
readonly featureApp: unknown;
export interface FeatureAppScope<TFeatureApp> {
readonly featureApp: TFeatureApp;

destroy(): void;
}
Expand All @@ -56,10 +56,10 @@ export interface FeatureAppManagerLike {
url: string
): AsyncValue<FeatureAppDefinition<unknown>>;

getFeatureAppScope(
featureAppDefinition: FeatureAppDefinition<unknown>,
getFeatureAppScope<TFeatureApp>(
featureAppDefinition: FeatureAppDefinition<TFeatureApp>,
idSpecifier?: string
): FeatureAppScope;
): FeatureAppScope<TFeatureApp>;

preloadFeatureApp(url: string): Promise<void>;
destroy(): void;
Expand All @@ -85,7 +85,7 @@ export class FeatureAppManager implements FeatureAppManagerLike {

private readonly featureAppScopes = new Map<
FeatureAppScopeId,
FeatureAppScope
FeatureAppScope<unknown>
>();

public constructor(
Expand All @@ -107,10 +107,10 @@ export class FeatureAppManager implements FeatureAppManagerLike {
return asyncFeatureAppDefinition;
}

public getFeatureAppScope(
featureAppDefinition: FeatureAppDefinition<unknown>,
public getFeatureAppScope<TFeatureApp>(
featureAppDefinition: FeatureAppDefinition<TFeatureApp>,
idSpecifier?: string
): FeatureAppScope {
): FeatureAppScope<TFeatureApp> {
const {id: featureAppId} = featureAppDefinition;
const featureAppScopeId = JSON.stringify({featureAppId, idSpecifier});

Expand All @@ -131,7 +131,7 @@ export class FeatureAppManager implements FeatureAppManagerLike {
this.featureAppScopes.set(featureAppScopeId, featureAppScope);
}

return featureAppScope;
return featureAppScope as FeatureAppScope<TFeatureApp>;
}

public async preloadFeatureApp(url: string): Promise<void> {
Expand Down Expand Up @@ -197,11 +197,11 @@ export class FeatureAppManager implements FeatureAppManagerLike {
);
}

private createFeatureAppScope(
featureAppDefinition: FeatureAppDefinition<unknown>,
private createFeatureAppScope<TFeatureApp>(
featureAppDefinition: FeatureAppDefinition<TFeatureApp>,
idSpecifier: string | undefined,
deleteFeatureAppScope: () => void
): FeatureAppScope {
): FeatureAppScope<TFeatureApp> {
const {configs} = this.options;
const config = configs && configs[featureAppDefinition.id];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('FeatureAppContainer (on Node.js)', () => {
let mockManager: FeatureAppManagerLike;
let mockGetFeatureAppScope: jest.Mock;
let mockFeatureAppDefinition: FeatureAppDefinition<unknown>;
let mockFeatureAppScope: FeatureAppScope;
let mockFeatureAppScope: FeatureAppScope<unknown>;
let spyConsoleError: jest.SpyInstance;

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('FeatureAppContainer', () => {
let mockManager: FeatureAppManagerLike;
let mockGetFeatureAppScope: jest.Mock;
let mockFeatureAppDefinition: FeatureAppDefinition<unknown>;
let mockFeatureAppScope: FeatureAppScope;
let mockFeatureAppScope: FeatureAppScope<unknown>;
let spyConsoleError: jest.SpyInstance;

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/feature-app-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const inBrowser =
export class FeatureAppContainer extends React.PureComponent<
FeatureAppContainerProps
> {
private readonly featureAppScope?: FeatureAppScope;
private readonly featureAppScope?: FeatureAppScope<unknown>;
private readonly featureApp?: FeatureApp;
private readonly containerRef = React.createRef<HTMLDivElement>();

Expand Down

0 comments on commit 91b205d

Please sign in to comment.