Skip to content

Commit

Permalink
Merge pull request #3 from bsideup/rx5-fix
Browse files Browse the repository at this point in the history
redo RxJS 5 support with adapters
  • Loading branch information
bsideup authored Feb 7, 2017
2 parents 5b9b5ad + 01436a6 commit f7c7378
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 186 deletions.
3 changes: 3 additions & 0 deletions examples/wikistream/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import "babel-polyfill";
import React from "react";
import ReactDOM from "react-dom";
import { rxConnect, ofActions } from "rx-connect";
import rx5Adapter from "../../../lib/rx5Adapter";
import Rx from "rxjs";

rxConnect.adapter = rx5Adapter;

import { ofWikiChanges } from "./wikiChangesObservable";

const CHANNELS = [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"clean": "rimraf lib dist",
"lint": "eslint src",
"build:lib": "babel src --out-dir lib",
"build:lib": "babel src --ignore __tests__ --out-dir lib",
"build:umd": "cross-env NODE_ENV=development webpack src/index.js dist/rx-connect.js",
"build:umd:min": "cross-env NODE_ENV=production webpack src/index.js dist/rx-connect.min.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
Expand Down
27 changes: 24 additions & 3 deletions src/__tests__/__snapshots__/mapActionCreators-test.js.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
exports[`test creates FuncSubject-like action 1`] = `
exports[`RxJS 4 creates FuncSubject-like action 1`] = `
Array [
1,
2,
3,
]
`;

exports[`test passes non-observables as is 1`] = `
exports[`RxJS 4 passes non-observables as is 1`] = `
Object {
"a": 123,
"b": "hi!",
}
`;

exports[`test strips dollar sign from Observable property names 1`] = `
exports[`RxJS 4 strips dollar sign from Observable property names 1`] = `
Object {
"a": [Function],
}
`;

exports[`RxJS 5 creates FuncSubject-like action 1`] = `
Array [
1,
2,
3,
]
`;

exports[`RxJS 5 passes non-observables as is 1`] = `
Object {
"a": 123,
"b": "hi!",
}
`;

exports[`RxJS 5 strips dollar sign from Observable property names 1`] = `
Object {
"a": [Function],
}
Expand Down
133 changes: 120 additions & 13 deletions src/__tests__/__snapshots__/rxConnect-test.js.snap
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
exports[`test accepts function-based mutations 1`] = `
exports[`RxJS 4 accepts function-based mutations 1`] = `
<div>
123
</div>
`;

exports[`test ignores not connect properties 1`] = `<div />`;
exports[`RxJS 4 ignores not connect properties 1`] = `<div />`;

exports[`test noDebounce 1`] = `
exports[`RxJS 4 noDebounce 1`] = `
<div>
0
</div>
`;

exports[`test noDebounce 2`] = `
exports[`RxJS 4 noDebounce 2`] = `
<div>
1
</div>
`;

exports[`test passes children automatically 1`] = `
exports[`RxJS 4 passes children automatically 1`] = `
<div>
Hello, RxConnect!
</div>
`;

exports[`test passes properties as Observable 1`] = `
exports[`RxJS 4 passes properties as Observable 1`] = `
<div>
123
</div>
`;

exports[`test receives new props 1`] = `
exports[`RxJS 4 receives new props 1`] = `
<div>
15
</div>
`;

exports[`test receives new props 2`] = `
exports[`RxJS 4 receives new props 2`] = `
<div>
15
</div>
`;

exports[`test receives new props 3`] = `
exports[`RxJS 4 receives new props 3`] = `
<div>
-15
</div>
`;

exports[`test throws an error if mutation is neither an object or function 1`] = `
exports[`RxJS 4 throws an error if mutation is neither an object or function 1`] = `
Array [
"Mutation must be a plain object or function. Check rxConnect of Component. Got: ",
Array [
Expand All @@ -57,21 +57,128 @@ Array [
]
`;

exports[`test works with Array 1`] = `
exports[`RxJS 4 throws an error if selector is neither an Observable or function 1`] = `
Array [
"Selector must be a function or an Observable. Check rxConnect of Component. Got: ",
undefined,
]
`;

exports[`RxJS 4 throws an error if selector returns non-Observable 1`] = `
Array [
"Selector must return an Observable or an iterator of observables. Check rxConnect of Component. Got: ",
undefined,
]
`;

exports[`RxJS 4 works with Array 1`] = `
<div>
123
bar
</div>
`;

exports[`RxJS 4 works with Generator 1`] = `
<div>
123
bar
</div>
`;

exports[`RxJS 4 works with Observable 1`] = `
<div>
123
</div>
`;

exports[`RxJS 5 accepts function-based mutations 1`] = `
<div>
123
</div>
`;

exports[`RxJS 5 ignores not connect properties 1`] = `<div />`;

exports[`RxJS 5 noDebounce 1`] = `
<div>
0
</div>
`;

exports[`RxJS 5 noDebounce 2`] = `
<div>
1
</div>
`;

exports[`RxJS 5 passes children automatically 1`] = `
<div>
Hello, RxConnect!
</div>
`;

exports[`RxJS 5 passes properties as Observable 1`] = `
<div>
123
</div>
`;

exports[`RxJS 5 receives new props 1`] = `
<div>
15
</div>
`;

exports[`RxJS 5 receives new props 2`] = `
<div>
15
</div>
`;

exports[`RxJS 5 receives new props 3`] = `
<div>
-15
</div>
`;

exports[`RxJS 5 throws an error if mutation is neither an object or function 1`] = `
Array [
"Mutation must be a plain object or function. Check rxConnect of Component. Got: ",
Array [
123,
],
]
`;

exports[`RxJS 5 throws an error if selector is neither an Observable or function 1`] = `
Array [
"Selector must be a function or an Observable. Check rxConnect of Component. Got: ",
undefined,
]
`;

exports[`RxJS 5 throws an error if selector returns non-Observable 1`] = `
Array [
"Selector must return an Observable or an iterator of observables. Check rxConnect of Component. Got: ",
undefined,
]
`;

exports[`RxJS 5 works with Array 1`] = `
<div>
123
bar
</div>
`;

exports[`test works with Generator 1`] = `
exports[`RxJS 5 works with Generator 1`] = `
<div>
123
bar
</div>
`;

exports[`test works with Observable 1`] = `
exports[`RxJS 5 works with Observable 1`] = `
<div>
123
</div>
Expand Down
58 changes: 37 additions & 21 deletions src/__tests__/mapActionCreators-test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
import Rx from "rx";
import { mapActionCreators } from "../";
import { mapActionCreators, rxConnect } from "../";
import rx5Adapter from "../rx5Adapter";
import { getAdapter } from "../rxConnect";

test("passes non-observables as is", async () => {
const props = await mapActionCreators({ a: 123, b: "hi!" }).toPromise();
const suites = {
"RxJS 4": () => {},
"RxJS 5": () => rxConnect.adapter = rx5Adapter
}

expect(props).toMatchSnapshot();
});
Object.entries(suites).forEach(([ name, initializer ]) => describe(name, () => {
let Rx;
beforeEach(() => {
initializer();
const adapter = getAdapter();
Rx = adapter.Rx;
});

test("strips dollar sign from Observable property names", async () => {
const actions = {
a$: new Rx.Subject()
};
it("passes non-observables as is", async () => {
const props = await mapActionCreators({ a: 123, b: "hi!" }).toPromise();

const props = await mapActionCreators(actions).toPromise();
expect(props).toMatchSnapshot();
});

expect(props).toMatchSnapshot();
});
it("strips dollar sign from Observable property names", async () => {
const actions = {
a$: new Rx.Subject()
};

test("creates FuncSubject-like action", async () => {
const actions = {
a$: new Rx.BehaviorSubject()
};
const props = await mapActionCreators(actions).toPromise();

const props = await mapActionCreators(actions).toPromise();
expect(props).toMatchSnapshot();
});

props.a(1, 2, 3);
it("creates FuncSubject-like action", async () => {
const actions = {
a$: new Rx.BehaviorSubject()
};

expect(actions.a$.getValue()).toMatchSnapshot();
});
const props = await mapActionCreators(actions).toPromise();

props.a(1, 2, 3);

expect(actions.a$.getValue()).toMatchSnapshot();
});

}));
Loading

0 comments on commit f7c7378

Please sign in to comment.