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 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:
Disposable
ensures itsdispose
action runs only once;CompositeDisposable
ensures a group of disposables are disposed together;SerialDisposable
switches underlying disposables on the fly and disposes them.
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
; // or you can import just the ones you need to keep it even tinier// import SerialDisposable from 'disposables/modules/SerialDisposable'; { let someHandler = ...; node; // use Disposable to guarantee single execution return { node; };} // CompositeDisposable lets you compose several disposables...let nodes = ...;let compositeDisp = nodes; // and more later...let moreNodes = ...moreNodes; // and dispose them at once! { compositeDisp;} // ... or replace with a bunch of new ones ...let serialDisp = ;serialDisp; { let nextCompositeDisp = newNodes; // release all the previous disposables: serialDisp;} // with a guarantee of each dispose() called only once.
License
Like the original RxJS code, it is licensed under Apache 2.0.