Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#164 Replace lodash by custom deepEqual to reduce bundle size #167

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"not op_mini all"
],
"dependencies": {
"lodash.isequal": "^4.5.0",
"prop-types": "^15.6.0",
"swipe-js-iso": "^2.1.5"
},
Expand Down
29 changes: 29 additions & 0 deletions src/deepEqual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default function deepEqual(a, b) {
if (a === b) {
return true;
}

if (
a === null ||
typeof a !== 'object' ||
b === null ||
typeof b !== 'object'
) {
return false;
}

let keysA = Object.keys(a),
keysB = Object.keys(b);

if (keysA.length !== keysB.length) {
return false;
}

for (let key of keysA) {
if (!keysB.includes(key) || !deepEqual(a[key], b[key])) {
return false;
}
}

return true;
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import Swipe from 'swipe-js-iso';
import isEqual from 'lodash.isequal';
import deepEqual from './deepEqual';

class ReactSwipe extends Component {
static propTypes = {
Expand Down Expand Up @@ -57,7 +57,7 @@ class ReactSwipe extends Component {
const { childCount, swipeOptions } = this.props;
const shouldUpdateSwipeInstance =
prevProps.childCount !== childCount ||
!isEqual(prevProps.swipeOptions, swipeOptions);
!deepEqual(prevProps.swipeOptions, swipeOptions);

if (shouldUpdateSwipeInstance) {
this.swipe.kill();
Expand Down