Skip to content

Instantly share code, notes, and snippets.

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 })
})
Rx.Observable.from(store)
.map(state => state.search)
.distinctUntilChanged()
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>
))}
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
}
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)
Rx.Observable.from(store)
.map(state => state.isPlaying)
.distinctUntilChanged()
.subscribe(isPlaying => {
if (isPlaying) {
play()
} else {
pause()
}
})
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)
}
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
const ButtonContainer = cssta(Animated.View)`
...
transition: background-color 0.2s;
...
`;
const ButtonText = cssta(Animated.Text)`
...
transition: color 0.3s;
`;
const ButtonContainer = cssta(View)`
--primary: #e67e22;
--foreground: var(--primary);
--background: white;
...
border: 1px solid var(--primary);
background-color: var(--background);
[active] {