Skip to content

Commit df65082

Browse files
Merge branch 'release/2.1.0'
2 parents a7b9b7d + 161d150 commit df65082

File tree

10 files changed

+131
-31
lines changed

10 files changed

+131
-31
lines changed

.babelrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
2-
"plugins": ["transform-object-rest-spread"],
3-
"presets": ["es2015", "react"],
2+
"presets": ["@babel/preset-env", "@babel/preset-react"],
43

54
"env": {
65
"test": {
76
"plugins": [
8-
["istanbul", { "exclude": ["**/*.spec.js"] }]
7+
["istanbul", { "exclude": ["**/*.spec.js", "src/helpers/throttle.js"] }]
98
]
109
}
1110
}

.browserslistrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
last 1 version
2+
not dead
3+
> 0.2%

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.publishrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"validations": {
3-
"vulnerableDependencies": true,
3+
"vulnerableDependencies": false,
44
"uncommittedChanges": true,
55
"untrackedFiles": true,
66
"sensitiveData": true,

karma-ci.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
2-
require('babel-register');
2+
require('@babel/register');
33

44
module.exports = require('./karma-ci.conf.babel').default;

karma-common.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = (
2929
resolve: {
3030
alias: {
3131
'react/addons': `${__dirname}/node_modules/react/dist/react-with-addons.js`,
32+
sinon$: `${__dirname}/node_modules/sinon/lib/sinon.js`,
3233
},
3334
},
3435

@@ -38,7 +39,6 @@ module.exports = (
3839
test: /\.js$/,
3940
include: [
4041
`${__dirname}/src/`,
41-
`${__dirname}/node_modules/sinon/`,
4242
],
4343
use: {
4444
loader: 'babel-loader',

karma-local.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
2-
require('babel-register');
2+
require('@babel/register');
33

44
module.exports = require('./karma-local.conf.babel').default;

package.json

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-responsive-breakpoints",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "A higher-order React component to translate CSS breakpoints into properties",
55
"main": "lib/index.js",
66
"files": [
@@ -30,51 +30,45 @@
3030
"url": "https://github.com/wimpyprogrammer/react-responsive-breakpoints/issues"
3131
},
3232
"homepage": "https://github.com/wimpyprogrammer/react-responsive-breakpoints#readme",
33-
"dependencies": {
34-
"lodash.noop": "^3.0.1",
35-
"lodash.reduce": "^4.6.0",
36-
"lodash.throttle": "^4.1.1"
37-
},
3833
"devDependencies": {
34+
"@babel/cli": "^7.2.3",
35+
"@babel/core": "^7.2.2",
36+
"@babel/preset-env": "^7.2.0",
37+
"@babel/preset-react": "^7.0.0",
38+
"@babel/register": "^7.0.0",
3939
"airbnb-js-shims": "^2.1.0",
40-
"babel-cli": "^6.26.0",
41-
"babel-core": "^6.0.0",
42-
"babel-loader": "^7.1.2",
40+
"babel-loader": "^8.0.4",
4341
"babel-plugin-istanbul": "^4.1.5",
44-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
45-
"babel-preset-es2015": "^6.24.1",
46-
"babel-preset-react": "^6.24.1",
47-
"babel-register": "^6.26.0",
4842
"chai": "^4.1.2",
4943
"codecov": "^3.0.1",
5044
"cross-env": "^5.0.5",
5145
"dirty-chai": "^2.0.1",
52-
"enzyme": "^3.5.0",
53-
"enzyme-adapter-react-16": "^1.3.0",
54-
"enzyme-adapter-react-helper": "^1.3.0",
46+
"enzyme": "^3.8.0",
47+
"enzyme-adapter-react-16": "^1.7.1",
48+
"enzyme-adapter-react-helper": "^1.3.1",
5549
"eslint": "^5.3.0",
5650
"eslint-config-airbnb": "^17.1.0",
5751
"eslint-plugin-import": "^2.14.0",
5852
"eslint-plugin-jsx-a11y": "^6.1.1",
5953
"eslint-plugin-react": "^7.11.1",
60-
"karma": "^3.0.0",
54+
"karma": "^3.1.4",
6155
"karma-coverage": "^1.1.1",
6256
"karma-mocha": "^1.3.0",
6357
"karma-mocha-reporter": "^2.2.4",
6458
"karma-sauce-launcher": "^1.2.0",
6559
"karma-viewport": "^1.0.0",
66-
"karma-webpack": "^3.0.0",
60+
"karma-webpack": "^3.0.5",
6761
"lodash.merge": "^4.6.0",
6862
"lodash.once": "^4.1.1",
6963
"mocha": "^5.0.0",
70-
"publish-please": "^3.2.0",
64+
"publish-please": "^5.4.3",
7165
"react": "*",
7266
"react-dom": "*",
7367
"react-test-renderer": "*",
7468
"rimraf": "^2.6.2",
7569
"sinon": "^6.0.1",
7670
"sinon-chai": "^3.2.0",
77-
"webpack": "^4.16.5"
71+
"webpack": "^4.27.1"
7872
},
7973
"peerDependencies": {
8074
"react": "*"

src/helpers/throttle.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// A stripped-down version of lodash throttle from
2+
// https://github.com/lodash/lodash/blob/0843bd4/lodash.js#L10898-L10914
3+
4+
export default function throttle(func, wait) {
5+
let lastArgs;
6+
let lastThis;
7+
let result;
8+
let timerId;
9+
let lastCallTime;
10+
11+
function invokeFunc() {
12+
const args = lastArgs;
13+
const thisArg = lastThis;
14+
15+
lastArgs = undefined;
16+
lastThis = undefined;
17+
result = func.apply(thisArg, args);
18+
return result;
19+
}
20+
21+
function trailingEdge() {
22+
timerId = undefined;
23+
24+
// Only invoke if we have `lastArgs` which means `func` has been
25+
// debounced at least once.
26+
if (lastArgs) {
27+
return invokeFunc();
28+
}
29+
lastArgs = undefined;
30+
lastThis = undefined;
31+
return result;
32+
}
33+
34+
function shouldInvoke(time) {
35+
const timeSinceLastCall = time - lastCallTime;
36+
37+
// Either this is the first call, activity has stopped and we're at the
38+
// trailing edge, the system time has gone backwards and we're treating
39+
// it as the trailing edge, or we've hit the `maxWait` limit.
40+
return (lastCallTime === undefined
41+
|| (timeSinceLastCall >= wait)
42+
|| (timeSinceLastCall < 0));
43+
}
44+
45+
function remainingWait(time) {
46+
const timeSinceLastCall = time - lastCallTime;
47+
const timeWaiting = wait - timeSinceLastCall;
48+
49+
return timeWaiting;
50+
}
51+
52+
// eslint-disable-next-line consistent-return
53+
function timerExpired() {
54+
const time = Date.now();
55+
if (shouldInvoke(time)) {
56+
return trailingEdge();
57+
}
58+
// Restart the timer.
59+
timerId = setTimeout(timerExpired, remainingWait(time));
60+
}
61+
62+
function leadingEdge() {
63+
// Reset any `maxWait` timer.
64+
// Start the timer for the trailing edge.
65+
timerId = setTimeout(timerExpired, wait);
66+
// Invoke the leading edge.
67+
return invokeFunc();
68+
}
69+
70+
function cancel() {
71+
if (timerId !== undefined) {
72+
clearTimeout(timerId);
73+
}
74+
lastArgs = undefined;
75+
lastCallTime = undefined;
76+
lastThis = undefined;
77+
timerId = undefined;
78+
}
79+
80+
function debounced() {
81+
const time = Date.now();
82+
const isInvoking = shouldInvoke(time);
83+
84+
// eslint-disable-next-line prefer-rest-params
85+
lastArgs = arguments;
86+
lastThis = this;
87+
lastCallTime = time;
88+
89+
if (isInvoking) {
90+
if (timerId === undefined) {
91+
return leadingEdge();
92+
}
93+
}
94+
if (timerId === undefined) {
95+
timerId = setTimeout(timerExpired, wait);
96+
}
97+
return result;
98+
}
99+
debounced.cancel = cancel;
100+
return debounced;
101+
}

src/withBreakpointsCustom.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/* eslint-env browser */
22
import React, { Component } from 'react';
3-
import noop from 'lodash.noop';
4-
import reduce from 'lodash.reduce';
5-
import throttle from 'lodash.throttle';
3+
import throttle from './helpers/throttle';
4+
5+
function noop() {}
66

77
function isVisible(markerEl) {
88
return !!markerEl && window.getComputedStyle(markerEl).display !== 'none';
99
}
1010

1111
export default (options, InnerComponent) => {
1212
function calculateBreakpoints() {
13-
return reduce(options.breakpoints, (breakpoints, { prop, selector }) => {
13+
const breakpointConfig = options.breakpoints || [];
14+
15+
return breakpointConfig.reduce((breakpoints, { prop, selector }) => {
1416
const markerEl = document.querySelector(selector);
1517
return { ...breakpoints, [prop]: isVisible(markerEl) };
1618
}, {});

0 commit comments

Comments
 (0)