Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
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