NOT ACTIVELY MAINTAINED
This project works fine but is not actively maintained.
For the new code, you might want to try the new official rx.disposables package instead.
disposables
Disposables let you safely compose resource disposal semantics.
Think DOM nodes, event handlers, socket connections.
This implementation of disposables is extracted from RxJS.
I took the liberty to tweak the code style to my liking and provide this as a standalone package.
This tiny package includes several disposables:
The API is mostly the same as RxJS except stricter in a few places.
It does not strive for 100% API compatibility with RxJS, but generally behavior is the same.
It's best if you consult the source and tests, as classes are small and few.
Usage
import { Disposable, CompositeDisposable, SerialDisposable } from 'disposables';
function attachHandlers(node) {
let someHandler = ...;
node.addEventHandler(someHandler);
return new Disposable(() => {
node.removeEventHandler(someHandler);
});
}
let nodes = ...;
let compositeDisp = new CompositeDisposable(nodes.map(attachHandlers));
let moreNodes = ...
moreNodes.map(attachHandlers).forEach(d => compositeDisp.add(d));
function goodbye() {
compositeDisp.dispose();
}
let serialDisp = new SerialDisposable();
serialDisp.setDisposable(compositeDisp);
function replaceNodes(newNodes) {
let nextCompositeDisp = new CompositeDisposable(newNodes.map(attachHandlers));
serialDisp.setDisposable(nextCompositeDisp);
}
License
Like the original RxJS code, it is licensed under Apache 2.0.