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

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
virkt25 committed Oct 3, 2017
1 parent f27e494 commit 1149eaa
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 82 deletions.
10 changes: 3 additions & 7 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"tasks": [
{
"taskName": "Watch and compile TypeScript",
"command": "tsc",
"args": ["--watch"],
"command": "npm",
"args": ["--silent", "run", "build:watch"],
"type": "process",
"isBackground": true,
"problemMatcher": "$tsc-watch",
Expand All @@ -24,11 +24,7 @@
{
"taskName": "Test and lint",
"command": "npm",
"args": [
"--silent",
"run",
"vscode-test"
],
"args": ["--silent", "run", "test:dev"],
"type": "process",
"group": {
"kind": "test",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"build": "npm run build:lib && npm run build:lib6",
"build:lib": "tsc --target es2017 --outDir dist",
"build:lib6": "tsc --target es2015 --outDir dist6",
"build:watch": "tsc --watch",
"clean": "rm -rf dist dist6",
"lint": "tslint -c tslint.full.json --project tsconfig.json --type-check",
"lint:fix": "npm run lint -- --fix",
"prepublish": "npm run build",
"pretest": "npm run clean && npm run build",
"test": "mocha",
"posttest": "npm run lint",
"vscode-test": "mocha && npm run lint"
"test:dev": "mocha && npm run lint"
},
"repository": {
"type": "git",
Expand All @@ -41,7 +42,6 @@
"@loopback/testlab": "^4.0.0-alpha.7",
"@types/mocha": "^2.2.43",
"mocha": "^3.5.3",
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"typescript": "^2.5.2"
}
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Controllers

This directory contains source files for the controllers exported by this extension.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

export * from './logger-mixin';
export * from './mixins/logger.mixin';
6 changes: 0 additions & 6 deletions src/logger-mixin/index.ts

This file was deleted.

21 changes: 2 additions & 19 deletions src/logger-mixin/mixins/README.md → src/mixins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cosnt newClass = MixinClass1(MixinClass2(BaseClass))

### LoggerMixin

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.
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.

**Example**
```
Expand Down Expand Up @@ -57,7 +57,7 @@ class ColorLogger {

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

**More Examples for binding a Logger**
#### More Examples for binding a Logger**
```
// Using the app's .logger() function.
class LoggingApplication extends LoggerMixin(Application) {
Expand All @@ -80,20 +80,3 @@ const app = new LoggingApplication({
components: [MyComponent] // Logger from MyComponent will be bound to loggers.ColorLogger
});
```

## Contributions

- [Guidelines](http://loopback.io/doc/en/contrib/index.html)
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)

## Tests

Run `npm test` from the root folder.

## Contributors

See [all contributors](https://github.com/strongloop/loopback-next-extension-starter/graphs/contributors).

## License

MIT
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ export function LoggerMixin<T extends Constructor<any>>(superClass: T) {
this.logger(logger);
}
}

if (this.options.components) {
// Super would have already mounted the component
for (const component of this.options.components) {
this.component(component);
}
}
}

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

/**
* Add a component to this application. Also mounts
* all the components repositories.
* all the components Loggers.
*
* @param component The component to add.
*
* ```ts
*
* export class ProductComponent {
* controllers = [ProductController];
* loggers = [Logger];
* loggers = [ProductLogger];
* providers = {
* [AUTHENTICATION_STRATEGY]: AuthStrategy,
* [AUTHORIZATION_ROLE]: Role,
* [PRODUCT_PROVIDER]: ProductProvider,
* };
* };
*
Expand All @@ -89,7 +81,7 @@ export function LoggerMixin<T extends Constructor<any>>(superClass: T) {
* loggers. This function is intended to be used internally
* by component()
*
* @param component The component to mount repositories of
* @param component The component to mount Logger's of
*/
mountComponentLogger(component: Constructor<any>) {
const componentKey = `components.${component.name}`;
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--compilers ts:ts-node/register
--recursive
--reporter dot
dist/test
15 changes: 1 addition & 14 deletions test/unit/logger-mixin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ describe('LoggerMixin', () => {
expectLoggerToBeBound(myApp);
});

it('binds user defined component without Logger', () => {
class EmptyTestComponent {}

const myApp = new AppWithLogger({
components: [EmptyTestComponent],
});

expectComponentToBeBound(myApp, EmptyTestComponent);
});

it('binds user defined component with Logger in constructor', () => {
const myApp = new AppWithLogger({
loggers: [MyLogger],
Expand All @@ -66,10 +56,7 @@ describe('LoggerMixin', () => {
});

const logger = myApp.getSync('loggers.MyLogger');
expect(typeof logger.log).to.be.eql('function');
expect(typeof logger.info).to.be.eql('function');
expect(typeof logger.warn).to.be.eql('function');
expect(typeof logger.error).to.be.eql('function');
expect(logger).to.be.instanceOf(MyLogger);
});

class AppWithLogger extends LoggerMixin(Application) {}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lib": ["es2017", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"target": "es6",
"target": "es2017",
"outDir": "dist",
"sourceMap": true,
"declaration": true
Expand Down
34 changes: 15 additions & 19 deletions tslint.full.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"$schema": "http://json.schemastore.org/tslint",
"extends": [
"./tslint.json"
],
// This configuration files enabled rules which require type checking
// and therefore cannot be run by Visual Studio Code TSLint extension
// See https://github.com/Microsoft/vscode-tslint/issues/70
"rules": {
// These rules find errors related to TypeScript features.


// These rules catch common errors in JS programming or otherwise
// confusing constructs that are prone to producing bugs.

"await-promise": true,
"no-floating-promises": true,
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
}
"$schema": "http://json.schemastore.org/tslint",
"extends": ["./tslint.json"],
// This configuration files enabled rules which require type checking
// and therefore cannot be run by Visual Studio Code TSLint extension
// See https://github.com/Microsoft/vscode-tslint/issues/70
"rules": {
// These rules find errors related to TypeScript features.

// These rules catch common errors in JS programming or otherwise
// confusing constructs that are prone to producing bugs.

"await-promise": true,
"no-floating-promises": true,
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
}
}

0 comments on commit 1149eaa

Please sign in to comment.