Skip to content

Commit

Permalink
feat(clock): rename register to tick
Browse files Browse the repository at this point in the history
  • Loading branch information
ihym committed May 17, 2018
1 parent e2f64ac commit d5ef34f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ export class AppModule { }

#### Write your own clock

The only required method to build your own clock, is `register` that must return an `Observable<any>`. Whenever this observable emits, the timestamp will be updated, using your formatter (and intl, if available).
The only required method to build your own clock, is `tick` that must return an `Observable<any>`. Whenever this observable emits, the timestamp will be updated, using your formatter (and intl, if available).

```ts
import { TimeagoClock } from 'ngx-timeago';
import { Observable, interval } from 'rxjs';

// ticks every 2s
export class MyClock extends TimeagoClock {
register(then: number): Observable<number> {
tick(then: number): Observable<number> {
return interval(2000);
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

export class MyClock extends TimeagoClock {
register(then: number): Observable<number> {
tick(then: number): Observable<number> {
return of(0)
.pipe(
expand(() => {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/timeago.clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { expand, delay, skip } from 'rxjs/operators';
import { MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } from './util';

export abstract class TimeagoClock {
abstract register(then: number): Observable<any>;
abstract tick(then: number): Observable<any>;
}

@Injectable()
export class TimeagoDefaultClock extends TimeagoClock {
register(then: number): Observable<number> {
tick(then: number): Observable<number> {
return of(0)
.pipe(
expand(() => {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/timeago.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TimeagoDirective implements OnChanges, OnDestroy {
if (this.clockSubscription) {
this.clockSubscription.unsubscribe();
}
this.clockSubscription = this.clock.register(date)
this.clockSubscription = this.clock.tick(date)
.pipe(filter(() => this.live, this))
.subscribe(() => this.stateChanges.next());
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/clock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('TimeagoClock', () => {

it('should complete instantly for differences greater than a day', (() => {
testScheduler.run(({ expectObservable }) => {
const source = clock.register(Date.now() - 60 * 60 * 24 * 1000).pipe(map(x => x.toString()));
const source = clock.tick(Date.now() - 60 * 60 * 24 * 1000).pipe(map(x => x.toString()));
const expected = '|';
expectObservable(source).toBe(expected);
});
Expand Down

0 comments on commit d5ef34f

Please sign in to comment.