Skip to content

Commit ace9364

Browse files
authored
Merge branch 'master' into feature/passive-event-listeners
2 parents 1a06a94 + 777d63b commit ace9364

File tree

7 files changed

+99
-76
lines changed

7 files changed

+99
-76
lines changed

.eslintrc

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

.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require('fs');
2+
3+
const prettierOptions = JSON.parse(fs.readFileSync('./.prettierrc', 'utf8'));
4+
5+
module.exports = {
6+
extends: ['last', 'prettier', 'prettier/react', 'plugin:react/recommended'],
7+
plugins: ['react', 'prettier'],
8+
globals: {
9+
document: true,
10+
window: true,
11+
describe: true,
12+
it: true,
13+
module: true,
14+
exports: true,
15+
require: true
16+
},
17+
rules: {
18+
'prettier/prettier': ['error', prettierOptions],
19+
'no-unused-vars': [
20+
'off',
21+
{
22+
vars: 'all',
23+
args: 'after-used',
24+
ignoreRestSiblings: false
25+
}
26+
]
27+
}
28+
};

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true
7+
}

dist/InfiniteScroll.js

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
Object.defineProperty(exports, '__esModule', {
4-
value: true,
4+
value: true
55
});
66

77
var _createClass = (function() {
@@ -52,7 +52,7 @@ function _classCallCheck(instance, Constructor) {
5252
function _possibleConstructorReturn(self, call) {
5353
if (!self) {
5454
throw new ReferenceError(
55-
"this hasn't been initialised - super() hasn't been called",
55+
"this hasn't been initialised - super() hasn't been called"
5656
);
5757
}
5858
return call && (typeof call === 'object' || typeof call === 'function')
@@ -64,16 +64,16 @@ function _inherits(subClass, superClass) {
6464
if (typeof superClass !== 'function' && superClass !== null) {
6565
throw new TypeError(
6666
'Super expression must either be null or a function, not ' +
67-
typeof superClass,
67+
typeof superClass
6868
);
6969
}
7070
subClass.prototype = Object.create(superClass && superClass.prototype, {
7171
constructor: {
7272
value: subClass,
7373
enumerable: false,
7474
writable: true,
75-
configurable: true,
76-
},
75+
configurable: true
76+
}
7777
});
7878
if (superClass)
7979
Object.setPrototypeOf
@@ -91,8 +91,8 @@ var InfiniteScroll = (function(_Component) {
9191
this,
9292
(InfiniteScroll.__proto__ || Object.getPrototypeOf(InfiniteScroll)).call(
9393
this,
94-
props,
95-
),
94+
props
95+
)
9696
);
9797

9898
_this.scrollListener = _this.scrollListener.bind(_this);
@@ -108,13 +108,21 @@ var InfiniteScroll = (function(_Component) {
108108
this.pageLoaded = this.props.pageStart;
109109
this.options = this.eventListenerOptions();
110110
this.attachScrollListener();
111-
},
111+
}
112112
},
113113
{
114114
key: 'componentDidUpdate',
115115
value: function componentDidUpdate() {
116+
if (this.props.isReverse && this.loadMore) {
117+
var parentElement = this.getParentElement(this.scrollComponent);
118+
parentElement.scrollTop =
119+
parentElement.scrollHeight -
120+
this.beforeScrollHeight +
121+
this.beforeScrollTop;
122+
this.loadMore = false;
123+
}
116124
this.attachScrollListener();
117-
},
125+
}
118126
},
119127
{
120128
key: 'componentWillUnmount',
@@ -154,15 +162,14 @@ var InfiniteScroll = (function(_Component) {
154162
};
155163
}
156164
return options;
157-
},
158-
165+
}
159166
// Set a defaut loader for all your `InfiniteScroll` components
160167
},
161168
{
162169
key: 'setDefaultLoader',
163170
value: function setDefaultLoader(loader) {
164171
this.defaultLoader = loader;
165-
},
172+
}
166173
},
167174
{
168175
key: 'detachMousewheelListener',
@@ -175,9 +182,9 @@ var InfiniteScroll = (function(_Component) {
175182
scrollEl.removeEventListener(
176183
'mousewheel',
177184
this.mousewheelListener,
178-
this.options ? this.options : this.props.useCapture,
185+
this.options ? this.options : this.props.useCapture
179186
);
180-
},
187+
}
181188
},
182189
{
183190
key: 'detachScrollListener',
@@ -190,14 +197,14 @@ var InfiniteScroll = (function(_Component) {
190197
scrollEl.removeEventListener(
191198
'scroll',
192199
this.scrollListener,
193-
this.options ? this.options : this.props.useCapture,
200+
this.options ? this.options : this.props.useCapture
194201
);
195202
scrollEl.removeEventListener(
196203
'resize',
197204
this.scrollListener,
198-
this.options ? this.options : this.props.useCapture,
205+
this.options ? this.options : this.props.useCapture
199206
);
200-
},
207+
}
201208
},
202209
{
203210
key: 'getParentElement',
@@ -208,13 +215,13 @@ var InfiniteScroll = (function(_Component) {
208215
return scrollParent;
209216
}
210217
return el && el.parentNode;
211-
},
218+
}
212219
},
213220
{
214221
key: 'filterProps',
215222
value: function filterProps(props) {
216223
return props;
217-
},
224+
}
218225
},
219226
{
220227
key: 'attachScrollListener',
@@ -243,13 +250,13 @@ var InfiniteScroll = (function(_Component) {
243250
scrollEl.addEventListener(
244251
'resize',
245252
this.scrollListener,
246-
this.options ? this.options : this.props.useCapture,
253+
this.options ? this.options : this.props.useCapture
247254
);
248255

249256
if (this.props.initialLoad) {
250257
this.scrollListener();
251258
}
252-
},
259+
}
253260
},
254261
{
255262
key: 'mousewheelListener',
@@ -262,7 +269,7 @@ var InfiniteScroll = (function(_Component) {
262269
) {
263270
e.preventDefault();
264271
}
265-
},
272+
}
266273
},
267274
{
268275
key: 'scrollListener',
@@ -300,12 +307,15 @@ var InfiniteScroll = (function(_Component) {
300307
el.offsetParent !== null
301308
) {
302309
this.detachScrollListener();
310+
this.beforeScrollHeight = parentNode.scrollHeight;
311+
this.beforeScrollTop = parentNode.scrollTop;
303312
// Call loadMore after detachScrollListener to allow for non-async loadMore functions
304313
if (typeof this.props.loadMore === 'function') {
305314
this.props.loadMore((this.pageLoaded += 1));
315+
this.loadMore = true;
306316
}
307317
}
308-
},
318+
}
309319
},
310320
{
311321
key: 'calculateOffset',
@@ -318,7 +328,7 @@ var InfiniteScroll = (function(_Component) {
318328
this.calculateTopPosition(el) +
319329
(el.offsetHeight - scrollTop - window.innerHeight)
320330
);
321-
},
331+
}
322332
},
323333
{
324334
key: 'calculateTopPosition',
@@ -327,7 +337,7 @@ var InfiniteScroll = (function(_Component) {
327337
return 0;
328338
}
329339
return el.offsetTop + this.calculateTopPosition(el.offsetParent);
330-
},
340+
}
331341
},
332342
{
333343
key: 'render',
@@ -362,7 +372,7 @@ var InfiniteScroll = (function(_Component) {
362372
'threshold',
363373
'useCapture',
364374
'useWindow',
365-
'getScrollParent',
375+
'getScrollParent'
366376
]);
367377

368378
props.ref = function(node) {
@@ -385,8 +395,8 @@ var InfiniteScroll = (function(_Component) {
385395
}
386396
}
387397
return _react2.default.createElement(element, props, childrenArray);
388-
},
389-
},
398+
}
399+
}
390400
]);
391401

392402
return InfiniteScroll;
@@ -405,8 +415,7 @@ InfiniteScroll.propTypes = {
405415
getScrollParent: _propTypes2.default.func,
406416
threshold: _propTypes2.default.number,
407417
useCapture: _propTypes2.default.bool,
408-
useWindow: _propTypes2.default.bool,
409-
passive: _propTypes2.default.bool,
418+
useWindow: _propTypes2.default.bool
410419
};
411420
InfiniteScroll.defaultProps = {
412421
element: 'div',
@@ -419,8 +428,7 @@ InfiniteScroll.defaultProps = {
419428
isReverse: false,
420429
useCapture: false,
421430
loader: null,
422-
getScrollParent: null,
423-
passive: false,
431+
getScrollParent: null
424432
};
425433
exports.default = InfiniteScroll;
426434
module.exports = exports['default'];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-infinite-scroller",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Infinite scroll component for React in ES6",
55
"main": "index.js",
66
"jsnext:main": "src/InfiniteScroll.js",

0 commit comments

Comments
 (0)