Skip to content

Instantly share code, notes, and snippets.

@saigowthamr
Created July 7, 2018 12:32
Show Gist options
  • Save saigowthamr/518a66690646b59d776260cb820d26d0 to your computer and use it in GitHub Desktop.
Save saigowthamr/518a66690646b59d776260cb820d26d0 to your computer and use it in GitHub Desktop.
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