Skip to content
This repository was archived by the owner on Feb 2, 2018. It is now read-only.

Commit 1149eaa

Browse files
committed
Apply feedback
1 parent f27e494 commit 1149eaa

File tree

11 files changed

+33
-82
lines changed

11 files changed

+33
-82
lines changed

.vscode/tasks.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"tasks": [
66
{
77
"taskName": "Watch and compile TypeScript",
8-
"command": "tsc",
9-
"args": ["--watch"],
8+
"command": "npm",
9+
"args": ["--silent", "run", "build:watch"],
1010
"type": "process",
1111
"isBackground": true,
1212
"problemMatcher": "$tsc-watch",
@@ -24,11 +24,7 @@
2424
{
2525
"taskName": "Test and lint",
2626
"command": "npm",
27-
"args": [
28-
"--silent",
29-
"run",
30-
"vscode-test"
31-
],
27+
"args": ["--silent", "run", "test:dev"],
3228
"type": "process",
3329
"group": {
3430
"kind": "test",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
"build": "npm run build:lib && npm run build:lib6",
1111
"build:lib": "tsc --target es2017 --outDir dist",
1212
"build:lib6": "tsc --target es2015 --outDir dist6",
13+
"build:watch": "tsc --watch",
1314
"clean": "rm -rf dist dist6",
1415
"lint": "tslint -c tslint.full.json --project tsconfig.json --type-check",
1516
"lint:fix": "npm run lint -- --fix",
1617
"prepublish": "npm run build",
1718
"pretest": "npm run clean && npm run build",
1819
"test": "mocha",
1920
"posttest": "npm run lint",
20-
"vscode-test": "mocha && npm run lint"
21+
"test:dev": "mocha && npm run lint"
2122
},
2223
"repository": {
2324
"type": "git",
@@ -41,7 +42,6 @@
4142
"@loopback/testlab": "^4.0.0-alpha.7",
4243
"@types/mocha": "^2.2.43",
4344
"mocha": "^3.5.3",
44-
"ts-node": "^3.3.0",
4545
"tslint": "^5.7.0",
4646
"typescript": "^2.5.2"
4747
}

src/controllers/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Controllers
2+
3+
This directory contains source files for the controllers exported by this extension.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
export * from './logger-mixin';
6+
export * from './mixins/logger.mixin';

src/logger-mixin/index.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/logger-mixin/mixins/README.md renamed to src/mixins/README.md

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cosnt newClass = MixinClass1(MixinClass2(BaseClass))
2222

2323
### LoggerMixin
2424

25-
LoggerMixin adds capabilities to a LoopBack Next Application by adding a `.logger()` function that allows used to bind a Logger class to `Context` automatically. The binding key will be `loggers.${Class.name}` where `Class.name` is the name of the Logger class being bound. The Mixin also overrides existing `.component()` function so that components are also capable of providing Logger's to be bound automatically.
25+
LoggerMixin adds capabilities to a LoopBack Next Application by adding a `.logger()` function that is used to bind a Logger class to `Context` automatically. The binding key will be `loggers.${Class.name}` where `Class.name` is the name of the Logger class being bound. Components are also able to provide their own Logger implementation which will be bound via `.component()` automatically when using this Mixin.
2626

2727
**Example**
2828
```
@@ -57,7 +57,7 @@ class ColorLogger {
5757

5858
Once a Logger has been bound, you can retrieve it by using [Dependency Inject](http://loopback.io/doc/en/lb4/Dependency-injection.html)
5959

60-
**More Examples for binding a Logger**
60+
#### More Examples for binding a Logger**
6161
```
6262
// Using the app's .logger() function.
6363
class LoggingApplication extends LoggerMixin(Application) {
@@ -80,20 +80,3 @@ const app = new LoggingApplication({
8080
components: [MyComponent] // Logger from MyComponent will be bound to loggers.ColorLogger
8181
});
8282
```
83-
84-
## Contributions
85-
86-
- [Guidelines](http://loopback.io/doc/en/contrib/index.html)
87-
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)
88-
89-
## Tests
90-
91-
Run `npm test` from the root folder.
92-
93-
## Contributors
94-
95-
See [all contributors](https://github.com/strongloop/loopback-next-extension-starter/graphs/contributors).
96-
97-
## License
98-
99-
MIT

src/logger-mixin/mixins/logger-mixin.ts renamed to src/mixins/logger.mixin.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ export function LoggerMixin<T extends Constructor<any>>(superClass: T) {
2929
this.logger(logger);
3030
}
3131
}
32-
33-
if (this.options.components) {
34-
// Super would have already mounted the component
35-
for (const component of this.options.components) {
36-
this.component(component);
37-
}
38-
}
3932
}
4033

4134
/**
@@ -61,18 +54,17 @@ export function LoggerMixin<T extends Constructor<any>>(superClass: T) {
6154

6255
/**
6356
* Add a component to this application. Also mounts
64-
* all the components repositories.
57+
* all the components Loggers.
6558
*
6659
* @param component The component to add.
6760
*
6861
* ```ts
6962
*
7063
* export class ProductComponent {
7164
* controllers = [ProductController];
72-
* loggers = [Logger];
65+
* loggers = [ProductLogger];
7366
* providers = {
74-
* [AUTHENTICATION_STRATEGY]: AuthStrategy,
75-
* [AUTHORIZATION_ROLE]: Role,
67+
* [PRODUCT_PROVIDER]: ProductProvider,
7668
* };
7769
* };
7870
*
@@ -89,7 +81,7 @@ export function LoggerMixin<T extends Constructor<any>>(superClass: T) {
8981
* loggers. This function is intended to be used internally
9082
* by component()
9183
*
92-
* @param component The component to mount repositories of
84+
* @param component The component to mount Logger's of
9385
*/
9486
mountComponentLogger(component: Constructor<any>) {
9587
const componentKey = `components.${component.name}`;

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
--compilers ts:ts-node/register
21
--recursive
32
--reporter dot
3+
dist/test

test/unit/logger-mixin.test.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ describe('LoggerMixin', () => {
3030
expectLoggerToBeBound(myApp);
3131
});
3232

33-
it('binds user defined component without Logger', () => {
34-
class EmptyTestComponent {}
35-
36-
const myApp = new AppWithLogger({
37-
components: [EmptyTestComponent],
38-
});
39-
40-
expectComponentToBeBound(myApp, EmptyTestComponent);
41-
});
42-
4333
it('binds user defined component with Logger in constructor', () => {
4434
const myApp = new AppWithLogger({
4535
loggers: [MyLogger],
@@ -66,10 +56,7 @@ describe('LoggerMixin', () => {
6656
});
6757

6858
const logger = myApp.getSync('loggers.MyLogger');
69-
expect(typeof logger.log).to.be.eql('function');
70-
expect(typeof logger.info).to.be.eql('function');
71-
expect(typeof logger.warn).to.be.eql('function');
72-
expect(typeof logger.error).to.be.eql('function');
59+
expect(logger).to.be.instanceOf(MyLogger);
7360
});
7461

7562
class AppWithLogger extends LoggerMixin(Application) {}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lib": ["es2017", "dom"],
1010
"module": "commonjs",
1111
"moduleResolution": "node",
12-
"target": "es6",
12+
"target": "es2017",
1313
"outDir": "dist",
1414
"sourceMap": true,
1515
"declaration": true

0 commit comments

Comments
 (0)