update log functions

This commit is contained in:
Dan Percic 2022-03-07 11:56:07 +02:00
parent f7f0bb86a6
commit 2bae4da2b9
3 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,4 @@
import { tap } from 'rxjs/operators';
import { ITrackable } from '../listing/models/trackable';
import { MonoTypeOperatorFunction } from 'rxjs';
import moment from 'moment';
import { FormGroup } from '@angular/forms';
@ -20,8 +18,8 @@ export function humanize(value: string, lowercase = true): string {
return words.map(capitalize).join(' ');
}
export function log<T>(message = ''): MonoTypeOperatorFunction<T> {
return tap<T>(res => console.log(`%c[${moment().format('HH:mm:ss.SSS')}] ${message}`, 'color: yellow;', res));
export function _log(value: unknown, message = '') {
console.log(`%c[${moment().format('HH:mm:ss.SSS')}] ${message}`, 'color: yellow;', value);
}
export function toNumber(str: string): number {

View File

@ -1,5 +1,6 @@
import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators';
import { distinctUntilChanged, map, shareReplay, tap } from 'rxjs/operators';
import { MonoTypeOperatorFunction, Observable, OperatorFunction, pipe, UnaryFunction } from 'rxjs';
import { _log } from './functions';
export function get<T>(predicate: (value: T, index: number) => boolean): OperatorFunction<readonly T[], T | undefined> {
return map(entities => entities.find(predicate));
@ -37,3 +38,7 @@ export function boolFactory<T = boolean>(obs: Observable<T>, project: (value: T)
);
return [result, inverse];
}
export function log<T>(message = ''): MonoTypeOperatorFunction<T> {
return tap<T>(res => _log(res, message));
}

View File

@ -1,11 +1,12 @@
import { Pipe, PipeTransform } from '@angular/core';
import { _log } from '@iqser/common-ui';
@Pipe({
name: 'log',
})
export class LogPipe implements PipeTransform {
transform<T>(value: T, message = ''): T {
console.log(message, value);
_log(value, message);
return value;
}
}