Skip to content

Commit 2f353e0

Browse files
author
Vesa Piittinen
committed
Use @researchgate/react-intersection-observer; version 1.0.3
1 parent 5596cdf commit 2f353e0

18 files changed

+112
-697
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
## [1.0.3] - 2018-06-13
9+
10+
### Changed
11+
- Now uses `@researchgate/react-intersection-observer` instead of customized implementation
12+
13+
### Fixed
14+
- Case where `viewport` and `threshold` were not passed to `Observer` in `Lazy`
15+
16+
817
## [1.0.2] - 2018-05-31
918

1019
### Changed

README.md

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
> Lazy load your content without breaking the internet!
66
77
Supports universal rendering including disabled JavaScript by using `noscript` elements that are also friendly to all
8-
search engines. Uses modern IntersectionObserver API and exposes `Observer` component which works exactly like the
9-
excellent [@researchgate/react-intersection-observer](https://github.com/researchgate/react-intersection-observer), but
10-
with a few minor changes.
8+
search engines. Uses modern IntersectionObserver API using the excellent
9+
[@researchgate/react-intersection-observer](https://github.com/researchgate/react-intersection-observer).
1110

1211
Also optionally supports displaying the content on IE8 and earlier by adding conditional comments to skip `noscript`
1312
elements.
@@ -20,22 +19,20 @@ npm install react-lazy
2019
import { Lazy } from 'react-lazy'
2120
// or
2221
import { LazyGroup } from 'react-lazy'
23-
// or
24-
import { Observer } from 'react-lazy'
2522
```
2623

2724
You also need to polyfill `intersection-observer`! Use polyfill.io or `require('intersection-observer')`. Check
28-
[Can I use](https://caniuse.com/#feat=intersectionobserver) for browser support status. Additionally features like `Map`
29-
and `Set` are also required.
25+
[Can I use](https://caniuse.com/#feat=intersectionobserver) for browser support status. `Map` and `Set` are also
26+
required, but these are required by React as well.
3027

3128

3229
----
3330

3431
## Why `react-lazy`?
3532

3633
1. Minimalistic and performant implementation with less dependencies than other solutions
37-
2. You can choose between ease-of-use (LazyGroup) and do-it-yourself (Lazy, Observer)
38-
3. The hard part of handling `noscript` is done for you (Lazy, LazyGroup)
34+
2. You can choose between ease-of-use (LazyGroup) and do-it-yourself (Lazy)
35+
3. The hard part of handling `noscript` is done for you
3936

4037

4138
----
@@ -92,21 +89,7 @@ import { Lazy } from 'react-lazy'
9289

9390
## Component introduction
9491

95-
First of all, `Observer` component is exposed. This is a powerful component for using the new IntersectionObserver API.
96-
The notable differences to the implementation of
97-
[@researchgate/react-intersection-observer](https://github.com/researchgate/react-intersection-observer) are:
98-
99-
- `viewport` prop is added and preferred over `root` prop
100-
- `cushion` prop is added and preferred over `rootMargin` prop
101-
- `onlyOnce` prop deprecation has been enforced and is unsupported
102-
- Other changes are internal code optimizations for further minor speed improvements and reduced code size
103-
104-
Essentially `react-lazy`'s implementation of `<Observer />` is fully compatible with all the examples and demos you find
105-
at [@researchgate/react-intersection-observer](https://github.com/researchgate/react-intersection-observer). (This part
106-
of the text holds true in 2018-05-30 at version 0.7.1 - throw issue if this state changes).
107-
108-
109-
As for lazy loading there are two components: `<Lazy />` and `<LazyGroup />`.
92+
There are two components: `<Lazy />` and `<LazyGroup />`.
11093

11194
**Lazy** provides basic functionality for lazy loading: it keeps render in `noscript` element until it has come into
11295
viewport and then simply swaps render. **Everything** inside the component is wrapped into `noscript`. As the component

dist/module/components/Lazy.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ var _propTypes = require('prop-types');
1414

1515
var _propTypes2 = _interopRequireDefault(_propTypes);
1616

17-
var _Observer = require('./Observer');
17+
var _reactIntersectionObserver = require('@researchgate/react-intersection-observer');
1818

19-
var _Observer2 = _interopRequireDefault(_Observer);
19+
var _reactIntersectionObserver2 = _interopRequireDefault(_reactIntersectionObserver);
2020

2121
var _wrap = require('../lib/wrap');
2222

@@ -87,16 +87,16 @@ var Lazy = function (_React$PureComponent) {
8787

8888
if (clientOnly || visible && this.state.show) {
8989
return _react2.default.createElement(
90-
_Observer2.default,
91-
{ cushion: cushion, onChange: this.onViewport, threshold: threshold, viewport: viewport },
90+
_reactIntersectionObserver2.default,
91+
{ onChange: this.onViewport, root: viewport, rootMargin: cushion, threshold: threshold },
9292
_react2.default.createElement(component, props, visible && this.state.show ? children : null)
9393
);
9494
}
9595

9696
// wrap all contents inside noscript
9797
return _react2.default.createElement(
98-
_Observer2.default,
99-
{ cushion: cushion, onChange: this.onViewport },
98+
_reactIntersectionObserver2.default,
99+
{ onChange: this.onViewport, root: viewport, rootMargin: cushion, threshold: threshold },
100100
_react2.default.createElement(component, (0, _wrap.propsWithNoScriptRender)(children, ltIE9, props))
101101
);
102102
}

dist/module/components/LazyGroup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var _DefaultWrapper = require('./DefaultWrapper');
2020

2121
var _DefaultWrapper2 = _interopRequireDefault(_DefaultWrapper);
2222

23-
var _Observer = require('./Observer');
23+
var _reactIntersectionObserver = require('@researchgate/react-intersection-observer');
2424

25-
var _Observer2 = _interopRequireDefault(_Observer);
25+
var _reactIntersectionObserver2 = _interopRequireDefault(_reactIntersectionObserver);
2626

2727
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2828

@@ -108,8 +108,8 @@ var LazyGroup = function (_React$PureComponent) {
108108
props = _objectWithoutProperties(_props2, ['children', 'childrenToWrap', 'childWrapper', 'clientOnly', 'component', 'cushion', 'ltIE9', 'onLoad', 'onViewport', 'threshold', 'viewport', 'visible']);
109109

110110
return _react2.default.createElement(
111-
_Observer2.default,
112-
{ cushion: cushion, onChange: this.onViewport, threshold: threshold, viewport: viewport },
111+
_reactIntersectionObserver2.default,
112+
{ onChange: this.onViewport, root: viewport, rootMargin: cushion, threshold: threshold },
113113
_react2.default.createElement(component, props,
114114
// swap render once element is visible in viewport
115115
clientOnly || visible && this.state.viewportAt

dist/module/components/Observer.js

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

dist/module/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
exports.Observer = exports.Lazy = exports.LazyGroup = undefined;
6+
exports.Lazy = exports.LazyGroup = undefined;
77

88
var _LazyGroup2 = require('./components/LazyGroup');
99

@@ -13,12 +13,7 @@ var _Lazy2 = require('./components/Lazy');
1313

1414
var _Lazy3 = _interopRequireDefault(_Lazy2);
1515

16-
var _Observer2 = require('./components/Observer');
17-
18-
var _Observer3 = _interopRequireDefault(_Observer2);
19-
2016
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2117

2218
exports.LazyGroup = _LazyGroup3.default;
23-
exports.Lazy = _Lazy3.default;
24-
exports.Observer = _Observer3.default;
19+
exports.Lazy = _Lazy3.default;

0 commit comments

Comments
 (0)