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 changeScene = async ( | |
{ store, commands$ }: CommandContext, | |
nextSceneId: number | |
) => { | |
logger.debug(`Changing scene - ${nextSceneId} requested`); | |
const activeScene = getActiveScene(store.getState()); | |
const activeSceneId = getActiveSceneId(store.getState()); | |
if (activeSceneId === nextSceneId) { |
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 React, { Component } from 'react'; | |
import Match from 'react-router/Match'; | |
import { connect } from 'react-redux'; | |
import * as ActionTypes from '../constants/actionTypes'; | |
import buildActionCreators from '../helpers/buildActionCreators'; | |
const EMPTY_PROPS = {}; | |
const createMountableComponent = (Cmp, routeId) => connect( |
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
// main.js | |
import { Subject } from 'rxjs'; | |
import { createStore, compose, applyMiddleware } from 'redux'; | |
import pingPongReducer from './pingPongReducer'; | |
import pingPongEpic from './pingPongEpic'; | |
const buildEpicSubscriber = () => { | |
let subscription = 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
import { select, put, take } from 'redux-saga/effects'; | |
function* emptySaga() {} | |
export function* withConfirmation(text, onConfirm, onCancel = emptySaga) { | |
yield put({ type: 'ShowConfirmationDialog', payload: text }); | |
const { type } = yield take([ | |
'ConfirmationDialogConfirmed', | |
'ConfirmationDialogCanceled' |
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
/// | |
/// <---- rootView.js | |
/// | |
import { view } from 'redux-elm'; | |
import buildRouting from './buildRouting'; | |
export default view(({ history }) => buildRouting(history)); |
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 { createStore, applyMiddleware } from 'redux'; | |
import { Observable, Subject } from 'rxjs'; | |
const api = type => { | |
console.log(`calling API ${type}`); | |
return new Promise(res => setTimeout(() => res(), 500)); | |
}; | |
const actionOrder = (actions, order) => actions.every((action, index) => action.type === order[index]); | |
const actionPredicate = actions => filterableAction => actions.some(action => action === filterableAction.type); |
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 api from './path/to/api' | |
import { take } from 'redux-saga' | |
function* watchSave() { | |
while(true) { | |
const { data } = yield take('SAVE_DATA'); | |
// Just naive example that callbacks do not propagate yield* | |
yield* data | |
.forEach(function*(record) { |
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 { createStore, applyMiddleware } from 'redux'; | |
import { Observable, Subject } from 'rxjs'; | |
const api = (url, fail) => { | |
console.log(`Loading API ${url}`); | |
return new Promise((res, rej) => setTimeout(() => fail ? rej(`data-${url}`) : res('SUCCESS'), 1000)); | |
}; | |
const customSaga = iterable => | |
iterable |
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
// Current Redux way | |
const view = props => ( | |
<div> | |
<button onClick={props.dispatch({type: 'FOO'})}>FooBar</button> | |
<button onClick={props.dispatch({type: 'BAR'})}>FooBar</button> | |
<button onClick={props.dispatch({type: 'BAZ'})}>Baz</button> | |
</div> | |
); | |
const store = createStore(rootReducer); |
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
// You can defer the side-effect execution in middlewares | |
const sideEffect = appState => dispatch => localStorage.setItem('counter', appState); | |
function plainOldReducer(appState) { | |
return appState + 1; | |
} | |
// Composition simply work | |
function nestedReducer*(appState, action) { | |
if (action === FOO) { |
NewerOlder