This is RxJS v 4. Find the latest version here
Represents a disposable resource that only disposes its underlying disposable resource when all getDisposable
dependent disposable objects have been disposed.
The follow example shows the basic usage of an Rx.RefCountDisposable
.
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
var refCountDisposable = new Rx.RefCountDisposable(disposable);
var disposable1 = refCountDisposable.getDisposable();
var disposable2 = refCountDisposable.getDisposable();
disposable1.dispose();
console.log(disposable.isDisposed);
// => false
disposable2.dispose();
console.log(disposable.isDisposed);
// => false
refCountDisposable.dispose();
// => disposed
console.log(refCountDisposable.isDisposed);
// => true
- rx.js
Initializes a new instance of the Rx.RefCountDisposable
class with the specified disposable
disposable
(Disposable): Underlying disposable.
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
var refCountDisposable = new Rx.RefCountDisposable(disposable);
console.log(refCountDisposable.isDisposed);
// => false
- rx.js
Disposes the underlying disposable only when all dependent disposables have been disposed.
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
var refCountDisposable = new Rx.RefCountDisposable(disposable);
var disposable1 = refCountDisposable.getDisposable();
var disposable2 = refCountDisposable.getDisposable();
disposable1.dispose();
console.log(disposable.isDisposed);
// => false
disposable2.dispose();
console.log(disposable.isDisposed);
// => false
refCountDisposable.dispose();
// => disposed
console.log(refCountDisposable.isDisposed);
// => true
- rx.js
Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
(Disposable): A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
var refCountDisposable = new Rx.RefCountDisposable(disposable);
var d = refCountDisposable.getDisposable();
console.log(d === disposable);
// => false
// Clean up disposables
disposable.dispose();
d.dispose();
// Now try to dispose the main
refCountDisposable.dispose();
console.log(refCountDisposable.isDisposed);
// => true
- rx.js
Gets a value that indicates whether the object is disposed.
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
var refCountDisposable = new Rx.RefCountDisposable(disposable);
disposable.dispose();
console.log(refCountDisposable.isDisposed);
// => false
refCountDisposable.dispose();
// => disposed
console.log(refCountDisposable.isDisposed);
// => true
- rx.js