-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45dea00
commit aef4283
Showing
15 changed files
with
127 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
build | ||
npm-debug.log |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { createActions } from "../rx-state/RxState"; | ||
import { createActions } from "../state/RxState"; | ||
|
||
export default createActions(["increment$", "decrement$", "reset$"]); |
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import Rx from "rxjs"; | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { RxStateProvider, createState } from "./state/RxState" | ||
import App from "./components/App"; | ||
import reducer$ from "./reducers"; | ||
|
||
ReactDOM.render( | ||
<RxStateProvider state$={createState(reducer$)}> | ||
<App /> | ||
</RxStateProvider>, | ||
document.getElementById("root"), | ||
); |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import Rx from "rxjs"; | ||
import { createState } from "./rx-state/RxState"; | ||
import Rx from "rxjs" | ||
import CounterReducer$ from "app/reducers/CounterReducer"; | ||
|
||
const reducer$ = Rx.Observable.merge( | ||
CounterReducer$.map(reducer => ["counter", reducer]), | ||
); | ||
|
||
export default createState(reducer$); | ||
export default reducer$; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,75 @@ | ||
import test from "ava"; | ||
import { mount } from "enzyme"; | ||
import Rx from "rxjs"; | ||
import React from "react"; | ||
|
||
import { | ||
createAction, | ||
createActions, | ||
createState, | ||
RxStateProvider, | ||
connect, | ||
} from "./RxState"; | ||
|
||
test("createAction creates new Subject instance", t => { | ||
const action$ = createAction(); | ||
const anotherAction$ = createAction(); | ||
|
||
t.true(action$ instanceof Rx.Subject); | ||
t.not(action$, anotherAction$); | ||
}); | ||
|
||
test("createActions creates new dict with actions", t => { | ||
const actions = createActions(["add$", "decrement$"]); | ||
|
||
t.deepEqual(actions.add$, new Rx.Subject); | ||
t.deepEqual(actions.decrement$, new Rx.Subject); | ||
t.is(actions.count$, undefined); | ||
}); | ||
|
||
test("createState creates reactive state using scoped reducers", t => { | ||
const add$ = new Rx.Subject; | ||
const counterReducer$ = add$.map(payload => state => state + payload); | ||
const rootReducer$ = counterReducer$.map(counter => ["counter", counter]); | ||
const state$ = createState(rootReducer$, Rx.Observable.of({ counter: 10 })); | ||
|
||
t.plan(1); | ||
|
||
add$.next(1); // No subscribers yet | ||
|
||
state$.toArray().subscribe(results => { | ||
t.deepEqual(results, [{ counter: 10 }, { counter: 12 }]); | ||
}); | ||
|
||
add$.next(2); | ||
add$.complete(); | ||
}); | ||
|
||
test("connect maps state to props in RxStateProvider context", t => { | ||
const add$ = new Rx.Subject; | ||
const counterReducer$ = add$.map(payload => state => state + payload); | ||
const rootReducer$ = counterReducer$.map(counter => ["counter", counter]); | ||
const state$ = createState(rootReducer$, Rx.Observable.of({ counter: 10 })); | ||
|
||
const Counter = ({ counter, add }) => ( | ||
<div> | ||
<h1>{counter}</h1> | ||
<button onClick={add}>add</button> | ||
</div> | ||
); | ||
|
||
const ConnectedCounter = connect(state => ({ | ||
counter: state.counter, | ||
add: () => add$.next(1), | ||
}))(Counter); | ||
|
||
const tree = mount( | ||
<RxStateProvider state$={state$}> | ||
<ConnectedCounter /> | ||
</RxStateProvider> | ||
); | ||
|
||
t.is(tree.find("h1").text(), "10"); | ||
tree.find("button").simulate("click") | ||
t.is(tree.find("h1").text(), "11"); | ||
}); |
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,3 @@ | ||
global.document = require('jsdom').jsdom('<body></body>'); | ||
global.window = document.defaultView; | ||
global.navigator = window.navigator; |
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