Skip to content

Commit

Permalink
Merge remote-tracking branch 'ReactiveX/master' into doc-generation
Browse files Browse the repository at this point in the history
* 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
robwormald committed Aug 24, 2015
2 parents c7352ea + f03adaf commit a8e8b49
Show file tree
Hide file tree
Showing 66 changed files with 3,143 additions and 397 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"main": "index.js",
"scripts": {
"build_all": "npm run build_es6 && npm run build_amd && npm run build_cjs && npm run build_global",
"build_amd": "rm -rf dist/amd && babel dist/es6 --out-dir dist/amd --modules amd --sourceMaps --loose all",
"build_cjs": "rm -rf dist/cjs && babel dist/es6 --out-dir dist/cjs --modules common --sourceMaps --loose all",
"build_amd": "rm -rf dist/amd && tsc typings/es6-shim/es6-shim.d.ts src/Rx.ts -m amd --outDir dist/amd --sourcemap --target ES5",
"build_cjs": "rm -rf dist/cjs && tsc typings/es6-shim/es6-shim.d.ts src/Rx.ts -m commonjs --outDir dist/cjs --sourcemap --target ES5",
"build_es6": "rm -rf dist/es6 && tsc src/Rx.ts --outDir dist/es6 --target ES6 -d",
"build_global": "rm -rf dist/global && mkdir dist/global && browserify src/Rx.global.js --outfile dist/global/Rx.js",
"build_global": "rm -rf dist/global && mkdir dist/global && browserify src/Rx.global.js --outfile dist/global/Rx.js; ./node_modules/.bin/uglifyjs ./dist/global/Rx.js --source-map ./dist/global/Rx.min.js.map --screw-ie8 -o ./dist/global/Rx.min.js",
"build_perf": "npm run build_es6 && npm run build_cjs && npm run build_global && npm run perf",
"build_test": "rm -rf dist/ && npm run build_es6 && npm run build_cjs && jasmine",
"test": "jasmine",
Expand Down Expand Up @@ -45,6 +45,7 @@
"benchpress": "^2.0.0-alpha.25",
"browserify": "^11.0.0",
"canonical-path": "0.0.2",
"colors": "^1.1.2",
"dgeni": "^0.4.1",
"dgeni-packages": "^0.10.18",
"glob": "^5.0.14",
Expand All @@ -56,9 +57,10 @@
"platform": "^1.3.0",
"promise": "^7.0.3",
"protractor": "^1.7.0",
"rx": "^2.4.3",
"typescript": "^1.5.3"
},
"rx": "^3.0.0",
"typescript": "^1.5.0-beta",
"uglifyjs": "^2.4.10"
},
"format": "es6",
"directories": {
"lib": "src"
Expand Down
43 changes: 43 additions & 0 deletions spec/Notification-spec.js
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);
});
});
});
122 changes: 122 additions & 0 deletions spec/observables/fromEvent-spec.js
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');
});
});
100 changes: 100 additions & 0 deletions spec/observables/fromEventPattern-spec.js
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');
});
});
13 changes: 13 additions & 0 deletions spec/operators/count-spec.js
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);
});
});
24 changes: 24 additions & 0 deletions spec/operators/debounce-spec.js
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);
});
});
50 changes: 50 additions & 0 deletions spec/operators/defaultIfEmpty-spec.js
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();
});
});
});
Loading

0 comments on commit a8e8b49

Please sign in to comment.