From cf19fcbfcae40f8da34476ac44529f4db1505226 Mon Sep 17 00:00:00 2001 From: radex Date: Wed, 1 Aug 2018 12:06:08 +0200 Subject: [PATCH] Remove Lodash dependency --- src/KeyboardsRegistry.js | 6 +++--- src/utils/EventEmitterManager.js | 4 +--- src/utils/utils.js | 3 +++ 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 src/utils/utils.js diff --git a/src/KeyboardsRegistry.js b/src/KeyboardsRegistry.js index 939976e..ea4c766 100644 --- a/src/KeyboardsRegistry.js +++ b/src/KeyboardsRegistry.js @@ -1,6 +1,6 @@ import {AppRegistry} from 'react-native'; -import _ from 'lodash'; import EventEmitterManager from './utils/EventEmitterManager'; +import {intersection} from './utils/utils'; /* * Tech debt: how to deal with multiple registries in the app? @@ -20,7 +20,7 @@ export default class KeyboardRegistry { static eventEmitter = new EventEmitterManager(); static registerKeyboard = (componentID, generator, params = {}) => { - if (!_.isFunction(generator)) { + if (typeof generator !== 'function') { console.error(`KeyboardRegistry.registerKeyboard: ${componentID} you must register a generator function`);//eslint-disable-line return; } @@ -38,7 +38,7 @@ export default class KeyboardRegistry { }; static getKeyboards = (componentIDs = []) => { - const validKeyboardIDs = _.intersection(componentIDs, Object.keys(KeyboardRegistry.registeredKeyboards)); + const validKeyboardIDs = intersection(componentIDs, Object.keys(KeyboardRegistry.registeredKeyboards)); return getKeyboardsWithIDs(validKeyboardIDs); }; diff --git a/src/utils/EventEmitterManager.js b/src/utils/EventEmitterManager.js index c6df57d..279d928 100644 --- a/src/utils/EventEmitterManager.js +++ b/src/utils/EventEmitterManager.js @@ -1,5 +1,3 @@ -import _ from 'lodash'; - export default class EventEmitterManager { constructor() { this.handlerCallbacks = {}; @@ -9,7 +7,7 @@ export default class EventEmitterManager { if (!this.handlerCallbacks[eventName]) { this.handlerCallbacks[eventName] = []; } - if (_.indexOf(this.handlerCallbacks[eventName], handlerCallback) === -1) { + if (this.handlerCallbacks[eventName].indexOf(handlerCallback) === -1) { this.handlerCallbacks[eventName].push(handlerCallback); } } diff --git a/src/utils/utils.js b/src/utils/utils.js new file mode 100644 index 0000000..9cff420 --- /dev/null +++ b/src/utils/utils.js @@ -0,0 +1,3 @@ +export function intersection(first, second) { + return first.filter(element => second.indexOf(element) > -1); +}