Skip to content

Commit

Permalink
refactor(core): Component servers are now key-value pairs
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Components must now provide key-value pairs in an
object called "servers".
  • Loading branch information
Kevin Delisle committed Sep 29, 2017
1 parent b0e5360 commit 866953a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export interface Component {
// tslint:disable-next-line:no-any
controllers?: Constructor<any>[];
providers?: ProviderMap;
servers?: Constructor<Server>[];
servers?: {
[name: string]: Constructor<Server>;
};

// tslint:disable-next-line:no-any
[prop: string]: any;
Expand All @@ -41,8 +43,8 @@ export function mountComponent(app: Application, component: Component) {
}

if (component.servers) {
for (const server of component.servers) {
app.server(server);
for (const serverKey in component.servers) {
app.server(component.servers[serverKey], serverKey);
}
}
}
9 changes: 7 additions & 2 deletions packages/core/test/unit/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ describe('Application', () => {
});

class FakeComponent implements Component {
servers: Constructor<Server>[] = [];
servers: {
[name: string]: Constructor<Server>;
};
constructor() {
this.servers.push(FakeServer);
this.servers = {
FakeServer,
FakeServer2: FakeServer,
};
}
}

Expand Down
9 changes: 7 additions & 2 deletions packages/rest/src/rest-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ export class RestComponent implements Component {
[RestBindings.SequenceActions.PARSE_PARAMS]: ParseParamsProvider,
[RestBindings.SequenceActions.SEND]: SendProvider,
};
servers: Constructor<Server>[] = [];
servers: {
[name: string]: Constructor<Server>;
};

constructor(
@inject(CoreBindings.APPLICATION_INSTANCE) app: Application,
@inject(RestBindings.CONFIG) config?: RestComponentConfig,
) {
if (!config) config = {};
this.servers.push(RestServer);
this.servers = {
RestServer: RestServer,
};
}
}

Expand Down

0 comments on commit 866953a

Please sign in to comment.