Skip to content

Commit 83cac37

Browse files
authored
feat(LazyLoad): Eager Load Images (#57)
1 parent 4ac2f42 commit 83cac37

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ import { LazyCollection } from '@quintype/components'
209209

210210
This component will ensure all [ResponsiveImages](#ResponsiveImage) that are in its descendent path will be loaded async. By default, the image is loaded with an empty gif, and the image becomes visible when the image scrolls 250 from the edge of the screen.
211211

212-
You can use `eager={true}` to force the image to be eager
212+
You can use `EagerLoadImages` or `eager={true}` to force the image to be eager.
213213

214214
```javascript
215-
import { LazyLoadImages } from '@quintype/components';
215+
import { LazyLoadImages, EagerLoadImages } from '@quintype/components';
216216

217217
function LazyLoadSecondImage() {
218218
return <div>
@@ -223,6 +223,9 @@ function LazyLoadSecondImage() {
223223
<ResponsiveImage slug={props["lazy-image-1"]} />
224224
<ResponsiveImage slug={props["lazy-image-forced-to-be-eager"]} eager={true}/>
225225
<ResponsiveImage slug={props["lazy-image-2"]} />
226+
<EagerLoadImages>
227+
<ResponsiveImage slug={props["lazy-image-forced-to-be-eager"]} />
228+
</EagerLoadImages>
226229
</div>
227230
</LazyLoadImages>
228231
<ResponsiveImage slug={props["eager-image-2"]} />

src/components/lazy-load-images.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,20 @@ export class LazyLoadImages extends React.Component {
109109
}
110110
}
111111

112-
LazyLoadImages.childContextTypes = {
112+
export class EagerLoadImages extends React.Component {
113+
getChildContext() {
114+
return {
115+
lazyLoadObserveImage: null,
116+
lazyLoadUnobserveImage: null
117+
}
118+
}
119+
120+
render() {
121+
return this.props.children;
122+
}
123+
}
124+
125+
EagerLoadImages.childContextTypes = LazyLoadImages.childContextTypes = {
113126
lazyLoadObserveImage: func,
114127
lazyLoadUnobserveImage: func
115128
};

0 commit comments

Comments
 (0)