Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. function generateActionNames(namespace, baseUrl) {
  2. const stages = ["REQUEST", "SUCCESS", "FAILURE"];
  3. const methods = ["GET", "ADD", "UPDATE", "DELETE"];
  4. const actionNames = doMagic(namespace, methods, method =>
  5. doMagic(method, stages, stage => stage)
  6. );
  7. return actionNames;
  8. }
  9.  
  10. function doMagic(prefix, keys, makeValue) {
  11. return keys.reduce(
  12. (result, key) => ({
  13. ...result,
  14. [key.toLowerCase()]: makeValue(`${prefix}_${key}`)
  15. }),
  16. {}
  17. );
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement