Skip to content

Commit

Permalink
fix: to map
Browse files Browse the repository at this point in the history
  • Loading branch information
zetxx committed Apr 17, 2022
1 parent 67f7f6b commit c2f3a83
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/methods/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const {NotFound} = require('./errors');
*/

module.exports = () => {
const methods = {};
const methods = new Map();
const o = {
add: ({method, fn}) => (
method && fn &&
(methods[method] =
methods.set(method,
(...args) => fn(...args))
),
find: ({direction, packet = {}} = {}) => {
Expand All @@ -22,13 +22,13 @@ module.exports = () => {
} = {}
} = packet;
const method = `${wantedMethod}.${direction}`;
if (!methods[method]) {
if (!methods.has(method)) {
throw NotFound.create(
'method: {wantedMethod} not found',
{wantedMethod}
);
}
return methods[method];
return methods.get(method);
},
call: async({direction, packet}) =>
o.find({direction, packet})(packet)
Expand Down

0 comments on commit c2f3a83

Please sign in to comment.