Navigation Menu

Skip to content

Commit

Permalink
combine reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
kanedaki committed Nov 11, 2016
1 parent 1337b67 commit c6b343b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
18 changes: 18 additions & 0 deletions temaFrameworks/combineReducers/combineReducers.js
@@ -0,0 +1,18 @@
const state = {
counter: 0,
session: {
user: 'Miguel',
token: '324324324'
}
}


const counter = require('./counter')
const session = require('./session')

function combineReducers(reducers) {
}

const newReducer = combineReducers({counter, session})
console.log(newReducer)
console.dir(newReducer(state, counter.increment()))
26 changes: 26 additions & 0 deletions temaFrameworks/combineReducers/counter.js
@@ -0,0 +1,26 @@
module.exports = function reducer(state = 0, action) {
switch(action.type) {
case INCREMENT:
return state + 1
case DECREMENT:
return state - 1
default:
state
}
}

const INCREMENT = 'CONTADOR:INCREMENT'
const DECREMENT = 'CONTADOR:DECREMENT'


module.exports.increment = function() {
return {
type: INCREMENT
}
}

module.exports.decrement = function() {
return {
type: DECREMENT
}
}
27 changes: 27 additions & 0 deletions temaFrameworks/combineReducers/session.js
@@ -0,0 +1,27 @@
module.exports = function reducer(state = {}, action) {
switch(action.type) {
case SET_SESSION:
return action.payload
case CLEAR_SESSION:
return {}
default:
return state
}
}

const SET_SESSION = 'SESSION:SET'
const CLEAR_SESSION = 'SESSION:CLEAR'


module.exports.setSession = function(session) {
return {
type: SET_SESSION,
payload: session
}
}

module.exports.clearSession = function clearSession() {
return {
type: CLEAR_SESSION
}
}
2 changes: 1 addition & 1 deletion temaFrameworks/createStore/counter.js
Expand Up @@ -5,7 +5,7 @@ module.exports = function reducer(state = 0, action) {
case DECREMENT:
return state - 1
default:
state
return state
}
}

Expand Down

0 comments on commit c6b343b

Please sign in to comment.