summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/registry.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-02-12 10:08:39 +0100
committerAlexandre Kühn <aku@odoo.com>2018-02-12 16:09:38 +0100
commit066eaaeafad845a7b616a535e8827a5b3ae0164a (patch)
tree6fb69b6dd636b801080cfd7596c97df22c67f599 /addons/web/static/src/js/core/registry.js
parent0de5c1f076d7e7d0e5361e08c810c727bd41d9e0 (diff)
[FIX] mail,web: JS mail and services tracebacks
Fix over this commit: https://github.com/odoo/odoo/commit/02ec09cb1c3e2d7bc7968f40c18f2208d7f3f498 In mobile, when discuss is installed, there is a traceback. This is a consequence on an issue with JS services, where some of them are not registered in the service provider. For instance, the webclient (the service provider) was instantiated before chat_manager (a service), so it was not aware of this service. To solve this issue, service providers now listen on newly registered services. Also improving deployment of JS services by not relying on topological sort.
Diffstat (limited to 'addons/web/static/src/js/core/registry.js')
-rw-r--r--addons/web/static/src/js/core/registry.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/registry.js b/addons/web/static/src/js/core/registry.js
index d70c09e4ae0..f925b0ea30a 100644
--- a/addons/web/static/src/js/core/registry.js
+++ b/addons/web/static/src/js/core/registry.js
@@ -25,6 +25,7 @@ var Registry = Class.extend({
*/
init: function (mapping) {
this.map = Object.create(mapping || null);
+ this.listeners = []; // listening callbacks on newly added items.
},
//--------------------------------------------------------------------------
@@ -34,12 +35,17 @@ var Registry = Class.extend({
/**
* Add a key (and a value) to the registry.
*
+ * Notify the listeners on newly added item in the registry.
+ *
* @param {string} key
* @param {any} value
* @returns {Registry} can be used to chain add calls.
*/
add: function (key, value) {
this.map[key] = value;
+ _.each(this.listeners, function (callback) {
+ callback(key, value);
+ });
return this;
},
/**
@@ -89,6 +95,14 @@ var Registry = Class.extend({
}
return null;
},
+ /**
+ * Register a callback to execute when items are added to the registry.
+ *
+ * @param {function} callback function with parameters (key, value).
+ */
+ onAdd: function (callback) {
+ this.listeners.push(callback);
+ },
});
return Registry;