Skip to content

Commit f951e99

Browse files
committed
feat: implement first version of viewport()
1 parent 94a3fc0 commit f951e99

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/viewport.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {Component} from 'react';
2+
import {h} from './util';
3+
import {ViewportSensor} from './ViewportSensor';
4+
import {loadable} from './loadable';
5+
6+
export const viewport = (params) => {
7+
const {Loadable} = params;
8+
9+
const Viewport = class Viewport extends Component<any, any> {
10+
state = {
11+
flipped: false
12+
};
13+
14+
onChange = () => {
15+
Loadable.load();
16+
this.setState({
17+
flipped: true
18+
});
19+
};
20+
21+
render () {
22+
const {flipped} = this.state;
23+
24+
return flipped ?
25+
h(Loadable, this.props) :
26+
h(ViewportSensor, {onChange: this.onChange},
27+
h('div')
28+
);
29+
}
30+
};
31+
32+
return Viewport;
33+
};

0 commit comments

Comments
 (0)