wardbell / subsink

RxJS subscription sink for unsubscribing gracefully in a component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: How can I remove a subscription from array?

csaszika opened this issue · comments

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()

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();
    }
}

@CN-Tower thanks for the answer :)
sorry for late respond.