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

Commit 966f76d

Browse files
committed
Apply feedback
1 parent e8019fc commit 966f76d

File tree

9 files changed

+27
-83
lines changed

9 files changed

+27
-83
lines changed

.vscode/tasks.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
{
77
"taskName": "Watch and compile TypeScript",
88
"command": "npm",
9-
"args": [
10-
"--silent",
11-
"run",
12-
"build:watch"
13-
],
9+
"args": ["--silent", "run", "build:watch"],
1410
"type": "process",
1511
"isBackground": true,
1612
"problemMatcher": "$tsc-watch",
@@ -28,11 +24,7 @@
2824
{
2925
"taskName": "Test and lint",
3026
"command": "npm",
31-
"args": [
32-
"--silent",
33-
"run",
34-
"test:dev"
35-
],
27+
"args": ["--silent", "run", "test:dev"],
3628
"type": "process",
3729
"group": {
3830
"kind": "test",

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

tslint.full.json

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
{
2-
"$schema": "http://json.schemastore.org/tslint",
3-
"extends": [
4-
"./tslint.json"
5-
],
6-
// This configuration files enabled rules which require type checking
7-
// and therefore cannot be run by Visual Studio Code TSLint extension
8-
// See https://github.com/Microsoft/vscode-tslint/issues/70
9-
"rules": {
10-
// These rules find errors related to TypeScript features.
11-
12-
13-
// These rules catch common errors in JS programming or otherwise
14-
// confusing constructs that are prone to producing bugs.
15-
16-
"await-promise": true,
17-
"no-floating-promises": true,
18-
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
19-
}
2+
"$schema": "http://json.schemastore.org/tslint",
3+
"extends": ["./tslint.json"],
4+
// This configuration files enabled rules which require type checking
5+
// and therefore cannot be run by Visual Studio Code TSLint extension
6+
// See https://github.com/Microsoft/vscode-tslint/issues/70
7+
"rules": {
8+
// These rules find errors related to TypeScript features.
9+
10+
// These rules catch common errors in JS programming or otherwise
11+
// confusing constructs that are prone to producing bugs.
12+
13+
"await-promise": true,
14+
"no-floating-promises": true,
15+
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
2016
}
21-
17+
}

0 commit comments

Comments
 (0)