Skip to content

Commit

Permalink
✨ display time and elapsedTime on each log
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno committed Dec 2, 2022
1 parent a2cdb18 commit bc92661
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,42 @@ export default function () {

return class extends target {
watchState = this.effect(() => {
let lastTime: Date | undefined;

const logInitialState$ = this.state$.pipe(
take(1),
tap((state) => {
const time = new Date();

const obj = {
name,
state,
time,
};

console.log(obj);

lastTime = time;
})
);

const logDiff$ = this.state$.pipe(
bufferCount(2, 1),
tap(([prevState, state]) => {
const time = new Date();
const elaspedTime = time.getTime() - lastTime!.getTime();

const obj = {
name,
prevState,
state,
time,
elaspedTime,
};

console.log(obj);

lastTime = time;
})
);

Expand Down

0 comments on commit bc92661

Please sign in to comment.