Skip to content

Instantly share code, notes, and snippets.

@iAmShakil
Last active August 31, 2018 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iAmShakil/3d04dc48beed3f66cc5a75b79ba4b6cc to your computer and use it in GitHub Desktop.
Save iAmShakil/3d04dc48beed3f66cc5a75b79ba4b6cc to your computer and use it in GitHub Desktop.
const reducer = ( state = 0, action ) => {
switch(action.type){
case "INCREMENT":
return state + 1
case "DECREMENT":
return state - 1
default:
return state
}
}
// when createStore is called with a reducer function, it returns 4 methods. We will just create the empty methods now as a first.
function createStore(reducer){
function getState(){
}
function dispatch(){
}
function subscribe(){
// invoking this returned function will remove the subscriber function
return function(){
}
}
return {
getState: getState,
dispatch: dispatch,
subscribe: subscribe,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment