Skip to content

Commit

Permalink
fix(core): add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shimks committed Feb 13, 2018
1 parent d6e51e4 commit 3918447
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const app = new Application({
port: 3001,
},
});
app.components([RestComponent, GrpcComponent]);
app.components([
RestComponent, // REST Server
GrpcComponent, // GRPC Server
]);

(async function start() {
// Let's retrieve the bound instances of our servers.
Expand Down
39 changes: 39 additions & 0 deletions packages/core/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ export class Application extends Context {
.tag('controller');
}

/**
* Bind an array of controllers to the Application's master
* context.
* Each controller added in this way will automatically be named based on
* the class constructor name with the "controllers." prefix.
*
* If you wish to control the binding keys for particular controller
* instances, use the app.controller function instead.
* ```ts
* app.controllers([
* FooController,
* BarController,
* ]);
* // Creates a binding for "controllers.FooController" and a binding for
* // "controllers.BarController";
* ```
*
* @param ctors Array of controller classes.
* @returns {Binding[]} An array of bindings for the registered controllers.
*/
controllers(ctors: ControllerClass[]): Binding[] {
return ctors.map(ctor => this.controller(ctor));
}
Expand Down Expand Up @@ -199,6 +219,25 @@ export class Application extends Context {
mountComponent(this, instance);
}

/**
* Add multiple components to this application and register their
* extensions.
*
* Each component added in this way will automatically be named based on the
* class constructor name with the "components." prefix.
*
* If you wish to control the binding keys for particular instances,
* use the app.component function instead.
* ```ts
* app.components([
* RestComponent,
* GRPCComponent,
* ]);
* // Creates a binding for "components.RestComponent" and a binding for
* // "components.GRPCComponent";
* ```
* @param ctors Array of components to add.
*/
public components(ctors: Constructor<Component>[]) {
ctors.map(ctor => this.component(ctor));
}
Expand Down
8 changes: 4 additions & 4 deletions packages/core/test/unit/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ describe('Application', () => {

it('allows binding of multiple servers as an array', async () => {
const app = new Application();
const bindings = app.servers([FakeServer, FakerServer]);
const bindings = app.servers([FakeServer, AnotherServer]);
expect(Array.from(bindings[0].tags)).to.containEql('server');
expect(Array.from(bindings[1].tags)).to.containEql('server');
const fakeResult = await app.getServer(FakeServer);
expect(fakeResult.constructor.name).to.equal(FakeServer.name);
const fakerResult = await app.getServer(FakerServer);
expect(fakerResult.constructor.name).to.equal(FakerServer.name);
const AnotherResult = await app.getServer(AnotherServer);
expect(AnotherResult.constructor.name).to.equal(AnotherServer.name);
});
});

Expand All @@ -138,4 +138,4 @@ class FakeServer extends Context implements Server {
}
}

class FakerServer extends FakeServer {}
class AnotherServer extends FakeServer {}

0 comments on commit 3918447

Please sign in to comment.