how to clear “distinct” RxJS operator in Angular 2?

Viewed 579

Is there a way to clear the distinct() cache?

as you can see, sometimes i set this.messages=[], at that point, i'd like to clear the cache. Instead i've done a hack, where i increase distinctCount.

ngOnInit() {
    let saved = {}
    let distinctCount = 1000000000000
    let messageStream = this.route.params
            .map(params=>params['id'])
            .switchMap((id)=> {
                this.messages = []
                saved[this.id] = this.newMessage
                this.id = id
                distinctCount+=1000000000000
                this.newMessage = saved[id] || ''
                return Observable.interval(3500).startWith(0).switchMap(()=> {
                    let count = 5
                    if (this.messages.length == 0) {
                        count = 10
                    }
                    return this.conversationsApi.apiConversationsByConversationIdGetMessagesGet(this.id, this.authService.getAuth(), undefined, count, undefined, undefined, undefined)
                })
            })
            .concatMap((messages:Array<MessageModel>)=>{
                return Observable.from(messages.slice().reverse())
            })
            .distinct(message=>message.id+distinctCount)
}
1 Answers
Related