I am currently working on a project that involves utilizing the pipe() operator in an observable to filter, sort, and publish items. While it is functioning as intended, I am curious if there is a more concise way to implement these operators.
Current Scenario: The existing setup involves calling pipe on an observable that contains an array of 'Items'. Within the pipe, the items are filtered, sorted, and then published to a behavior subject.
public items$: BehaviorSubject
public testObservable = () =>
of({
Test: '123',
Properties: 'props',
Items: [
{ key: 1, val: 'test1' },
{ key: 2, val: 'test2' },
{ key: 3, val: 'test3' }
]
});
testMethod() {
this.testObservable()
.pipe(
pluck('Items'),
map(items => items.filter(item => item.key != 2)),
map(items => items.sort((a, b) => (a.key > b.key ? 1 : -1))),
tap(items => { this.items$.next(items) })
);