Created
February 21, 2018 22:59
-
-
Save nergal/591a54437161623584568387ca208be6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeComponent { | |
public interactionsPublic$: Observable<Interaction[]>; | |
private interactions$: Observable<Interaction[]>; | |
public filterField: 'isAccepted' | 'isPending' | 'isRejected'; | |
protected defaultFilter = 'isAccepted'; | |
public filterSubject: BehaviorSubject<string[]> = new BehaviorSubject([]); | |
constructor( | |
public store: Store<ProductsState>, | |
public modalService: NgbModal | |
) { | |
this.interactions$ = this.store.select('interactions'); | |
this.interactionsPublic$ = combineLatest( | |
this.interactions$, | |
this.filterSubject | |
).pipe( | |
map(([items, ids]: [Interaction[], string[]]) => | |
filter((item: Interaction) => includes(item.interactionId)(ids))(items) | |
) | |
); | |
} | |
onFilterChange($event) { | |
this.filterField = $event; | |
this.interactions$.pipe( | |
first(), | |
map(filter(this.filterField)), | |
map(flatMap('interactionId')), | |
).subscribe((items: string[]) => this.filterSubject.next(items)); | |
} | |
ngOnInit() { | |
const subscription = this.interactions$.pipe( | |
filter$(x => !!x.length) | |
).subscribe(() => { | |
this.onFilterChange(this.defaultFilter); | |
subscription.unsubscribe(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment