Skip to content

Instantly share code, notes, and snippets.

@renren89
Created October 31, 2015 10:44
Show Gist options
  • Save renren89/a8d5ed8dc794e26acd24 to your computer and use it in GitHub Desktop.
Save renren89/a8d5ed8dc794e26acd24 to your computer and use it in GitHub Desktop.
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