Skip to content

Commit

Permalink
simplify close subscription function
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 1, 2021
1 parent 315af18 commit 7af20f8
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/core-js/modules/esnext.observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var subscriptionClosed = function (subscriptionState) {
return subscriptionState.observer === undefined;
};

var close = function (subscription, subscriptionState) {
var close = function (subscriptionState) {
var subscription = subscriptionState.facade;
if (!DESCRIPTORS) {
subscription.closed = true;
var subscriptionObserver = subscriptionState.subscriptionObserver;
Expand Down Expand Up @@ -79,7 +80,7 @@ Subscription.prototype = redefineAll({}, {
unsubscribe: function unsubscribe() {
var subscriptionState = getInternalState(this);
if (!subscriptionClosed(subscriptionState)) {
close(this, subscriptionState);
close(subscriptionState);
cleanupSubscription(subscriptionState);
}
}
Expand Down Expand Up @@ -111,11 +112,10 @@ SubscriptionObserver.prototype = redefineAll({}, {
}
},
error: function error(value) {
var subscription = getInternalState(this).subscription;
var subscriptionState = getInternalState(subscription);
var subscriptionState = getInternalState(getInternalState(this).subscription);
if (!subscriptionClosed(subscriptionState)) {
var observer = subscriptionState.observer;
close(subscription, subscriptionState);
close(subscriptionState);
try {
var errorMethod = getMethod(observer.error);
if (errorMethod) errorMethod.call(observer, value);
Expand All @@ -126,11 +126,10 @@ SubscriptionObserver.prototype = redefineAll({}, {
}
},
complete: function complete() {
var subscription = getInternalState(this).subscription;
var subscriptionState = getInternalState(subscription);
var subscriptionState = getInternalState(getInternalState(this).subscription);
if (!subscriptionClosed(subscriptionState)) {
var observer = subscriptionState.observer;
close(subscription, subscriptionState);
close(subscriptionState);
try {
var completeMethod = getMethod(observer.complete);
if (completeMethod) completeMethod.call(observer);
Expand Down

0 comments on commit 7af20f8

Please sign in to comment.