Skip to content

Instantly share code, notes, and snippets.

View mvbattan's full-sized avatar

Batu mvbattan

  • Buenos Aires
View GitHub Profile
@mvbattan
mvbattan / reducer.js
Created December 11, 2017 17:39
Complete reducer
const reducerDescription: {
primaryActions: [actions.GET_MATCHES, actions.GET_PITCHES],
override: {
[actions.INCREMENT_COUNTER]: onAdd()
}
}
export default createReducer(initialState, completeReducer(reducerDescription))
@mvbattan
mvbattan / reducer.js
Last active December 14, 2017 13:06
Complete state
const stateDescription = {
matches: [],
pitches: [],
counter: 0
};
const initialState = completeState(stateDescription, ['counter']);
@mvbattan
mvbattan / actions.js
Created December 11, 2017 17:44
complete types
export const actions = createTypes(
completeTypes(['GET_MATCHES', 'GET_PITCHES'], ['INCREMENT_COUNTER']),
'@@SOCCER'
);
@mvbattan
mvbattan / reducer.js
Created December 11, 2017 17:53
Selectors
// if action.payload is like: { matches: [] };
const reducerDescription = {
// This will store the array of matches instead of the whole object comming from payload
[actions.GET_MATCHES_SUCCESS]: onSuccess(action => action.payload.matches)
};
@mvbattan
mvbattan / actions.js
Created December 11, 2017 18:02
Create Thunk Action
import SoccerService from '../services/SoccerService';
export const actions = createTypes(completeTypes['GET_MATCHES','GET_PITCHES'], '@SOCCER');
const actionCreators = {
getMatches: () =>
createThunkAction(actions.GET_MATCHES, 'matches', SoccerService.getMatches),
getPitches: clubId =>
createThunkAction(actions.GET_PITCHES, 'pitches', SoccerService.getPitches, () => clubId)
};
@mvbattan
mvbattan / actions.js
Last active December 14, 2017 13:07
Async with behavior
const actionCreators = {
fetchSomething: () => async dispatch => {
dispatch({ type: actions.FETCH });
const response = Service.fetch();
if (response.ok) {
dispatch({ type: actions.FETCH_SUCCESS, payload: response.data });
dispatch(navigationActions.push('/successRoute');
} else {
dispatch({ type: actions.FETCH_ERROR, payload: response.error });
if (response.status === 404) {
@mvbattan
mvbattan / actions.js
Last active December 19, 2017 23:59
Compose Injections
const actionCreators = {
fetchSomething: () => composeInjections(
baseThunkAction(actions.FETCH, 'fetchTarget', Service.fetch),
withPostSuccess(dispatch => dispatch(navigationActions.push('/successRoute'))),
withStatusHandling({ 404: dispatch => dispatch(navigationActions.push('/failureRoute')) })
)
}
@mvbattan
mvbattan / reducer.js
Created December 11, 2017 21:43
Complete Reducer - before
const reducerDescription: {
[actions.GET_MATCHES]: onLoading(),
[actions.GET_MATCHES_SUCCESS]: onSuccess(),
[actions.GET_MATCHES_FAILURE]: onFailure(),
[actions.GET_PITCHES]: onLoading(),
[actions.GET_PITCHES_SUCCESS]: onSuccess(),
[actions.GET_PITCHES_FAILURE]: onFailure(),
[actions.INCREMENT_COUNTER]: onAdd()
};
@mvbattan
mvbattan / generator.py
Created September 7, 2018 05:15
Ejercicio 3 - Generator
# Taken from https://stackoverflow.com/a/44308018
from scipy.stats import norm, truncnorm
import matplotlib.pyplot as plt
from numpy import array
from math import pi, cos
SAMPLE_SIZE = 200
def get_truncated_normal(mean=0, sd=1, low=0, upp=10):
return truncnorm(
@mvbattan
mvbattan / actions.js
Last active November 29, 2018 13:44
createThunkAction with named params
import SoccerService from '../services/SoccerService';
export const actions = createTypes(completeTypes['GET_MATCHES','GET_PITCHES'], '@SOCCER');
const actionCreators = {
getMatches: () => createThunkAction({
type: actions.GET_MATCHES,
target: 'matches',
service: SoccerService.getMatches
}),