Skip to content

Commit f421279

Browse files
t47iogilbox
authored andcommitted
Optimize lodash import to reduce bundle size (#24)
* Optimize lodash import in index.js * Optimize lodash import in spark.js
1 parent c193144 commit f421279

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const React = require('react');
22
const ReactDOM = require('react-dom');
3-
const _ = require('lodash');
3+
const _isString = require('lodash/isString');
44
const sparkFactory = require('./spark');
55

66
function factory(options) {
@@ -14,7 +14,7 @@ function factory(options) {
1414
} = spark;
1515

1616
const sparkScrollFactory = defaultComponent => React.createClass({
17-
displayName: 'SparkScroll' + (_.isString(defaultComponent) ? defaultComponent : defaultComponent.displayName),
17+
displayName: 'SparkScroll' + (_isString(defaultComponent) ? defaultComponent : defaultComponent.displayName),
1818

1919
render () {
2020
var Component = this.props.component || defaultComponent;
@@ -47,7 +47,7 @@ function factory(options) {
4747
SparkScroll.div = SparkScroll;
4848

4949
const sparkProxyFactory = defaultComponent => React.createClass({
50-
displayName: 'SparkProxy.' + (_.isString(defaultComponent) ? defaultComponent : defaultComponent.displayName),
50+
displayName: 'SparkProxy.' + (_isString(defaultComponent) ? defaultComponent : defaultComponent.displayName),
5151

5252
render () {
5353
var Component = this.props.component || defaultComponent;

src/spark.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
var assign = require('object-assign');
2-
var _ = require('lodash');
3-
var AnimationFrame = require('animation-frame');
4-
var EventEmitter = require('events').EventEmitter;
1+
const assign = require('object-assign');
2+
const AnimationFrame = require('animation-frame');
3+
const EventEmitter = require('events').EventEmitter;
4+
5+
const _clone = require('lodash/clone');
6+
const _extend = require('lodash/extend');
7+
const _isArray = require('lodash/isArray');
8+
const _isObject = require('lodash/isObject');
59

610
function sparkFactory({animator, formulas, actionProps, setup, invalidateAutomatically}) {
711

@@ -168,7 +172,7 @@ function sparkFactory({animator, formulas, actionProps, setup, invalidateAutomat
168172
if (!data) {
169173
return;
170174
}
171-
data = _.clone(data);
175+
data = _clone(data);
172176

173177
if (allowAnimation) {
174178
actor.removeAllKeyframes();
@@ -184,7 +188,7 @@ function sparkFactory({animator, formulas, actionProps, setup, invalidateAutomat
184188
const containerRect = container.getBoundingClientRect();
185189
for (scrY in data) {
186190
let keyFrame = data[scrY] || {};
187-
keyFrame = _.clone(keyFrame);
191+
keyFrame = _clone(keyFrame);
188192
let actionCount = 0;
189193
c = scrY.charCodeAt(0);
190194

@@ -208,7 +212,7 @@ function sparkFactory({animator, formulas, actionProps, setup, invalidateAutomat
208212
ease = {};
209213
let kfEase = elmEase;
210214
if (keyFrame.ease != null) {
211-
if (_.isObject(keyFrame.ease)) {
215+
if (_isObject(keyFrame.ease)) {
212216
ease = keyFrame.ease;
213217
} else {
214218
kfEase = keyFrame.ease;
@@ -230,12 +234,12 @@ function sparkFactory({animator, formulas, actionProps, setup, invalidateAutomat
230234
actionCount++;
231235
} else {
232236
keyFrame.anims || (keyFrame.anims = {});
233-
if (!_.isArray(v)) {
237+
if (!_isArray(v)) {
234238
v = [v, kfEase];
235239
}
236240
o = {};
237241
o[k] = v[1];
238-
_.extend(ease, o);
242+
_extend(ease, o);
239243
keyFrame.anims[k] = v[0];
240244
delete keyFrame[k];
241245
}

0 commit comments

Comments
 (0)