diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-04-03 16:38:11 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | f68462198e4e7917ce32b16db7874d697ef442af (patch) | |
| tree | 2bd6ff3864e3c2b25aa3f85fb31c8caacde72c51 /addons/web/static/src/js/fields/basic_fields.js | |
| parent | b9d9c6e3bc8d3fd4bb547aadf002652bb7bb9db4 (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/src/js/fields/basic_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 20 |
1 files changed, 15 insertions, 5 deletions
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(); }, }); |
