From 138d5627b56186d3782472309081b79f2c9c55b8 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Sun, 4 Feb 2018 16:35:57 +0100 Subject: [PATCH] chore(complex-matcher): remove unnecessary invoke --- packages/complex-matcher/src/index.js | 40 ++------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/packages/complex-matcher/src/index.js b/packages/complex-matcher/src/index.js index 20325d549..f2c63f614 100644 --- a/packages/complex-matcher/src/index.js +++ b/packages/complex-matcher/src/index.js @@ -2,43 +2,7 @@ import { isPlainObject, some } from 'lodash' // =================================================================== -// Invoke a function and returns it result. -// All parameters are forwarded. -// -// Why using `invoke()`? -// - avoid tedious IIFE syntax -// - avoid declaring variables in the common scope -// - monkey-patching -// -// ```js -// const sum = invoke(1, 2, (a, b) => a + b) -// -// eventEmitter.emit = invoke(eventEmitter.emit, emit => function (event) { -// if (event === 'foo') { -// throw new Error('event foo is disabled') -// } -// -// return emit.apply(this, arguments) -// }) -// ``` -function invoke (fn) { - const n = arguments.length - 1 - if (!n) { - return fn() - } - - fn = arguments[n] - const args = new Array(n) - for (let i = 0; i < n; ++i) { - args[i] = arguments[i] - } - - return fn.apply(undefined, args) -} - -// =================================================================== - -const RAW_STRING_CHARS = invoke(() => { +const RAW_STRING_CHARS = (() => { const chars = { __proto__: null } const add = (a, b = a) => { let i = a.charCodeAt(0) @@ -55,7 +19,7 @@ const RAW_STRING_CHARS = invoke(() => { add('A', 'Z') add('a', 'z') return chars -}) +})() const isRawString = string => { const { length } = string for (let i = 0; i < length; ++i) {