summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models/utils/cc_throttle_function.js
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-06-15 18:12:21 +0000
committerSébastien Theys <seb@odoo.com>2020-06-15 18:12:21 +0000
commit3fea5b2136627c1d7e83b2a5e111952fe3eb10a1 (patch)
tree5eefad07972a87ce4689b83260f981bc87aadad4 /addons/mail/static/src/js/models/utils/cc_throttle_function.js
parent0a82848606151ef60eb6523e9c4c161171f214e7 (diff)
[REF] mail, *: refactor messaging with OWL
This commit is a significant rewriting of client-side discuss, chatter, chat window, and messaging menu using OWL. The behavior should be broadly the same, with some slight functional changes here and there. From a technical standpoint, the code of messaging is mainly organized in 2 main groups of modules: - models, which are logical entities that depict the client-side state of messaging as a whole. - components, which are in charge of displaying information from models. This refactoring also introduces new JS guidelines regarding folder structure (/static) and naming rules for JS modules. Community PR: https://github.com/odoo/odoo/pull/39023 Enterprise PR: https://github.com/odoo/enterprise/pull/6249 Task-1914207 This PR is a collaborative work by Alexandre, Julien, Sébastien and Xavier, with the precious help of Lucas to speed it up towards the end. closes odoo/odoo#39023 Related: odoo/enterprise#6249 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com> Co-authored-by: Alexandre Kühn <aku@odoo.com> Co-authored-by: Julien Giannone <jgi@odoo.com> Co-authored-by: Lucas Perais <lpe@odoo.com> Co-authored-by: Sébastien Theys <seb@odoo.com> Co-authored-by: Xavier Dubuc <xdu@odoo.com>
Diffstat (limited to 'addons/mail/static/src/js/models/utils/cc_throttle_function.js')
-rw-r--r--addons/mail/static/src/js/models/utils/cc_throttle_function.js181
1 files changed, 0 insertions, 181 deletions
diff --git a/addons/mail/static/src/js/models/utils/cc_throttle_function.js b/addons/mail/static/src/js/models/utils/cc_throttle_function.js
deleted file mode 100644
index b4b87087e6d..00000000000
--- a/addons/mail/static/src/js/models/utils/cc_throttle_function.js
+++ /dev/null
@@ -1,181 +0,0 @@
-odoo.define('mail.model.CCThrottleFunctionObject', function (require) {
-"use strict";
-
-var Class = require('web.Class');
-
-/**
- * This object models the behaviour of the clearable and cancellable (CC)
- * throttle version of a provided function.
- */
-var CCThrottleFunctionObject = Class.extend({
-
- /**
- * @param {Object} params
- * @param {integer} params.duration duration of the 'cooldown' phase, i.e.
- * the minimum duration between the most recent function call that has
- * been made and the following function call.
- * @param {function} params.func provided function for making the CC
- * throttled version.
- */
- init: function (params) {
- this._arguments = undefined;
- this._cooldownTimeout = undefined;
- this._duration = params.duration;
- this._func = params.func;
- this._shouldCallFunctionAfterCD = false;
- },
-
- //--------------------------------------------------------------------------
- // Public
- //--------------------------------------------------------------------------
-
- /**
- * Cancel any buffered function call, but keep the cooldown phase running.
- */
- cancel: function () {
- this._arguments = undefined;
- this._shouldCallFunctionAfterCD = false;
- },
- /**
- * Clear the internal throttle timer, so that the following function call
- * is immediate. For instance, if there is a cooldown stage, it is aborted.
- */
- clear: function () {
- if (this._cooldownTimeout) {
- clearTimeout(this._cooldownTimeout);
- this._onCooldownTimeout();
- }
- },
- /**
- * Called when there is a call to the function. This function is throttled,
- * so the time it is called depends on whether the "cooldown stage" occurs
- * or not:
- *
- * - no cooldown stage: function is called immediately, and it starts
- * the cooldown stage when successful.
- * - in cooldown stage: function is called when the cooldown stage has
- * ended from timeout.
- *
- * Note that after the cooldown stage, only the last attempted function
- * call will be considered.
- */
- do: function () {
- this._arguments = Array.prototype.slice.call(arguments);
- if (this._cooldownTimeout === undefined) {
- this._callFunction();
- } else {
- this._shouldCallFunctionAfterCD = true;
- }
- },
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- /**
- * Immediately calls the function with arguments of last buffered function
- * call. It initiates the cooldown stage after this function call.
- *
- * @private
- */
- _callFunction: function () {
- this._func.apply(null, this._arguments);
- this._cooldown();
- },
- /**
- * Called when the function has been successfully called. The following
- * calls to the function with this object should suffer a "cooldown stage",
- * which prevents the function from being called until this stage has ended.
- *
- * @private
- */
- _cooldown: function () {
- this.cancel();
- this._cooldownTimeout = setTimeout(
- this._onCooldownTimeout.bind(this),
- this._duration
- );
- },
-
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
-
- /**
- * Called when the cooldown stage ended from timeout. Calls the function if
- * a function call was buffered.
- *
- * @private
- */
- _onCooldownTimeout: function () {
- if (this._shouldCallFunctionAfterCD) {
- this._callFunction();
- } else {
- this._cooldownTimeout = undefined;
- }
- },
-});
-
-return CCThrottleFunctionObject;
-
-});
-
-
-odoo.define('mail.model.CCThrottleFunction', function (require) {
-"use strict";
-
-var CCThrottleFunctionObject = require('mail.model.CCThrottleFunctionObject');
-
-/**
- * A function that creates a cancellable and clearable (CC) throttle version
- * of a provided function.
- *
- * This throttle mechanism allows calling a function at most once during a
- * certain period:
- *
- * - When a function call is made, it enters a 'cooldown' phase, in which any
- * attempt to call the function is buffered until the cooldown phase ends.
- * - At most 1 function call can be buffered during the cooldown phase, and the
- * latest one in this phase will be considered at its end.
- * - When a cooldown phase ends, any buffered function call will be performed
- * and another cooldown phase will follow up.
- *
- * This throttle version has the following interesting properties:
- *
- * - cancellable: it allows removing a buffered function call during the
- * cooldown phase, but it keeps the cooldown phase running.
- * - clearable: it allows to clear the internal clock of the throttled function,
- * so that any cooldown phase is immediately ending.
- *
- * @param {Object} params
- * @param {integer} params.duration a duration for the throttled behaviour,
- * in milli-seconds.
- * @param {function} params.func the function to throttle
- * @returns {function} the cancellable and clearable throttle version of the
- * provided function in argument.
- */
-var CCThrottleFunction = function (params) {
- var duration = params.duration;
- var func = params.func;
-
- var throttleFunctionObject = new CCThrottleFunctionObject({
- duration: duration,
- func: func,
- });
-
- var callable = function () {
- return throttleFunctionObject.do.apply(throttleFunctionObject, arguments);
- };
- callable.cancel = function () {
- throttleFunctionObject.cancel();
- };
- callable.clear = function () {
- throttleFunctionObject.clear();
- };
-
- return callable;
-};
-
-return CCThrottleFunction;
-
-});