Created
November 14, 2016 12:21
-
-
Save a-eid/9079cf76e6ce458fcfb02a53b64b61a6 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
const createStore = (retucer) => { | |
let state | |
let listeners = [] | |
const getState = ()=> state | |
const dispatch = (action)=>{ | |
state = reducer(state , action) | |
listeners.forEach((listener) => listener() ) | |
} | |
const subscribe = (listener)=>{ | |
listeners.push(listener); | |
return ()=>{ | |
listeners.filter( (l)=> listener != l ) | |
} | |
} | |
state = dispatch({}) | |
return { | |
getState , dispatch , subscribe | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment