File size: 5,128 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
import { isFunction } from './util/isFunction';
import { isSubscription, Subscription } from './Subscription';
import { config } from './config';
import { reportUnhandledError } from './util/reportUnhandledError';
import { noop } from './util/noop';
import { nextNotification, errorNotification, COMPLETE_NOTIFICATION } from './NotificationFactories';
import { timeoutProvider } from './scheduler/timeoutProvider';
import { captureError } from './util/errorContext';
export class Subscriber extends Subscription {
constructor(destination) {
super();
this.isStopped = false;
if (destination) {
this.destination = destination;
if (isSubscription(destination)) {
destination.add(this);
}
}
else {
this.destination = EMPTY_OBSERVER;
}
}
static create(next, error, complete) {
return new SafeSubscriber(next, error, complete);
}
next(value) {
if (this.isStopped) {
handleStoppedNotification(nextNotification(value), this);
}
else {
this._next(value);
}
}
error(err) {
if (this.isStopped) {
handleStoppedNotification(errorNotification(err), this);
}
else {
this.isStopped = true;
this._error(err);
}
}
complete() {
if (this.isStopped) {
handleStoppedNotification(COMPLETE_NOTIFICATION, this);
}
else {
this.isStopped = true;
this._complete();
}
}
unsubscribe() {
if (!this.closed) {
this.isStopped = true;
super.unsubscribe();
this.destination = null;
}
}
_next(value) {
this.destination.next(value);
}
_error(err) {
try {
this.destination.error(err);
}
finally {
this.unsubscribe();
}
}
_complete() {
try {
this.destination.complete();
}
finally {
this.unsubscribe();
}
}
}
const _bind = Function.prototype.bind;
function bind(fn, thisArg) {
return _bind.call(fn, thisArg);
}
class ConsumerObserver {
constructor(partialObserver) {
this.partialObserver = partialObserver;
}
next(value) {
const { partialObserver } = this;
if (partialObserver.next) {
try {
partialObserver.next(value);
}
catch (error) {
handleUnhandledError(error);
}
}
}
error(err) {
const { partialObserver } = this;
if (partialObserver.error) {
try {
partialObserver.error(err);
}
catch (error) {
handleUnhandledError(error);
}
}
else {
handleUnhandledError(err);
}
}
complete() {
const { partialObserver } = this;
if (partialObserver.complete) {
try {
partialObserver.complete();
}
catch (error) {
handleUnhandledError(error);
}
}
}
}
export class SafeSubscriber extends Subscriber {
constructor(observerOrNext, error, complete) {
super();
let partialObserver;
if (isFunction(observerOrNext) || !observerOrNext) {
partialObserver = {
next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
error: error !== null && error !== void 0 ? error : undefined,
complete: complete !== null && complete !== void 0 ? complete : undefined,
};
}
else {
let context;
if (this && config.useDeprecatedNextContext) {
context = Object.create(observerOrNext);
context.unsubscribe = () => this.unsubscribe();
partialObserver = {
next: observerOrNext.next && bind(observerOrNext.next, context),
error: observerOrNext.error && bind(observerOrNext.error, context),
complete: observerOrNext.complete && bind(observerOrNext.complete, context),
};
}
else {
partialObserver = observerOrNext;
}
}
this.destination = new ConsumerObserver(partialObserver);
}
}
function handleUnhandledError(error) {
if (config.useDeprecatedSynchronousErrorHandling) {
captureError(error);
}
else {
reportUnhandledError(error);
}
}
function defaultErrorHandler(err) {
throw err;
}
function handleStoppedNotification(notification, subscriber) {
const { onStoppedNotification } = config;
onStoppedNotification && timeoutProvider.setTimeout(() => onStoppedNotification(notification, subscriber));
}
export const EMPTY_OBSERVER = {
closed: true,
next: noop,
error: defaultErrorHandler,
complete: noop,
};
//# sourceMappingURL=Subscriber.js.map |