question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding Force Unsubscribe upon new Subscription

See original GitHub issue

Feature Request

With pipable operator, RxJS strongly recommends to create new features via pipable function and publish it as user-land module. If this feature request is

Is your feature request related to a problem? Please describe. The problem this would solve is this not being able to subscribe to an observable and cancelling in-flight requests at the same time.

btnClick() {
   this._subscriptions.add(this.obs$.subscribe()); //This request will fire every time this button is clicked
}

Describe the solution you’d like

btnClickFeatureRequest() {
   this._subscription.addClean(this.obs$.subscribe()); 
    //follows "Remove" fn() but also calls .unsubscribe() before splicing it. 
    //Allowing this method to be called X times and only ever returning the last result.
}

Ex: (in Subscription.ts)


    addClean(subscription: Subscription) {
		const subscriptions = this._subscriptions;
		if (subscriptions) {
			const subscriptionIndex = subscriptions.indexOf(subscription);
			if (subscriptionIndex !== -1) {
				subscriptions[subscriptionIndex].unsubscribe();//THIS!!!
				subscriptions.splice(subscriptionIndex, 1);
			}
		}
	}
        this.add(subscription); //THIS!!!

Describe alternatives you’ve considered

DestinctUntil, TakeUntil -> Which both require setting up multiple subscribers and more variables making a component with 20+ observables that are being subscribed to very unclean.

(If this is new operator request) describe reason it should be core operator Cleaner code for the end coder, having to add multiple subscribers to cancel within the call is just unclean.

Additional context Will add if request is made.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kwonojcommented, Feb 15, 2019
  1. It’d work I guess, if not only few modification required.

  2. I don’t think we’ll have in core, cause we intentionally deprecated from v5.

Cloaing for now as I believe answe itself has provided.

1reaction
kwonojcommented, Feb 15, 2019

This sounds like serialsubscription (https://github.com/paulcbetts/rxjs-serial-subscription) which we have userland implementation as well. Also it’s quite easy to create your own subscription and let it parent subscription to achieve desired behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to REMOVE YouTube Subscriptions ⚡️⚡️EVEN ...
Learn how to QUICKLY unsubscribe from all the YouTube channels you DONT watch.This video is actually an update to a tutorial I created...
Read more >
Subscribe/Unsubscribe Report - Support
In the drop down, click Subscribe; Click Unsubscribe. Watch the video below to learn how to schedule and unschedule report (Lightning):.
Read more >
6 Ways to Unsubscribe from Observables in Angular
1. Use the unsubscribe method ... A Subscription essentially just has an unsubscribe() function to release resources or cancel Observable ...
Read more >
Best Practices for Managing RxJS Subscriptions - This Dot Labs
One method we can use, is to unsubscribe manually from active subscriptions when we no longer require them. RxJS provides us with a...
Read more >
Manage App Store purchases, subscriptions, settings, and ...
Change or cancel your App Store subscriptions · Tap the My Account button or your picture at the top right, then tap Subscriptions....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found