summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-04-03 16:38:11 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitf68462198e4e7917ce32b16db7874d697ef442af (patch)
tree2bd6ff3864e3c2b25aa3f85fb31c8caacde72c51 /addons/web/static
parentb9d9c6e3bc8d3fd4bb547aadf002652bb7bb9db4 (diff)
[REF] web: don't debounce `DebouncedField._onInput` directly
The `DebouncedField` class has a `_onInput` method which is called when the user is typing text and which is debounced so that its action (setting the field's value) is not recalled too quickly. The problem is that if we have to do other actions which should not wait for the debouncing (or wait for another debouncing) when the user is typing text, this would imply to namespace the "input" event to add another handler, which is not very elegant. Instead, this commit changes the `DebouncedField` so that the `_onInput` handler is not debounced but instead calls a private method which is debounced (`_doDebouncedAction`).
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js8
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js20
2 files changed, 20 insertions, 8 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 79583894fdc..93d7c8418e2 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -39,9 +39,11 @@ var AbstractField = Widget.extend({
events: {
'keydown': '_onKeydown',
},
- // for field widgets that may have a large number of field changes quickly,
- // it could be a good idea to debounce the changes. In that case, this is
- // the suggested value. For example, see InputField.
+ /**
+ * for field widgets that may have a large number of field changes quickly,
+ * it could be a good idea to debounce the changes. In that case, this is
+ * the suggested value. For example, @see DebouncedField.
+ */
DEBOUNCE: 1000,
/**
* if this flag is set to true, the rest of the web client will assume that
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 1b96d585ac7..e6e5e84577e 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -45,7 +45,7 @@ var DebouncedField = AbstractField.extend({
this._super.apply(this, arguments);
if (this.DEBOUNCE && this.mode === 'edit') {
- this._onInput = _.debounce(this._onInput.bind(this), this.DEBOUNCE);
+ this._doDebouncedAction = _.debounce(this._doDebouncedAction.bind(this), this.DEBOUNCE);
}
},
@@ -63,6 +63,15 @@ var DebouncedField = AbstractField.extend({
*/
_getValue: function () {
},
+ /**
+ * Notifies the outside world of the new value (checked from the DOM).
+ * This method is debounced so that onchanges are not triggered too quickly.
+ *
+ * @private
+ */
+ _doDebouncedAction: function () {
+ this._setValue(this._getValue());
+ },
//--------------------------------------------------------------------------
// Handlers
@@ -70,7 +79,7 @@ var DebouncedField = AbstractField.extend({
/**
* We immediately notify the outside world when this field confirms its
- * changes
+ * changes.
*
* @private
*/
@@ -78,13 +87,14 @@ var DebouncedField = AbstractField.extend({
this._setValue(this._getValue());
},
/**
- * We notify the outside world for each change in this field. It does not
- * necessarily mean that onchanges will be triggered instantly.
+ * Called when the user is typing text -> By default this only calls a
+ * debounced method to notify the outside world of the changes.
+ * @see _doDebouncedAction
*
* @private
*/
_onInput: function () {
- this._setValue(this._getValue());
+ this._doDebouncedAction();
},
});