Commit f413dfa9 authored by Merzough Münker's avatar Merzough Münker
Browse files

fix: split live and static pipe

parent 6e6504b2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
// region 
export * from './lib/timeago-live.pipe';
export * from './lib/timeago.directive';
export * from './lib/timeago.formatter';
export * from './lib/timeago.pipe';
+26 −0
Original line number Diff line number Diff line
import {
  Pipe,
  PipeTransform,
} from '@angular/core';
import {
  interval,
  map,
  Observable,
  startWith,
} from 'rxjs';
import { TimeagoFormatter } from './timeago.formatter';

@Pipe({
  name: 'timeagoLive',
  standalone: true,
})
export class TimeagoLivePipe implements PipeTransform {

  transform(input: string | number | Date): Observable<string> {
    return interval(1000).pipe(
      map(() => TimeagoFormatter(input)),
      startWith(TimeagoFormatter(input)),
    );
  }

}
+2 −18
Original line number Diff line number Diff line
@@ -2,11 +2,6 @@ import {
  Pipe,
  PipeTransform,
} from '@angular/core';
import {
  interval,
  map,
  startWith,
} from 'rxjs';
import { TimeagoFormatter } from './timeago.formatter';

@Pipe({
@@ -15,19 +10,8 @@ import { TimeagoFormatter } from './timeago.formatter';
})
export class TimeagoPipe implements PipeTransform {

  transform(input: string | number | Date, live = false) {
    const date = new Date(input);

    const timeago = TimeagoFormatter(date);

    if (live) {
      return interval(1000).pipe(
        map(() => TimeagoFormatter(date)),
        startWith(timeago),
      );
    }

    return timeago;
  transform(input: string | number | Date): string {
    return TimeagoFormatter(input);
  }

}