Skip to content

Commit

Permalink
docs: add throttle demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonslyvia committed Apr 7, 2016
1 parent 5a8c08e commit 5ca0149
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
13 changes: 8 additions & 5 deletions examples/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, hashHistory, Link} from 'react-router';
import { Router, Route, hashHistory, Link } from 'react-router';

import Decorator from './pages/decorator';
import Normal from './pages/Normal';
import Scroll from './pages/Scroll';
import Overflow from './pages/Overflow';
import Image from './pages/Image';
import Normal from './pages/normal';
import Scroll from './pages/scroll';
import Overflow from './pages/overflow';
import Image from './pages/image';
import Throttle from './pages/throttle';

const Home = () => (
<ul>
Expand All @@ -15,6 +16,7 @@ const Home = () => (
<li><Link to="/decorator">using with <code>decorator</code></Link></li>
<li><Link to="/scroll">using with <code>scrollTo</code></Link></li>
<li><Link to="/overflow">using inside overflow container</Link></li>
<li><Link to="/throttle">using <code>throttle</code></Link></li>
</ul>
);

Expand All @@ -26,6 +28,7 @@ const routes = (
<Route path="/normal" component={Normal} />
<Route path="/scroll" component={Scroll} />
<Route path="/overflow" component={Overflow} />
<Route path="/throttle" component={Throttle} />
</Router>
);

Expand Down
7 changes: 7 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@
text-align: center;
margin: 20px 0;
}
code {
background: #eee;
padding: 2px 3px;
border-radius: 3px;
color: #333;
text-decoration: none;
}
</style>
</head>
<body>
Expand Down
52 changes: 52 additions & 0 deletions examples/pages/throttle.js
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>
);
}
}

0 comments on commit 5ca0149

Please sign in to comment.