Skip to content

Instantly share code, notes, and snippets.

@cwharris
Created May 8, 2013 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwharris/5537240 to your computer and use it in GitHub Desktop.
Save cwharris/5537240 to your computer and use it in GitHub Desktop.
obsFilter
Rx.Observable.prototype.obsFilter = function (func) {
var self = this;
return Rx.Observable.createWithDisposable(function (o) {
self.subscribe(function (source) {
var subject = null;
source.finallyAction(function() {
if (subject !== null){
subject.onCompleted();
subject = null;
}
}).subscribe(function (x) {
if (func(x)) {
if (subject === null) {
subject = new Rx.Subject();
o.onNext(subject);
}
subject.onNext(x);
} else {
if (subject !== null) {
subject.onCompleted();
subject = null;
}
}
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment