From: Greg Hurrell Date: Tue, 4 Aug 2015 06:20:23 +0000 (-0700) Subject: Debounce history updates X-Git-Url: https://git.wincent.com/hextrapolate.git/commitdiff_plain/26bbd63a9d16d0a462544910eb2ee77b4a1f6968 Debounce history updates Because they're slow. --- diff --git a/src/App.js b/src/App.js index b3ff45d..b8b3470 100644 --- a/src/App.js +++ b/src/App.js @@ -15,11 +15,21 @@ import Field from './Field.react'; import Label from './Label.react'; import Size from './Size.react'; import convert from './convert'; +import debounce from './debounce'; import './App.css'; const SERIALIZATION_BASE = DIGITS.length; +const replaceHistoryState = debounce( + value => window.history.replaceState( + {}, + '', + '#' + convert(value.value, value.base, SERIALIZATION_BASE) + ), + 500 +); + function getInitialValue() { // Extract value from URL fragment, if present. const value = window.location.hash.replace(/^#/, ''); @@ -44,11 +54,7 @@ export default class App extends React.Component { _onValueChange = (value: Value) => { this.setState({value}); - window.history.replaceState( - {}, - '', - '#' + convert(value.value, value.base, SERIALIZATION_BASE) - ); + replaceHistoryState(value); } componentDidMount() {