-
Notifications
You must be signed in to change notification settings - Fork 2
Filter events
Tyler Long edited this page Oct 11, 2018
·
1 revision
Let's say you only interested in 'SET' events, you can filter the event stream before subscribe
:
import { filter } from 'rxjs/operators'
const person = SubX.create()
person.$.pipe(
filter(event => event.type === 'SET')
).subscribe(console.log)
Example above isn't useful in real project because there is already person.set$
available. It just shows you how to filter events.
Sometimes you might only want the changes to a SubX object's direct properties (no recursive events):
const person = SubX.create()
const directChangesToPerson$ = person.$.pipe(filter(event => event.path.length === 1))
It's a convenstion to end an event stream with $
, that's why we name the constant directChangesToPerson$
instead of directChangesToPerson
.