Skip to content

Commit 283c157

Browse files
authored
Remove lodash in favour of ES6 syntax and lodash.* dependencies (greena13#73)
* Remove lodash in favour of ES6 syntax and lodash.* dependencies * Update lodash reference in example
1 parent e5c66ec commit 283c157

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

examples/master/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {HotKeys, HotKeyMapMixin} from 'react-hotkeys';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
4-
import rand from 'lodash/number/random';
4+
import rand from 'lodash.random';
55

66
const DEFAULT_NODE_SIZE = 100;
77
const SIZE_INCREMENT = 5;

lib/HotKeyMapMixin.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3-
import assign from 'lodash/assign';
4-
import isEqual from 'lodash/isEqual';
3+
import isEqual from 'lodash.isequal';
54

65
export default function HotKeyMapMixin(hotKeyMap = {}) {
76

@@ -40,7 +39,7 @@ export default function HotKeyMapMixin(hotKeyMap = {}) {
4039
const parentMap = this.context.hotKeyMap || {};
4140
const thisMap = this.props.keyMap || {};
4241

43-
return assign({}, parentMap, hotKeyMap, thisMap);
42+
return {...parentMap, ...hotKeyMap, ...thisMap};
4443
},
4544

4645
getMap() {

lib/HotKeys.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import createReactClass from 'create-react-class';
44
import ReactDOM from 'react-dom';
55
import FocusTrap from './FocusTrap';
66
import HotKeyMapMixin from './HotKeyMapMixin';
7-
import isBool from 'lodash/isBoolean';
8-
import isArray from 'lodash/isArray';
9-
import isObject from 'lodash/isObject';
10-
import forEach from 'lodash/forEach';
11-
import isEqual from 'lodash/isEqual';
7+
8+
import isBool from 'lodash.isboolean';
9+
import isObject from 'lodash.isobject';
10+
import isEqual from 'lodash.isequal';
1211

1312
function getSequencesFromMap(hotKeyMap, hotKeyName) {
1413
const sequences = hotKeyMap[hotKeyName];
@@ -19,7 +18,7 @@ function getSequencesFromMap(hotKeyMap, hotKeyName) {
1918
return [hotKeyName];
2019
}
2120

22-
if (isArray(sequences)) {
21+
if (Array.isArray(sequences)) {
2322
return sequences;
2423
}
2524

@@ -96,12 +95,14 @@ const HotKeys = createReactClass({
9695
const mousetrap = this.__mousetrap__;
9796

9897
// Group all our handlers by sequence
99-
forEach(handlers, (handler, hotKey) => {
98+
Object.keys(handlers).forEach((hotKey) => {
99+
const handler = handlers[hotKey];
100+
100101
const handlerSequences = getSequencesFromMap(hotKeyMap, hotKey);
101102

102103
// Could be optimized as every handler will get called across every bound
103104
// component - imagine making a node a focus point and then having hundreds!
104-
forEach(handlerSequences, (sequence) => {
105+
handlerSequences.forEach((sequence) => {
105106
let action;
106107

107108
const callback = (event, sequence) => {
@@ -130,7 +131,7 @@ const HotKeys = createReactClass({
130131

131132
// Hard reset our handlers (probably could be more efficient)
132133
mousetrap.reset();
133-
forEach(sequenceHandlers, (handler) =>
134+
sequenceHandlers.forEach((handler) =>
134135
mousetrap.bind(handler.sequence, handler.callback, handler.action));
135136
},
136137

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
"chai-enzyme": "^1.0.0-beta.0",
2121
"cheerio": "^1.0.0-0",
2222
"css-loader": "^0.9.1",
23+
"enzyme": "^3.0.0",
2324
"enzyme-adapter-react-14": "^1.0.3",
2425
"eslint": "^1.10.3",
2526
"eslint-plugin-react": "^3.16.1",
2627
"estraverse": "^4.2.0",
2728
"jsdom": "^11.3.0",
2829
"jsdom-global": "^3.0.2",
30+
"lodash.random": "^3.2.0",
2931
"mocha": "^2.4.5",
3032
"prompt": "^0.2.14",
3133
"react": "^0.14.0",
@@ -39,8 +41,9 @@
3941
},
4042
"dependencies": {
4143
"create-react-class": "^15.5.2",
42-
"enzyme": "^3.0.0",
43-
"lodash": "^4.13.1",
44+
"lodash.isboolean": "^3.0.3",
45+
"lodash.isequal": "^4.5.0",
46+
"lodash.isobject": "^3.0.2",
4447
"mousetrap": "^1.5.2",
4548
"prop-types": "^15.5.8"
4649
},

yarn.lock

+16
Original file line numberDiff line numberDiff line change
@@ -2597,6 +2597,18 @@ lodash.isarray@^3.0.0:
25972597
version "3.0.4"
25982598
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"
25992599

2600+
lodash.isboolean@^3.0.3:
2601+
version "3.0.3"
2602+
resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6"
2603+
2604+
lodash.isequal@^4.5.0:
2605+
version "4.5.0"
2606+
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
2607+
2608+
lodash.isobject@^3.0.2:
2609+
version "3.0.2"
2610+
resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-3.0.2.tgz#3c8fb8d5b5bf4bf90ae06e14f2a530a4ed935e1d"
2611+
26002612
lodash.isplainobject@^3.0.0:
26012613
version "3.2.0"
26022614
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-3.2.0.tgz#9a8238ae16b200432960cd7346512d0123fbf4c5"
@@ -2657,6 +2669,10 @@ lodash.pickby@^4.0.0:
26572669
version "4.6.0"
26582670
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff"
26592671

2672+
lodash.random@^3.2.0:
2673+
version "3.2.0"
2674+
resolved "https://registry.yarnpkg.com/lodash.random/-/lodash.random-3.2.0.tgz#96e24e763333199130d2c9e2fd57f91703cc262d"
2675+
26602676
lodash.restparam@^3.0.0:
26612677
version "3.6.1"
26622678
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"

0 commit comments

Comments
 (0)