@ukon1990/subscription-manager
Advanced tools
Comparing version 1.1.0-beta.0 to 1.1.0-beta.1
@@ -1,4 +0,4 @@ | ||
// Set options as a parameter, environment variable, or rc file. | ||
// eslint-disable-next-line no-global-assign | ||
require = require("esm")(module/* , options */) | ||
module.exports = require("./main.js") | ||
/* istanbul ignore file */ | ||
import { SubscriptionManager } from './subscription-manager'; | ||
export { SubscriptionManager }; | ||
//# sourceMappingURL=index.js.map |
import { Subscribable, Subscription } from 'rxjs'; | ||
declare class MappedSubscription { | ||
index: number; | ||
subscription: Subscription; | ||
} | ||
export declare class SubscriptionManager { | ||
@@ -6,4 +10,19 @@ private list; | ||
getList(): Subscription[]; | ||
getMap(): Map<string, Subscription>; | ||
getMap(): Map<string, MappedSubscription>; | ||
/** | ||
* Adds the subscription to an array of subscriptions, that are unsubscribed upon | ||
* the first event. This is a wrapper function over the add function, replacing the need for | ||
* the option terminateUponEvent. | ||
* There are two optional parameters in the options param. | ||
* | ||
* @param emitter | ||
* @param fun | ||
* @param options { | ||
* @param label Adds the subscription to the map variable, so that you can unsubscribe at that spesific event manually | ||
* } | ||
*/ | ||
addSingleEvent(emitter: Subscribable<any>, fun: Function, options?: { | ||
id?: string; | ||
}): Subscription; | ||
/** | ||
* Adds the subscription to an array of subscriptions. | ||
@@ -25,2 +44,4 @@ * There are two optional parameters in the options param. | ||
unsubscribeById(id: string): void; | ||
getById(id: string): Subscription; | ||
} | ||
export {}; |
@@ -1,4 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class SubscriptionManager { | ||
class MappedSubscription { | ||
} | ||
export class SubscriptionManager { | ||
constructor() { | ||
@@ -15,2 +15,17 @@ this.list = []; | ||
/** | ||
* Adds the subscription to an array of subscriptions, that are unsubscribed upon | ||
* the first event. This is a wrapper function over the add function, replacing the need for | ||
* the option terminateUponEvent. | ||
* There are two optional parameters in the options param. | ||
* | ||
* @param emitter | ||
* @param fun | ||
* @param options { | ||
* @param label Adds the subscription to the map variable, so that you can unsubscribe at that spesific event manually | ||
* } | ||
*/ | ||
addSingleEvent(emitter, fun, options) { | ||
return this.add(emitter, fun, Object.assign(Object.assign({}, options), { terminateUponEvent: true })); | ||
} | ||
/** | ||
* Adds the subscription to an array of subscriptions. | ||
@@ -27,2 +42,3 @@ * There are two optional parameters in the options param. | ||
add(emitter, fun, options) { | ||
const newIndex = this.list.length; | ||
const subscription = emitter | ||
@@ -33,2 +49,8 @@ .subscribe((data) => { | ||
subscription.unsubscribe(); | ||
if (options.id) { | ||
this.unsubscribeById(options.id); | ||
} | ||
else { | ||
this.list.splice(newIndex, 1); | ||
} | ||
} | ||
@@ -40,3 +62,6 @@ } | ||
if (options && options.id) { | ||
this.map.set(options.id, subscription); | ||
this.map.set(options.id, { | ||
subscription, | ||
index: this.list.length - 1, | ||
}); | ||
} | ||
@@ -52,2 +77,3 @@ return subscription; | ||
this.list.length = 0; | ||
this.map = new Map(); | ||
} | ||
@@ -57,7 +83,15 @@ unsubscribeById(id) { | ||
if (subscription) { | ||
subscription.unsubscribe(); | ||
subscription.subscription.unsubscribe(); | ||
this.map.delete(id); | ||
this.list.splice(subscription.index, 1); | ||
} | ||
} | ||
getById(id) { | ||
const sub = this.getMap().get(id); | ||
if (sub) { | ||
return sub.subscription; | ||
} | ||
return undefined; | ||
} | ||
} | ||
exports.SubscriptionManager = SubscriptionManager; | ||
//# sourceMappingURL=subscription-manager.js.map |
{ | ||
"name": "@ukon1990/subscription-manager", | ||
"version": "1.1.0-beta.0", | ||
"version": "1.1.0-beta.1", | ||
"description": "This does hopefully make subscription management less tedious, and helps clean up your code with less variables.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26775
20
520
0