From c1fe1884e2540453d37f403933f8a0be1ceebcbd Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 19 Oct 2015 13:24:05 +0200 Subject: [PATCH] Ajout debounce chargement icone --- src/components/common/app-icon.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/common/app-icon.js b/src/components/common/app-icon.js index 2476ae9..0e8b6d9 100644 --- a/src/components/common/app-icon.js +++ b/src/components/common/app-icon.js @@ -2,6 +2,7 @@ var React = require('react'); var Util = require('../../util'); var LazyLoad = require('../mixins/lazy-load'); var debug = Util.Debug('common:app-icon'); +var _ = require('lodash'); var LOADING_ICON = 'img/hourglass.svg'; var DEFAULT_ICON = 'img/default-icon.svg'; @@ -10,6 +11,12 @@ module.exports = React.createClass({ mixins: [LazyLoad], + componentWillMount: function() { + if(!this._findIconDebounced) { + this._findIconDebounced = _.debounce(this._findIcon, 250); + } + }, + getInitialState: function() { return { icon: DEFAULT_ICON, iconPath: DEFAULT_ICON, currentTheme: '' }; }, @@ -33,7 +40,7 @@ module.exports = React.createClass({ this.setState({ icon: newIcon, iconPath: LOADING_ICON, currentTheme: newTheme }); - this._findIcon(newIcon, newTheme); + this._findIconDebounced(newIcon, newTheme); },