forked from ReactiveX/rxjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'ReactiveX/master' into doc-generation
* ReactiveX/master: (29 commits) feat(operator): add debounce closes ReactiveX#193 feat(operator): add throttle feat(operator):add repeat bugfix(defer): Catch errors from Defer's observableFactory function. bugfix(merge): Prevent MergeSubscriber from setting its _isUnsubscribed flag to true before its inner subscriptions have all completed. feat(operator): Add count operator. chore(build): add uglifyjs minification to global build. chore(build): use typescript compiler for es5 build chore(tsd): update typings dependencies bugfix(reduce): Pass the initial value to the ReduceOperator. chore(operator): fix API signatures for merge, concat, combineLatest and zip feat(operator): Add minimal delay operator. chore(tests): add tests for skip feat(operator): add skipUntil closes ReactiveX#180 feat(operator): add groupBy feat(operator): Add do operator. Removing ensure feat(operator): Add expand operator. feat(operator): add finally feat(operator): Add distinctUntilChanged and distinctUntilKeyChanged ... Conflicts: package.json
- Loading branch information
Showing
66 changed files
with
3,143 additions
and
397 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* globals describe, it, expect */ | ||
var Rx = require('../dist/cjs/Rx'); | ||
|
||
var Notification = Rx.Notification; | ||
|
||
describe('Notification', function () { | ||
it('should exist', function () { | ||
expect(typeof Notification).toBe('function'); | ||
}); | ||
|
||
describe('createNext', function () { | ||
it('should return a Notification', function () { | ||
var n = Notification.createNext('test'); | ||
expect(n instanceof Notification).toBe(true); | ||
expect(n.value).toBe('test'); | ||
expect(n.kind).toBe('N'); | ||
expect(typeof n.exception).toBe('undefined'); | ||
expect(n.hasValue).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('createError', function () { | ||
it('should return a Notification', function () { | ||
var n = Notification.createError('test'); | ||
expect(n instanceof Notification).toBe(true); | ||
expect(typeof n.value).toBe('undefined'); | ||
expect(n.kind).toBe('E'); | ||
expect(n.exception).toBe('test'); | ||
expect(n.hasValue).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('createComplete', function () { | ||
it('should return a Notification', function () { | ||
var n = Notification.createComplete(); | ||
expect(n instanceof Notification).toBe(true); | ||
expect(typeof n.value).toBe('undefined'); | ||
expect(n.kind).toBe('C'); | ||
expect(typeof n.exception).toBe('undefined'); | ||
expect(n.hasValue).toBe(false); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* globals describe, it, expect */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.fromEvent', function () { | ||
it('should setup an event observable on objects with "on" and "off" ', function () { | ||
var onEventName, onHandler; | ||
var offEventName, offHandler; | ||
var obj = { | ||
on: function (a, b) { | ||
onEventName = a; | ||
onHandler = b; | ||
}, | ||
off: function (a, b) { | ||
offEventName = a; | ||
offHandler = b; | ||
} | ||
}; | ||
|
||
var subscription = Observable.fromEvent(obj, 'click') | ||
.subscribe(function () { }); | ||
|
||
subscription.unsubscribe(); | ||
|
||
expect(onEventName).toBe('click'); | ||
expect(typeof onHandler).toBe('function'); | ||
expect(offEventName).toBe(onEventName); | ||
expect(offHandler).toBe(onHandler); | ||
}); | ||
|
||
it('should setup an event observable on objects with "addEventListener" and "removeEventListener" ', function () { | ||
var onEventName, onHandler; | ||
var offEventName, offHandler; | ||
var obj = { | ||
addEventListener: function (a, b) { | ||
onEventName = a; | ||
onHandler = b; | ||
}, | ||
removeEventListener: function (a, b) { | ||
offEventName = a; | ||
offHandler = b; | ||
} | ||
}; | ||
|
||
var subscription = Observable.fromEvent(obj, 'click') | ||
.subscribe(function () { }); | ||
|
||
subscription.unsubscribe(); | ||
|
||
expect(onEventName).toBe('click'); | ||
expect(typeof onHandler).toBe('function'); | ||
expect(offEventName).toBe(onEventName); | ||
expect(offHandler).toBe(onHandler); | ||
}); | ||
|
||
it('should setup an event observable on objects with "addListener" and "removeListener" ', function () { | ||
var onEventName, onHandler; | ||
var offEventName, offHandler; | ||
var obj = { | ||
addListener: function (a, b) { | ||
onEventName = a; | ||
onHandler = b; | ||
}, | ||
removeListener: function (a, b) { | ||
offEventName = a; | ||
offHandler = b; | ||
} | ||
}; | ||
|
||
var subscription = Observable.fromEvent(obj, 'click') | ||
.subscribe(function () { }); | ||
|
||
subscription.unsubscribe(); | ||
|
||
expect(onEventName).toBe('click'); | ||
expect(typeof onHandler).toBe('function'); | ||
expect(offEventName).toBe(onEventName); | ||
expect(offHandler).toBe(onHandler); | ||
}); | ||
|
||
it('should pass through events that occur', function (done) { | ||
var send; | ||
var obj = { | ||
on: function (name, handler) { | ||
send = handler; | ||
}, | ||
off: function () { | ||
} | ||
}; | ||
|
||
var subscription = Observable.fromEvent(obj, 'click') | ||
.subscribe(function (e) { | ||
expect(e).toBe('test'); | ||
done(); | ||
}); | ||
|
||
send('test'); | ||
}); | ||
|
||
it('should pass through events that occur and use the selector if provided', function (done) { | ||
var send; | ||
var obj = { | ||
on: function (name, handler) { | ||
send = handler; | ||
}, | ||
off: function () { | ||
} | ||
}; | ||
|
||
function selector(x) { | ||
return x + '!'; | ||
} | ||
|
||
var subscription = Observable.fromEvent(obj, 'click', selector) | ||
.subscribe(function (e) { | ||
expect(e).toBe('test!'); | ||
done(); | ||
}); | ||
|
||
send('test'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* globals describe, it, expect, jasmine */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
var Promise = require('promise'); | ||
|
||
describe('Observable.fromEventPattern', function(){ | ||
it('should call addHandler on subscription', function () { | ||
var addHandlerCalledWith; | ||
var addHandler = function (h) { | ||
addHandlerCalledWith = h; | ||
}; | ||
|
||
var removeHandler = function () { }; | ||
|
||
Observable.fromEventPattern(addHandler, removeHandler) | ||
.subscribe(function () { }); | ||
|
||
expect(typeof addHandlerCalledWith).toBe('function'); | ||
}); | ||
|
||
it('should call removeHandler on unsubscription', function () { | ||
var removeHandlerCalledWith; | ||
var addHandler = function () { }; | ||
var removeHandler = function (h) { | ||
removeHandlerCalledWith = h; | ||
}; | ||
|
||
var subscription = Observable.fromEventPattern(addHandler, removeHandler) | ||
.subscribe(function () { }); | ||
|
||
subscription.unsubscribe(); | ||
|
||
expect(typeof removeHandlerCalledWith).toBe('function'); | ||
}); | ||
|
||
it('should send errors in addHandler down the error path', function () { | ||
Observable.fromEventPattern(function (handler) { | ||
throw 'bad'; | ||
}, function () { }) | ||
.subscribe(function () { }, | ||
function (err) { | ||
expect(err).toBe('bad'); | ||
}); | ||
}); | ||
|
||
it('should accept a selector that maps outgoing values', function (done) { | ||
var target; | ||
var trigger = function () { | ||
if (target) { | ||
target.apply(null, arguments); | ||
} | ||
}; | ||
|
||
var addHandler = function (handler) { | ||
target = handler; | ||
}; | ||
var removeHandler = function (handler) { | ||
target = null; | ||
}; | ||
var selector = function (a, b) { | ||
return a + b + '!'; | ||
}; | ||
|
||
Observable.fromEventPattern(addHandler, removeHandler, selector) | ||
.subscribe(function (x) { | ||
expect(x).toBe('testme!'); | ||
done(); | ||
}); | ||
|
||
trigger('test', 'me'); | ||
}); | ||
|
||
it('should send errors in the selector down the error path', function (done) { | ||
var target; | ||
var trigger = function (value) { | ||
if (target) { | ||
target(value); | ||
} | ||
}; | ||
|
||
var addHandler = function (handler) { | ||
target = handler; | ||
}; | ||
var removeHandler = function (handler) { | ||
target = null; | ||
}; | ||
var selector = function (x) { | ||
throw 'bad'; | ||
}; | ||
|
||
Observable.fromEventPattern(addHandler, removeHandler, selector) | ||
.subscribe(function () { }, | ||
function (err) { | ||
expect(err).toBe('bad'); | ||
done(); | ||
}); | ||
|
||
trigger('test'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* globals describe, it, expect */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('count', function () { | ||
it('should count the values of an observable', function (done) { | ||
Observable.fromArray([1, 2, 3]) | ||
.count() | ||
.subscribe(function (total) { | ||
expect(total).toEqual(3); | ||
}, null, done); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* globals describe, it, expect */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.prototype.debounce()', function () { | ||
it('should debounce events', function (done) { | ||
Observable.of(1, 2, 3).debounce(50) | ||
.subscribe(function (x) { | ||
expect(x).toBe(1); | ||
}, null, done); | ||
}); | ||
|
||
it('should debounce events multiple times', function (done) { | ||
var expected = ['1-0', '2-0'] | ||
Observable.concat( | ||
Observable.timer(0, 10).take(3).map(function (x) { return '1-' + x }), | ||
Observable.timer(80, 10).take(5).map(function (x) { return '2-' + x }) | ||
) | ||
.debounce(50) | ||
.subscribe(function (x) { | ||
expect(x).toBe(expected.shift()); | ||
}, null, done); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* globals describe, it, expect */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.prototype.defaultIfEmpty()', function () { | ||
it('should return the argument if Observable is empty', function (done) { | ||
var emptyObservable = Observable.empty(); | ||
emptyObservable.defaultIfEmpty(2) | ||
.subscribe(function(x) { | ||
expect(x).toBe(2); | ||
}, null, done); | ||
}); | ||
|
||
it('should return null if the Observable is empty and no arguments', function(done) { | ||
var emptyObservable = Observable.empty(); | ||
emptyObservable.defaultIfEmpty() | ||
.subscribe(function(x) { | ||
expect(x).toBe(null); | ||
}, null, done); | ||
}); | ||
|
||
it('should return the Observable if not empty with a default value', function(done) { | ||
var expected = [1,2,3]; | ||
var observable = Observable.of(1,2,3); | ||
observable.defaultIfEmpty(2) | ||
.subscribe(function(x) { | ||
expect(x).toBe(expected.shift()); | ||
}, null, done); | ||
}); | ||
|
||
it('should return the Observable if not empty with no default value', function(done) { | ||
var expected = [1,2,3]; | ||
var observable = Observable.of(1,2,3); | ||
observable.defaultIfEmpty() | ||
.subscribe(function(x) { | ||
expect(x).toBe(expected.shift()); | ||
}, null, done); | ||
}); | ||
|
||
it('should error if the Observable errors', function(done) { | ||
var observable = Observable.throw("candy"); | ||
observable.defaultIfEmpty(2) | ||
.subscribe(function(x) { | ||
throw "this should not be called"; | ||
}, function(err) { | ||
expect(err).toBe("candy"); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.