Skip to content

Commit

Permalink
WHAT: using proxy
Browse files Browse the repository at this point in the history
WHY:

* XXXXX

HOW:

* NOTHING TO SAY
  • Loading branch information
ecmadao committed Jun 25, 2018
1 parent 28798c7 commit ea10912
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"comma-dangle": 0,
"no-underscore-dangle": 0,
"no-multi-spaces": 0,
"arrow-body-style": 0,
"no-param-reassign": ["error", { "props": false }],
"react/jsx-equals-spacing": 0,
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
Expand Down
33 changes: 12 additions & 21 deletions app/utils/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,16 @@ const fetch = async (options, timeouts = [2000]) => {
}
};

export default {
get: (options, timeouts) => {
options.method = 'GET';
return fetch(options, timeouts);
},
post: (options, timeouts) => {
options.method = 'POST';
return fetch(options, timeouts);
},
put: (options, timeouts) => {
options.method = 'PUT';
return fetch(options, timeouts);
},
delete: (options, timeouts) => {
options.method = 'DELETE';
return fetch(options, timeouts);
},
patch: (options, timeouts) => {
options.method = 'PATCH';
return fetch(options, timeouts);
},
const handler = {
get: (target, method) => {
return (...args) => {
const [options, timeouts] = args;
options.method = method.toUpperCase();
return fetch(options, timeouts);
};
}
};

const proxy = new Proxy({}, handler);
export default proxy;

0 comments on commit ea10912

Please sign in to comment.