Created
October 31, 2015 10:44
-
-
Save renren89/a8d5ed8dc794e26acd24 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var x = /\s/g; | |
var y = /(.{4})/g; | |
const initialState = { | |
number: '' | |
} | |
//console.log(initialState) | |
function reducer(state = initialState, action) { | |
console.log("current state is ", state, "current action is ", action); | |
switch(action.type) { | |
case PROCESS_NUMBER: | |
return { | |
...state, | |
number: action.payload.replace(x, '').replace(y, '$1 ') | |
} | |
console.log("this is the current state", state) | |
default: | |
return state; | |
} | |
} | |
const PROCESS_NUMBER = 'PROCESS_NUMBER'; | |
function processAction(payload) { | |
return {type: PROCESS_NUMBER, payload} | |
} | |
//console.log(reducer(null, processAction("9999999999999") )) | |
reducer(null, processAction("4555555")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment