lazy-react 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/demo.js +39 -56
- package/demo/index.js +218 -29
- package/demo/index.js.LICENSE.txt +32 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -8
- package/src/baseClass.js +65 -61
- package/src/lazyLoadBackgroundImage.js +16 -31
- package/src/lazyLoadComponent.js +20 -28
- package/src/lazyLoadFrame.js +17 -33
- package/src/lazyLoadImage.js +14 -31
- package/webpack.config.demo.js +1 -1
- package/src/indexSingleFile.js +0 -75
package/src/indexSingleFile.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
//this file it's here just for reference on how build size differs with webpack and babel when there is one or more files involved
|
|
2
|
-
|
|
3
|
-
import React from 'react' // eslint-disable-line no-unused-vars
|
|
4
|
-
import ReactDom from 'react-dom'
|
|
5
|
-
|
|
6
|
-
class CheckIfRender extends React.Component {
|
|
7
|
-
constructor(props) {
|
|
8
|
-
super(props)
|
|
9
|
-
this.state = {
|
|
10
|
-
link: ''
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
listener() {
|
|
14
|
-
if (window.scrollY + window.innerWidth + 100 > this.state.top) {
|
|
15
|
-
this.setState({ link: this.props.link })
|
|
16
|
-
this.removeListener()
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
removeListener() {
|
|
20
|
-
window.removeEventListener('scroll', this.listener)
|
|
21
|
-
}
|
|
22
|
-
componentDidMount() {
|
|
23
|
-
const element = ReactDom.findDOMNode(this)
|
|
24
|
-
const { top } = element.getBoundingClientRect()
|
|
25
|
-
this.setState({ top })
|
|
26
|
-
window.addEventListener('scroll', this.listener)
|
|
27
|
-
}
|
|
28
|
-
componentWillUnmount() {
|
|
29
|
-
this.removeListener()
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
class LazyFrame extends CheckIfRender {
|
|
34
|
-
constructor(props) {
|
|
35
|
-
super(props)
|
|
36
|
-
}
|
|
37
|
-
render() {
|
|
38
|
-
return (
|
|
39
|
-
<iframe
|
|
40
|
-
height={this.props.height || '500'}
|
|
41
|
-
scrolling={this.props.scrolling || 'no'}
|
|
42
|
-
src={this.state.link}
|
|
43
|
-
frameBorder={this.props.frameBorder || 'no'}
|
|
44
|
-
allowTransparency={this.props.allowTransparency || 'true'}
|
|
45
|
-
allowFullScreen={this.props.allowFullScreen || 'true'}
|
|
46
|
-
style={this.props.style || { width: '100%' }}
|
|
47
|
-
/>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
class LazyBackgroundImage extends CheckIfRender {
|
|
53
|
-
constructor(props) {
|
|
54
|
-
super(props)
|
|
55
|
-
}
|
|
56
|
-
render() {
|
|
57
|
-
return (
|
|
58
|
-
<div
|
|
59
|
-
className={this.props.className}
|
|
60
|
-
style={{ backgroundImage: `url(${this.state.link})` }}
|
|
61
|
-
/>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
class LazyImage extends CheckIfRender {
|
|
67
|
-
constructor(props) {
|
|
68
|
-
super(props)
|
|
69
|
-
}
|
|
70
|
-
render() {
|
|
71
|
-
return <img src={this.state.link} alt={this.props.alt} />
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { LazyBackgroundImage, LazyImage, LazyFrame }
|