diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/web/static/src/js/component_extension.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/web/static/src/js/component_extension.js')
| -rw-r--r-- | addons/web/static/src/js/component_extension.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/addons/web/static/src/js/component_extension.js b/addons/web/static/src/js/component_extension.js new file mode 100644 index 00000000..4edaee80 --- /dev/null +++ b/addons/web/static/src/js/component_extension.js @@ -0,0 +1,42 @@ +(function () { + /** + * Symbol used in ComponentWrapper to redirect Owl events to Odoo legacy + * events. + */ + odoo.widgetSymbol = Symbol('widget'); + + /** + * Add a new method to owl Components to ensure that no performed RPC is + * resolved/rejected when the component is destroyed. + */ + owl.Component.prototype.rpc = function () { + return new Promise((resolve, reject) => { + return this.env.services.rpc(...arguments) + .then(result => { + if (this.__owl__.status !== 5 /* not destroyed */) { + resolve(result); + } + }) + .catch(reason => { + if (this.__owl__.status !== 5) /* not destroyed */ { + reject(reason); + } + }); + }); + }; + + /** + * Patch owl.Component.__trigger method to call a hook that adds a listener + * for the triggered event just before triggering it. This is useful if + * there are legacy widgets in the ancestors. In that case, there would be + * a widgetSymbol key in the environment, corresponding to the hook to call + * (see ComponentWrapper). + */ + const originalTrigger = owl.Component.prototype.__trigger; + owl.Component.prototype.__trigger = function (component, evType, payload) { + if (this.env[odoo.widgetSymbol]) { + this.env[odoo.widgetSymbol](evType); + } + originalTrigger.call(this, component, evType, payload); + }; +})(); |
