Created
July 7, 2018 12:32
-
-
Save saigowthamr/518a66690646b59d776260cb820d26d0 to your computer and use it in GitHub Desktop.
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
import { reducer } from './reducers'; //import your reducer | |
let state; | |
const getState = () => state; | |
const listeners = []; | |
const dispatch = action => { | |
state = reducer(action, state); | |
listeners.forEach(listener => listener()) | |
}; | |
const subscribe = (listener) => { | |
listeners.push(listener) | |
return () => { | |
listeners.filter(lis => lis !== listener) | |
} | |
}; | |
dispatch({}); | |
const reducers = () => reducer; | |
reducers(); //getting the reducers | |
function Async(cb, request) { | |
request(cb); | |
} | |
//helps to do async things | |
const thunk = function(cb, request, delay) { | |
if (delay) { | |
return setTimeout(() => { | |
Async(cb, request); | |
}, delay); | |
} | |
Async(cb, request); | |
}; | |
export { getState, dispatch, thunk,subscribe}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment