Created
October 2, 2017 03:14
-
-
Save Calvin-Huang/202e234039698b1ff0376343eaf1a515 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
(function (global, factory) { | |
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | |
typeof define === 'function' && define.amd ? define(['exports'], factory) : | |
(factory((global.middleware = global.middleware || {}))); | |
}(this, (function (exports) { | |
'use strict'; | |
/** | |
* Middleware | |
*/ | |
const middleware = (actionTypes, actions, $) => { | |
return store => next => action => { | |
const returnValue = next(action); | |
const state = store.getState(); | |
switch (action.type) { | |
case actionTypes.FETCH_PUBLIC_REPOS: { | |
$.getJSON(`https://api.github.com/search/repositories?q=language:javascript&per_page=10&page=${action.page}`) | |
.done((data) => { | |
store.dispatch(actions.receivePublicRepos(data.items)); | |
}); | |
break; | |
} | |
case actionTypes.FETCH_REPOS_NEXT_PAGE: { | |
store.dispatch(actions.fetchPublicRepos()); | |
break; | |
} | |
.... | |
} | |
} | |
exports.default = middleware; | |
Object.defineProperty(exports, '__esModule', { value: true }); | |
}))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment