skip to content

pluck

 

Map each emitted value to it's property, defined by path:

Also see the map operator and try comparing pluck to map

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const { rxObserver } = require('api/v0.3');
const { of } = require('rxjs');
const { pluck, map } = require('rxjs/operators');

const source$ = of({ a: 1 }, { a: 2 }, { a: 3 });

source$
  .pipe(
    map(x => JSON.stringify(x))
  )
  .subscribe(rxObserver('of( { a: 1 } , ... )'));

source$
  .pipe(
    pluck('a')
  )
  .subscribe(rxObserver(`pluck('a')`));

0msof( { a: 1 } , ... )startcomplete{"a":1}{"a":1} {"a":2}{"a":2} {"a":3}{"a":3} pluck('a')startcomplete11 22 33

NOTE: I've created a package to simplify subproperty access
It turns Observables of Objects into Objects of Observables
Check it out: rxjs/proxy {👓}