This file contains hidden or 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.from(store) | |
.map(state => state.search) | |
.distinctUntilChanged() | |
.switchMap(search => ( | |
getColorsObservable() | |
.filter(color => color.includes(search)) | |
)) | |
.subscribe(result => { | |
store.dispatch({ type: 'ADD_RESULT', result }) | |
}) |
This file contains hidden or 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.from(store) | |
.map(state => state.search) | |
.distinctUntilChanged() |
This file contains hidden or 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
const App = connect(state => state, dispatch => ({ | |
setSearch: e => { | |
dispatch({ type: 'SET_SEARCH', search: e.target.value }) | |
} | |
}))(({ search, results, setSearch }) => ( | |
<div> | |
<input value={search} onChange={setSearch} /> | |
{results.map(result => ( | |
<div key={result}>{result}</div> | |
))} |
This file contains hidden or 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
const defaultState = { search: '', results: [] } | |
const store = createStore((state = defaultState, action) => { | |
switch (action.type) { | |
case 'SET_SEARCH': | |
return { ...state, search: action.search, results: [] } | |
case 'ADD_RESULTS': | |
return { ...state, results: state.results.concat(action.results) } | |
default: | |
return state | |
} |
This file contains hidden or 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
const colors = require('css-color-list')() | |
// Returns an observable that emits a color every 10ms. | |
// Stops when we've gone through every color. | |
const getColorsObservable = () => | |
Rx.Observable.interval(10) | |
.map(i => colors[i]) | |
.takeWhile(color => color != null) |
This file contains hidden or 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.from(store) | |
.map(state => state.isPlaying) | |
.distinctUntilChanged() | |
.subscribe(isPlaying => { | |
if (isPlaying) { | |
play() | |
} else { | |
pause() | |
} | |
}) |
This file contains hidden or 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
const getAction = ({ action, state }) => | |
typeof action === "function" ? action(state) : action | |
const Dispatch = connect(state => ({ state }))( | |
class Dispatch extends Component { | |
componentWillMount() { | |
const currentAction = getAction(this.props) | |
if (currentAction != null) this.props.dispatch(currentAction) | |
} |
This file contains hidden or 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
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* @flow | |
*/ | |
import React, { Component } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, |