Represents a disposable resource which only allows a single assignment of its underlying disposable resource. If an underlying disposable resource has already been set, future attempts to set the underlying disposable resource will throw an Error.
The follow example shows the basic usage of an Rx.SingleAssignmentDisposable.
var singleDisposable = new Rx.SingleAssignmentDisposable();
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
singleDisposable.setDisposable(disposable);
singleDisposable.dispose();
// => disposed
- rx.js
Initializes a new instance of the Rx.SingleAssignmentDisposable
class.
var singleDisposable = new Rx.SingleAssignmentDisposable();
console.log(singleDisposable.isDisposed);
// => false
- rx.js
Disposes the underlying disposable.
var singleDisposable = new Rx.SingleAssignmentDisposable();
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
singleDisposable.setDisposable(disposable);
console.log(singleDisposable.isDisposed);
// => false
singleDisposable.dispose();
// => disposed
console.log(singleDisposable.isDisposed);
// => true
- rx.js
Gets the underlying disposable. After disposal, the result of getting this method is undefined.
(Disposable): The underlying disposable.
var singleDisposable = new Rx.SingleAssignmentDisposable();
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
singleDisposable.setDisposable(disposable);
var d = singleDisposable.getDisposable();
console.log(d === disposable);
- rx.js
Sets the underlying disposable.
value
(Disposable): The new underlying disposable.
var singleDisposable = new Rx.SingleAssignmentDisposable();
var d1 = Rx.Disposable.create(function () {
console.log('one');
});
singleDisposable.setDisposable(d1);
var d2 = Rx.Disposable.create(function () {
console.log('two');
});
try {
singleDisposable.setDisposable(d2);
} catch (e) {
console.log(e.message);
}
// => Disposable has already been assigned
- rx.js
Gets a value that indicates whether the object is disposed.
var singleDisposable = new Rx.SingleAssignmentDisposable();
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
singleDisposable.setDisposable(disposable);
console.log(singleDisposable.isDisposed);
// => false
singleDisposable.dispose();
// => disposed
console.log(singleDisposable.isDisposed);
// => true
- rx.js