@obsidize/rx-map
Version:
ES6 Map with rxjs extensions for change detection
28 lines (27 loc) • 739 B
JavaScript
import { castArray } from './utility';
/**
* Simple subscription aggregator.
* This is needed to prevent unwarrented rxjs exceptions when attempting to mass-unsubscribe.
*/
export class Subsink {
constructor() {
this.mSubscriptions = new Set();
}
static unsubscribeSafe(target) {
try {
target.unsubscribe();
}
catch (_a) { }
}
add(...targets) {
return this.addMany(targets);
}
unsubscribe() {
this.mSubscriptions.forEach(Subsink.unsubscribeSafe);
this.mSubscriptions.clear();
}
addMany(targets) {
castArray(targets).forEach(target => this.mSubscriptions.add(target));
return this;
}
}