summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/component_extension.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/component_extension.js')
-rw-r--r--addons/web/static/src/js/component_extension.js21
1 files changed, 21 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 00000000000..39568bd0594
--- /dev/null
+++ b/addons/web/static/src/js/component_extension.js
@@ -0,0 +1,21 @@
+/**
+ * Add a new method to owl Components to ensure that no performed RPC is
+ * resolved/rejected when the component is destroyed.
+ */
+(function () {
+ owl.Component.prototype.rpc = function () {
+ return new Promise((resolve, reject) => {
+ return this.env.services.rpc(...arguments)
+ .then(result => {
+ if (!this.__owl__.isDestroyed) {
+ resolve(result);
+ }
+ })
+ .catch(reason => {
+ if (!this.__owl__.isDestroyed) {
+ reject(reason);
+ }
+ });
+ });
+ };
+})();