forked from twobin/react-lazyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a8c08e
commit 5ca0149
Showing
3 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, {Component} from 'react'; | ||
import LazyLoad from '../../src/'; | ||
import Widget from '../components/Widget'; | ||
import Operation from '../components/Operation'; | ||
import {uniqueId} from '../utils'; | ||
|
||
export default class Throttle extends Component { | ||
constructor() { | ||
super(); | ||
|
||
const id = uniqueId(); | ||
this.state = { | ||
arr: Array(20).fill(0).map((a, index) => { | ||
return { | ||
uniqueId: id, | ||
once: [6, 7].indexOf(index) > -1 | ||
}; | ||
}) | ||
}; | ||
} | ||
|
||
handleClick() { | ||
const id = uniqueId(); | ||
|
||
this.setState({ | ||
arr: this.state.arr.map(el => { | ||
return { | ||
...el, | ||
uniqueId: id | ||
}; | ||
}) | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="wrapper"> | ||
<Operation type="throttle" onClickUpdate={::this.handleClick} /> | ||
<div className="widget-list"> | ||
{this.state.arr.map((el, index) => { | ||
return ( | ||
<LazyLoad once={el.once} key={index} throttle={200}> | ||
<Widget once={el.once} id={el.uniqueId} /> | ||
</LazyLoad> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|