Question: How can I remove a subscription from array?
csaszika opened this issue · comments
Balint Csaszar (Chassy) commented
So this is the following syntax:
this.subs.sink = newSub.subscibe()
this.subs.sink = newSub2.subscibe()
How can I remove the first one?
Actual idea:
this.subs.sink = newSub.subscibe()
this.subs.sink = newSub2.subscibe()
this.subs.unsubscibe()
this.subs.sink = newSub2.subscibe()
CN-Tower commented
Try subsink2, https://www.npmjs.com/package/subsink2:
// npm insall subsink2
import { SubSink } from 'subsink2';
@Component(...)
export SomeComponet {
subs: SubSink = new SubSink();
constructor() {}
ngOnInit() {
// Origin subscriptions
this.subs.sink = Subscription;
this.subs.add(Subscription);
// Subs with ID
this.subs.id('sub1').sink = Subscription;
this.subs.id('sub2').sink = Subscription;
// Some subs that you don't wan't be unsubscribed on destory.
this.subs.id_('sub3').sink = Subscription;
...
// Unsubscribe subs by ID
this.subs.id('sub1').unsubscribe();
}
ngOnDestory() {
// Unsubscribe all the subs except `.id_` subs.
this.subs.unsubscribe();
}
}
Balint Csaszar (Chassy) commented
@CN-Tower thanks for the answer :)
sorry for late respond.