Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 4457c51

Browse files
Fixing Issue #658
1 parent a103d0c commit 4457c51

27 files changed

+425
-508
lines changed

dist/rx.all.compat.js

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -971,62 +971,53 @@
971971
if (disposable.isDisposed) { throw new ObjectDisposedError(); }
972972
};
973973

974-
var BooleanDisposable = (function () {
975-
var trueInstance = (function () {
976-
var d = new BooleanDisposable();
977-
d.isDisposed = true;
978-
return d;
979-
}());
980-
981-
function BooleanDisposable (isSingle) {
982-
this.isDisposed = false;
974+
// Single assignment
975+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
976+
this.isDisposed = false;
977+
this.current = null;
978+
};
979+
SingleAssignmentDisposable.prototype.getDisposable = function () {
980+
return this.current;
981+
};
982+
SingleAssignmentDisposable.prototype.setDisposable = function (value) {
983+
if (this.current) { throw new Error('Disposable has already been assigned'); }
984+
var shouldDispose = this.isDisposed;
985+
!shouldDispose && (this.current = value);
986+
shouldDispose && value && value.dispose();
987+
};
988+
SingleAssignmentDisposable.prototype.dispose = function () {
989+
if (!this.isDisposed) {
990+
this.isDisposed = true;
991+
var old = this.current;
983992
this.current = null;
984-
this.isSingle = isSingle;
985993
}
986-
987-
var booleanDisposablePrototype = BooleanDisposable.prototype;
988-
989-
/**
990-
* Gets the underlying disposable.
991-
* @return The underlying disposable.
992-
*/
993-
booleanDisposablePrototype.getDisposable = function () {
994-
return this.current === trueInstance ? disposableEmpty : this.current;
995-
};
996-
997-
/**
998-
* Sets the underlying disposable.
999-
* @param {Disposable} value The new underlying disposable.
1000-
*/
1001-
booleanDisposablePrototype.setDisposable = function (value) {
1002-
var shouldDispose = this.current === trueInstance;
1003-
if (!shouldDispose) {
1004-
var old = this.current;
1005-
this.current = value;
1006-
}
1007-
old && old.dispose();
1008-
shouldDispose && value && value.dispose();
1009-
};
1010-
1011-
/**
1012-
* Disposes the underlying disposable as well as all future replacements.
1013-
*/
1014-
booleanDisposablePrototype.dispose = function () {
1015-
if (!this.isDisposed) {
1016-
var old = this.current;
1017-
this.current = trueInstance;
1018-
this.isDisposed = trueInstance.isDisposed;
1019-
}
1020-
old && old.dispose();
1021-
};
1022-
1023-
return BooleanDisposable;
1024-
}());
1025-
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
1026-
return new BooleanDisposable(true);
994+
old && old.dispose();
1027995
};
996+
997+
// Multiple assignment disposable
1028998
var SerialDisposable = Rx.SerialDisposable = function () {
1029-
return new BooleanDisposable();
999+
this.isDisposed = false;
1000+
this.current = null;
1001+
};
1002+
SerialDisposable.prototype.getDisposable = function () {
1003+
return this.current;
1004+
};
1005+
SerialDisposable.prototype.setDisposable = function (value) {
1006+
var shouldDispose = this.isDisposed;
1007+
if (!shouldDispose) {
1008+
var old = this.current;
1009+
this.current = value;
1010+
}
1011+
old && old.dispose();
1012+
shouldDispose && value && value.dispose();
1013+
};
1014+
SerialDisposable.prototype.dispose = function () {
1015+
if (!this.isDisposed) {
1016+
this.isDisposed = true;
1017+
var old = this.current;
1018+
this.current = null;
1019+
}
1020+
old && old.dispose();
10301021
};
10311022

10321023
/**

dist/rx.all.compat.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.compat.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.js

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -780,62 +780,53 @@
780780
if (disposable.isDisposed) { throw new ObjectDisposedError(); }
781781
};
782782

783-
var BooleanDisposable = (function () {
784-
var trueInstance = (function () {
785-
var d = new BooleanDisposable();
786-
d.isDisposed = true;
787-
return d;
788-
}());
789-
790-
function BooleanDisposable (isSingle) {
791-
this.isDisposed = false;
783+
// Single assignment
784+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
785+
this.isDisposed = false;
786+
this.current = null;
787+
};
788+
SingleAssignmentDisposable.prototype.getDisposable = function () {
789+
return this.current;
790+
};
791+
SingleAssignmentDisposable.prototype.setDisposable = function (value) {
792+
if (this.current) { throw new Error('Disposable has already been assigned'); }
793+
var shouldDispose = this.isDisposed;
794+
!shouldDispose && (this.current = value);
795+
shouldDispose && value && value.dispose();
796+
};
797+
SingleAssignmentDisposable.prototype.dispose = function () {
798+
if (!this.isDisposed) {
799+
this.isDisposed = true;
800+
var old = this.current;
792801
this.current = null;
793-
this.isSingle = isSingle;
794802
}
795-
796-
var booleanDisposablePrototype = BooleanDisposable.prototype;
797-
798-
/**
799-
* Gets the underlying disposable.
800-
* @return The underlying disposable.
801-
*/
802-
booleanDisposablePrototype.getDisposable = function () {
803-
return this.current === trueInstance ? disposableEmpty : this.current;
804-
};
805-
806-
/**
807-
* Sets the underlying disposable.
808-
* @param {Disposable} value The new underlying disposable.
809-
*/
810-
booleanDisposablePrototype.setDisposable = function (value) {
811-
var shouldDispose = this.current === trueInstance;
812-
if (!shouldDispose) {
813-
var old = this.current;
814-
this.current = value;
815-
}
816-
old && old.dispose();
817-
shouldDispose && value && value.dispose();
818-
};
819-
820-
/**
821-
* Disposes the underlying disposable as well as all future replacements.
822-
*/
823-
booleanDisposablePrototype.dispose = function () {
824-
if (!this.isDisposed) {
825-
var old = this.current;
826-
this.current = trueInstance;
827-
this.isDisposed = trueInstance.isDisposed;
828-
}
829-
old && old.dispose();
830-
};
831-
832-
return BooleanDisposable;
833-
}());
834-
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
835-
return new BooleanDisposable(true);
803+
old && old.dispose();
836804
};
805+
806+
// Multiple assignment disposable
837807
var SerialDisposable = Rx.SerialDisposable = function () {
838-
return new BooleanDisposable();
808+
this.isDisposed = false;
809+
this.current = null;
810+
};
811+
SerialDisposable.prototype.getDisposable = function () {
812+
return this.current;
813+
};
814+
SerialDisposable.prototype.setDisposable = function (value) {
815+
var shouldDispose = this.isDisposed;
816+
if (!shouldDispose) {
817+
var old = this.current;
818+
this.current = value;
819+
}
820+
old && old.dispose();
821+
shouldDispose && value && value.dispose();
822+
};
823+
SerialDisposable.prototype.dispose = function () {
824+
if (!this.isDisposed) {
825+
this.isDisposed = true;
826+
var old = this.current;
827+
this.current = null;
828+
}
829+
old && old.dispose();
839830
};
840831

841832
/**

dist/rx.all.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.min.js

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.compat.js

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -971,62 +971,53 @@
971971
if (disposable.isDisposed) { throw new ObjectDisposedError(); }
972972
};
973973

974-
var BooleanDisposable = (function () {
975-
var trueInstance = (function () {
976-
var d = new BooleanDisposable();
977-
d.isDisposed = true;
978-
return d;
979-
}());
980-
981-
function BooleanDisposable (isSingle) {
982-
this.isDisposed = false;
974+
// Single assignment
975+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
976+
this.isDisposed = false;
977+
this.current = null;
978+
};
979+
SingleAssignmentDisposable.prototype.getDisposable = function () {
980+
return this.current;
981+
};
982+
SingleAssignmentDisposable.prototype.setDisposable = function (value) {
983+
if (this.current) { throw new Error('Disposable has already been assigned'); }
984+
var shouldDispose = this.isDisposed;
985+
!shouldDispose && (this.current = value);
986+
shouldDispose && value && value.dispose();
987+
};
988+
SingleAssignmentDisposable.prototype.dispose = function () {
989+
if (!this.isDisposed) {
990+
this.isDisposed = true;
991+
var old = this.current;
983992
this.current = null;
984-
this.isSingle = isSingle;
985993
}
986-
987-
var booleanDisposablePrototype = BooleanDisposable.prototype;
988-
989-
/**
990-
* Gets the underlying disposable.
991-
* @return The underlying disposable.
992-
*/
993-
booleanDisposablePrototype.getDisposable = function () {
994-
return this.current === trueInstance ? disposableEmpty : this.current;
995-
};
996-
997-
/**
998-
* Sets the underlying disposable.
999-
* @param {Disposable} value The new underlying disposable.
1000-
*/
1001-
booleanDisposablePrototype.setDisposable = function (value) {
1002-
var shouldDispose = this.current === trueInstance;
1003-
if (!shouldDispose) {
1004-
var old = this.current;
1005-
this.current = value;
1006-
}
1007-
old && old.dispose();
1008-
shouldDispose && value && value.dispose();
1009-
};
1010-
1011-
/**
1012-
* Disposes the underlying disposable as well as all future replacements.
1013-
*/
1014-
booleanDisposablePrototype.dispose = function () {
1015-
if (!this.isDisposed) {
1016-
var old = this.current;
1017-
this.current = trueInstance;
1018-
this.isDisposed = trueInstance.isDisposed;
1019-
}
1020-
old && old.dispose();
1021-
};
1022-
1023-
return BooleanDisposable;
1024-
}());
1025-
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
1026-
return new BooleanDisposable(true);
994+
old && old.dispose();
1027995
};
996+
997+
// Multiple assignment disposable
1028998
var SerialDisposable = Rx.SerialDisposable = function () {
1029-
return new BooleanDisposable();
999+
this.isDisposed = false;
1000+
this.current = null;
1001+
};
1002+
SerialDisposable.prototype.getDisposable = function () {
1003+
return this.current;
1004+
};
1005+
SerialDisposable.prototype.setDisposable = function (value) {
1006+
var shouldDispose = this.isDisposed;
1007+
if (!shouldDispose) {
1008+
var old = this.current;
1009+
this.current = value;
1010+
}
1011+
old && old.dispose();
1012+
shouldDispose && value && value.dispose();
1013+
};
1014+
SerialDisposable.prototype.dispose = function () {
1015+
if (!this.isDisposed) {
1016+
this.isDisposed = true;
1017+
var old = this.current;
1018+
this.current = null;
1019+
}
1020+
old && old.dispose();
10301021
};
10311022

10321023
/**

dist/rx.compat.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.compat.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)