Skip to content

Instantly share code, notes, and snippets.

Paul pablopaul

Block or report user

Report or block pablopaul

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View redux-store-subscribe.js
const unsubscribe = store.subscribe( () => console.log( store.getState() ) );
View redux-store-getstate.js
const state = store.getState();
// Logs 'x'
console.log(state);
View redux-store-dispatch-action.js
store.dispatch(
{
type: 'CHARACTER_TYPED',
char: 'x'
}
);
View redux-store.js
import { createStore } from 'redux';
// reducer is the reducer we defined earlier
const store = createStore(reducer);
View redux-reducer.js
const reducer = (state = '', action) => {
switch (action.type) {
case 'CHARACTER_TYPED':
const { character } = action;
return state + character;
case 'BACKSPACE':
return state.substr(0, state.length - 1);
View redux-reducer-concept-2.js
function (state, action) {
// newState = Processing result of state and action
return newState;
}
View redux-reduder-concept.js
function (a, b) {
// c = Processing result of a and b
return c;
};
View redux-action-creator.js
const insertCharacterActionCreator = (char) => {
return {
type: 'CHARACTER_TYPED',
character: char
}
};
View redux-action-object-2.js
{
type: 'CHARACTER_TYPED',
character: 'x'
}
@pablopaul
pablopaul / action-object-1.js
Last active Nov 21, 2016
Redux Action Object 1
View action-object-1.js
{
type: 'BACKSPACE'
}
You can’t perform that action at this time.