Last active
August 29, 2015 14:27
-
-
Save creepone/c6679e63c150ae5735a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this._inputChangeSignal() | |
.merge(this._disableTriggerSignal()) | |
.merge(Rx.Observable.return()) // start with the initial search immediately | |
.debounce(500) | |
.flatMapLatest(function () { | |
self.$el.find(".results").hide(); | |
self.$el.find(".pulse").show(); | |
self._populateModel(); | |
return self._getCounts(); | |
}) | |
.subscribe(function (results) { | |
self.model.riskClasses = results.riskClasses; | |
self._renderCounts(results.counts); | |
self.$el.find(".pulse").hide(); | |
self.$el.find(".results").fadeIn(); | |
}); | |
_inputChangeSignal: function() { | |
return Rx.Observable.merge( | |
$.map(this.$el.find("[data-riskclass]"), function (el) { | |
return Rx.Observable.fromEvent(el, "change"); | |
}) | |
); | |
}, | |
_disableTriggerSignal: function() { | |
return Rx.Observable.merge( | |
$.map(this.$el.find(".disable-trigger"), function (el) { | |
return Rx.Observable.fromEvent(el, "click"); | |
}) | |
); | |
}, | |
ajax: function (url, o) { | |
var subject = new Rx.Subject(); | |
$.ajax({ | |
type: "POST", | |
url: url, | |
dataType: "json", | |
contentType: "application/json; charset=utf-8", | |
data: JSON.stringify(o) | |
}) | |
.done(function(res) { | |
subject.onNext(res); | |
subject.onCompleted(); | |
}) | |
.fail(function() { | |
_onAjaxFail(arguments); | |
subject.onCompleted(); | |
}); | |
return subject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment