From 26bbd63a9d16d0a462544910eb2ee77b4a1f6968 Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Mon, 3 Aug 2015 23:20:23 -0700 Subject: [PATCH] Debounce history updates Because they're slow. --- src/App.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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() { -- 2.37.1