-
Notifications
You must be signed in to change notification settings - Fork 2
Events with timestamp
Tyler Long edited this page Oct 11, 2018
·
1 revision
Want events with timestamp? RxJS provides us with such an operator.
import { timestamp } from 'rxjs/operators'
const rectangle = SubX.create({ position: { } })
rectangle.$.pipe(timestamp()).subscribe(console.log)
rectangle.position.x = 0
Timestamp {
value:
{ type: 'SET',
val: 0,
oldVal: undefined,
path: [ 'position', 'x' ] },
timestamp: 1537247605018 }
Want a flat event with timestamp instead? While, you can map it.
import { timestamp, map } from 'rxjs/operators'
const rectangle = SubX.create({ position: { } })
rectangle.$.pipe(
timestamp(),
map(event => ({ ...event.value, timestamp: event.timestamp }))
).subscribe(console.log)
rectangle.position.x = 0
{ type: 'SET',
val: 0,
oldVal: undefined,
path: [ 'position', 'x' ],
timestamp: 1537248003912 }