Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit 6ffa1b0

Browse files
committed
Use lodash debounce and throttle instead of maintaining own debounce
1 parent 6de34ec commit 6ffa1b0

File tree

5 files changed

+14
-65
lines changed

5 files changed

+14
-65
lines changed

lib/common/Pic.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { Component, PropTypes } from 'react';
2+
import throttle from 'lodash/throttle';
3+
import debounce from 'lodash/debounce';
4+
25
import getResponsiveImage from '../utils/getResponsiveImage';
3-
import debounce from '../utils/debounce';
46
import isElementInView from '../utils/isElementInView';
57
import ImageWrapper from '../server/index';
68

@@ -62,8 +64,10 @@ export default class Pic extends Component {
6264
this.setResponsiveImage = this.setResponsiveImage.bind(this);
6365
this.inViewHandler = this.inViewHandler.bind(this);
6466

65-
// calls inViewHandler with a debounce
66-
this.debouncedInViewHandler = debounce(this.inViewHandler.bind(this), 150);
67+
// inViewHandlers
68+
this.inViewHandler = this.inViewHandler.bind(this);
69+
this.debouncedInViewHandler = debounce(this.inViewHandler.bind(this), 300);
70+
this.throttedInViewHandler = throttle(this.inViewHandler.bind(this), 150);
6771
}
6872

6973
componentDidMount() {

lib/utils/debounce.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,8 @@
8484
"browser": {
8585
"./lib/server/index.js": "./lib/client/index.js"
8686
},
87-
"license": "MIT"
87+
"license": "MIT",
88+
"dependencies": {
89+
"lodash": "^4.17.4"
90+
}
8891
}

test/utils.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React from 'react';
33
import { mount, render } from 'enzyme';
44

55
import getResponsiveImage from '../lib/utils/getResponsiveImage';
6-
import debounce from '../lib/utils/debounce';
76
import isElementInView from '../lib/utils/isElementInView';
87
import convertReactToHTMLStyle from '../lib/utils/convertReactToHTMLStyle';
98

@@ -38,26 +37,6 @@ describe('Utils', () => {
3837
});
3938
});
4039

41-
describe('debounce', () => {
42-
it('debounces correctly', (done) => {
43-
let counter = 0;
44-
45-
const increment = () => {
46-
counter += 1;
47-
};
48-
49-
const debouncedIncr = debounce(increment, 15);
50-
51-
debouncedIncr();
52-
debouncedIncr();
53-
54-
setTimeout(() => {
55-
expect(counter).to.equal(1);
56-
done();
57-
}, 100);
58-
});
59-
});
60-
6140
describe('isElementInView', () => {
6241
afterEach(() => {
6342
window.HTMLDivElement.prototype.getBoundingClientRect = () => ({

yarn.lock

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,6 @@ async@^2.1.2, async@^2.1.4:
233233
dependencies:
234234
lodash "^4.14.0"
235235

236-
async@~0.2.6:
237-
version "0.2.10"
238-
resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1"
239-
240236
asynckit@^0.4.0:
241237
version "0.4.0"
242238
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -728,7 +724,7 @@ babel-plugin-transform-strict-mode@^6.22.0:
728724
babel-runtime "^6.22.0"
729725
babel-types "^6.22.0"
730726

731-
babel-polyfill@^6.16.0, babel-polyfill@^6.23.0:
727+
babel-polyfill@^6.16.0:
732728
version "6.23.0"
733729
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.23.0.tgz#8364ca62df8eafb830499f699177466c3b03499d"
734730
dependencies:
@@ -3115,11 +3111,7 @@ lodash.restparam@^3.0.0:
31153111
version "3.6.1"
31163112
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
31173113

3118-
lodash.throttle@^4.1.1:
3119-
version "4.1.1"
3120-
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
3121-
3122-
lodash@^4.0.0, lodash@^4.1.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.2.0, lodash@^4.3.0:
3114+
lodash@^4.0.0, lodash@^4.1.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0:
31233115
version "4.17.4"
31243116
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
31253117

@@ -4639,16 +4631,7 @@ ua-parser-js@^0.7.9:
46394631
version "0.7.12"
46404632
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"
46414633

4642-
uglify-js@^2.6:
4643-
version "2.6.4"
4644-
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.6.4.tgz#65ea2fb3059c9394692f15fed87c2b36c16b9adf"
4645-
dependencies:
4646-
async "~0.2.6"
4647-
source-map "~0.5.1"
4648-
uglify-to-browserify "~1.0.0"
4649-
yargs "~3.10.0"
4650-
4651-
uglify-js@^2.8.5:
4634+
uglify-js@^2.6, uglify-js@^2.8.5:
46524635
version "2.8.22"
46534636
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.22.tgz#d54934778a8da14903fa29a326fb24c0ab51a1a0"
46544637
dependencies:

0 commit comments

Comments
 (0)