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
/** | |
* Pauses the underlying observable sequence based upon the observable sequence which yields true/false, | |
* and yields the values that were buffered while paused. | |
* @example | |
* var pauser = new Rx.Subject(); | |
* var source = Rx.Observable.interval(100).pausableBuffered(pauser); | |
* @param {Observable} pauser The observable sequence used to pause the underlying sequence. | |
* @returns {Observable} The observable sequence which is paused based upon the pauser. | |
*/ | |
observableProto.pausableBuffered = function (subject) { |
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
// Shim in iterator support | |
var $iterator$ = (typeof Symbol === 'object' && Symbol.iterator) || | |
'_es6shim_iterator_'; | |
// Firefox ships a partial implementation using the name @@iterator. | |
// https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14 | |
// So use that name if we detect it. | |
if (window.Set && typeof new window.Set()['@@iterator'] === 'function') { | |
$iterator$ = '@@iterator'; | |
} |
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
var fn = typeof jQuery !== 'undefined' && jQuery ? | |
jQuery.fn : | |
(typeof Zepto !== 'undefined' && Zepto ? Zepto.fn : null); | |
if (fn) { | |
fn.onAsObservable = function(event, selector, resultSelector) { | |
var self = this; | |
return Rx.Observable.fromEventPattern( | |
function(h) { self.on(event, selector, h); }, | |
function(h) { self.off(event, selector, h); }, |
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
/* Fix older IE events */ | |
function fixEvent(event) { | |
var stopPropagation = function () { | |
this.cancelBubble = true; | |
}; | |
var preventDefault = function () { | |
this.bubbledKeyCode = this.keyCode; | |
if (this.ctrlKey) { | |
try { |
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
/* | |
* Pausable is for hot observables in which values are lost between pause and resume | |
*/ | |
// With no outside controller | |
var pausable = Rx.Observable.fromEvent(document, 'mousemove').pausable(); | |
var subscription = pausable.subscribe(function (next) { | |
// Do something with values | |
}); |
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
/** | |
* Creates an observable sequence from an incoming generator with no arguments | |
* @example | |
* var source = Observable.fromGenerator(function * () { yield 42; }); | |
* @param {Function} generatorFunction A function which is a generator. | |
* @param {Scheduler} [scheduler] Optional scheduler for scheduling recursive calls. Defaults to current thread if not specified | |
* @returns {Observable} An observable sequence which is generated by the generator. | |
*/ | |
Observable.spawn = function (generatorFunction, scheduler) { | |
return observableFromGenerator(observableFromGenerator, scheduler)(); |
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
var fnString = 'function'; | |
function toThunk(obj, ctx) { | |
if (Array.isArray(obj)) { | |
return objectToThunk.call(ctx, obj); | |
} | |
if (isGeneratorFunction(obj)) { | |
return observableSpawn(obj.call(ctx)); | |
} |
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
function fakeEvent(value) { | |
return Rx.Observable.create(function(observer) { | |
// Not capturing release | |
setInterval(function () { | |
observer.onNext(value++); | |
}, 500); | |
}).publish().refCount(); | |
} |
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
Rx.Observable.prototype.map = function (selector, thisArg) { | |
return new MapObservable(this, selector, thisArg); | |
}; | |
var MapObserver = (function (__super__) { | |
function Klass(observable, observer) { | |
this.observable = observable; | |
this.observer = observer; | |
__super__.call(this); |
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
/** | |
* Invokes a specified action after the source observable sequence terminates gracefully or exceptionally. | |
* | |
* @example | |
* var res = observable.finallyAction(function () { console.log('sequence ended'; }); | |
* @param {Function} finallyAction Action to invoke after the source observable sequence terminates. | |
* @returns {Observable} Source sequence with the action-invoking termination behavior applied. | |
*/ | |
observableProto['finally'] = observableProto.finallyAction = function (action) { | |
var source = this; |