This repository was archived by the owner on Jun 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
This repository was archived by the owner on Jun 18, 2020. It is now read-only.
Decorator API #6
Copy link
Copy link
Closed
Description
I. Logger decorator
Before
export class AppComponent implements OnInit {
constructor(private logger: LoggerService) {}
public ngOnInit(): void {
this.logger.debug('hello world');
}
}
After
export class AppComponent implements OnInit {
@Logger() private logger: LoggerService;
public ngOnInit(): void {
this.logger.debug('hello world');
}
}
II. Use only methods
Before
export class AppComponent implements OnInit {
constructor(private logger: LoggerService) {}
public ngOnInit(): void {
this.logger.trace('hello world');
this.logger.debug('hello world');
this.logger.log('hello world');
this.logger.warn('hello world');
this.logger.error('hello world');
}
}
After
export class AppComponent implements OnInit {
@Trace() private trace: LogFn;
@Debug() private debug: LogFn;
@Log() private log: LogFn;
@Warn() private warn: LogFn;
@Error() private error: LogFn;
public ngOnInit(): void {
this.trace('hello world');
this.debug('hello world');
this.log('hello world');
this.warn('hello world');
this.error('hello world');
}
}
III. Group, GroupCollapsed
Before
export class AppComponent implements OnInit {
constructor(private readonly logger: LoggerService) {}
public ngOnInit(): void {
this.logger.group(
'Show trace in opened group',
({ trace }: LoggerService): void => {
for (let i: number = 0; i < 20; i++) {
trace( 'trace is worked', i);
}
}
);
}
}
After
export class AppComponent implements OnInit {
@Trace() private trace: LogFn;
@Group('Show trace in opened group') public ngOnInit(): void {
for (let i: number = 0; i < 20; i++) {
this.trace('trace is worked', i);
}
}
}
Metadata
Metadata
Assignees
Labels
No labels