Skip to content

Commit

Permalink
Merge pull request #89 from jmezach/server-side-prerender
Browse files Browse the repository at this point in the history
Server side prerender
  • Loading branch information
urish authored Oct 4, 2016
2 parents 88ec4df + 034d7b9 commit 64795ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/CalendarPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ export class CalendarPipe implements PipeTransform, OnDestroy {
// initialize the timer
if (!CalendarPipe._midnight) {
CalendarPipe._midnight = new EventEmitter<Date>();
let timeToUpdate = CalendarPipe._getMillisecondsUntilUpdate();
CalendarPipe._timer = window.setTimeout(() => {
// emit the current date
CalendarPipe._midnight.emit(new Date());

// refresh the timer
CalendarPipe._removeTimer();
CalendarPipe._initTimer();
}, timeToUpdate);
if (typeof window !== 'undefined') {
let timeToUpdate = CalendarPipe._getMillisecondsUntilUpdate();
CalendarPipe._timer = window.setTimeout(() => {
// emit the current date
CalendarPipe._midnight.emit(new Date());

// refresh the timer
CalendarPipe._removeTimer();
CalendarPipe._initTimer();
}, timeToUpdate);
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/TimeAgoPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export class TimeAgoPipe implements PipeTransform, OnDestroy {
const momentInstance = momentConstructor(value);
this._removeTimer();
const timeToUpdate = this._getSecondsUntilUpdate(momentInstance) * 1000;
this._currentTimer = this._ngZone.runOutsideAngular(() =>
window.setTimeout(() => this._cdRef.markForCheck(), timeToUpdate));
this._currentTimer = this._ngZone.runOutsideAngular(() => {
if (typeof window !== 'undefined') {
return window.setTimeout(() => this._cdRef.markForCheck(), timeToUpdate);
}
});
return momentConstructor(value).from(momentConstructor(), omitSuffix);
}

Expand Down

0 comments on commit 64795ca

Please sign in to comment.