3
有沒有辦法清除distinct()緩存?如何在Angular 2中清除「獨特」的RxJS操作符?
正如你所看到的,有時我設置this.messages = [],在這一點上,我想清除緩存。相反,我做了一個黑客,我增加了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)
}