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
function epic(actions){ | |
return actions.ofType('FOO') | |
.mergeMap(action => { | |
const transformed = transform(action); // may throw collapsing the pipe | |
return makeThingDoAsyncy(transform) | |
.catch(e => [foo(e)]); // won't catch above | |
}); | |
} | |
// imperative |
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
import { createServer, at } from 'fyfe'; | |
import { GET, composeRoutes, composeMiddleware } from 'fyfe-compose-routes'; | |
import fyfeDefaults from 'fyfe-defaults'; | |
// composes routes together | |
// first route to return something other then Void will win | |
const routes = composeRoutes( | |
// use a route handler | |
// Request => Responce|String|Stream|Void | |
GET('/', renderIndex), |
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
# fetching a single pull request from github | |
# put it into ~/.profile or ~/.bashrc | |
function fetch_pr() { | |
PR=$1 | |
BRANCH=$2 | |
if [ -z $PR ]; then | |
echo "Missing pull request number" | |
return 1 | |
fi |
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
# npm publish with goodies | |
# prerequisites: | |
# `npm install -g trash conventional-recommended-bump conventional-changelog conventional-github-releaser conventional-commits-detector json` | |
# `np` with optional argument `patch`/`minor`/`major`/`<version>` | |
# defaults to conventional-recommended-bump | |
# and optional argument preset `angular`/ `jquery` ... | |
# defaults to conventional-commits-detector | |
np() { | |
travis status --no-interactive && | |
trash node_modules &>/dev/null; |
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
export class BadFunComp extends React.PureComponent { | |
handleFun() { | |
const { funApi } = this.props; | |
funAPi(); | |
} | |
render() { | |
// displayCoolness.props.handleFun will always have a new ref value | |
// causes child to re-render on ever BadFunComp render | |
return ( | |
<DisplayCoolness onFun={ () => this.handleFun() } /> |
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
const serviceValues = [ 2, 3, 4 ]; | |
// convert values array into a stream of individual values: Obs[...num] | |
return Observable.of(serviceValues) | |
// call service on each value and get Observable in return: Obs[Obs[newValFromService]] | |
.map(val => serviceApi(val)) | |
// convert stream of observables into a stream of a single array of observables Obs[ [Obs[newVal]] ] | |
.toArray() | |
// trigger all the service calls with maximum concurrenct | |
.switchMap((serviceCalls) => Observable.combineLatest(serviceCalls)) | |
.subscribe(newVals => console.log('new values from server: ', newVals)) // [...{id: 2, ...data}, {id: 3, ...dat}] |
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
function thunkToObservable(thunk) { | |
return (getState, ...args) => { | |
return new Observable(observer => { | |
const dispatchProxy = new Subject(); | |
const dispatch = action => dispatchProxy.next(action); | |
thunk(...args)(dispatch, getState); | |
return dispatchProxy.subscribe(observer); | |
}); | |
}; | |
} |
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
import { ActionsObservable } from 'redux-observale/lib/ActionsObservable'; | |
import rootEpic from './epics'; | |
const flux = new Reactor({ /*...*/ }); | |
const input$ = new Subject(); | |
const actions$ = new ActionsObservable(input$); | |
const epic$ = new Subject(); | |
epic$ |
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
import createTypes from 'redux-create-types'; | |
export const ns = 'app'; | |
export const types = createTypes( | |
[ | |
'openModal', | |
'onClick', | |
'updateEmailSettings', | |
createAsyncTypes('fetch') | |
], |
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
import { Observable } from 'rxjs'; | |
export default function logOutEpic(actions, { getState }) { | |
return Observable | |
.interval(500) | |
.takeUntil(actions.ofType('LOG_OUT').first()) | |
.map(() => { | |
const { app: { accessToken } = {} } = getState(); | |
return accessToken; | |
}) |