[IMP] *: remove core.bus

This commit removes the legacy global bus (core bus) and the places
where it was used.
The main users of this bus were the public widgets, they now use the bus
on Component.env.
Some of the uses were dead code and has been removed.

closes odoo/odoo#139076

Task: 3439226
Related: odoo/enterprise#49131
Signed-off-by: Francois Georis (fge) <fge@odoo.com>
This commit is contained in:
Michael (mcm)
2023-10-20 09:35:21 +00:00
parent a38a5b77fb
commit 8cf98fbe67
20 changed files with 23 additions and 120 deletions
@@ -1,24 +0,0 @@
/** @odoo-module **/
/**
* BarcodeEvents has been removed and replaced by the barcode service.
*
* This file is a temporary service to remap barcode events from new barcode
* service to core.bus (which was the purpose of BarcodeEvents).
*
* @TODO: remove this as soon as all barcode code is using new barcode service
*/
import { registry } from "@web/core/registry";
import core from "@web/legacy/js/services/core";
export const barcodeRemapperService = {
dependencies: ["barcode"],
start(env, { barcode }) {
barcode.bus.addEventListener("barcode_scanned", ev => {
const { barcode, target } = ev.detail;
core.bus.trigger('barcode_scanned', barcode, target);
});
},
};
registry.category("services").add("barcode_remapper", barcodeRemapperService);
@@ -1,7 +1,6 @@
/** @odoo-module **/
import {barcodeService} from "@barcodes/barcode_service";
import {barcodeRemapperService} from "@barcodes/js/barcode_events";
import { makeTestEnv } from "@web/../tests/helpers/mock_env";
import { registry } from "@web/core/registry";
import testUtils from "@web/../tests/legacy/helpers/test_utils";
@@ -30,8 +29,6 @@
barcodeService.maxTimeBetweenKeysInMs = 0;
barcodeService.isMobileChrome = true;
registry.category("services").add("barcode", barcodeService, { force: true});
// remove this one later
registry.category("services").add("barcode_remapper", barcodeRemapperService);
this.env = makeTestEnv();
},
after() {
@@ -90,7 +90,6 @@
'web/static/src/legacy/js/libs/autocomplete.js',
'web/static/src/legacy/js/libs/bootstrap.js',
'web/static/src/legacy/js/libs/jquery.js',
'web/static/src/legacy/js/core/bus.js',
'web/static/src/legacy/js/core/class.js',
'web/static/src/legacy/js/core/dialog.js',
'web/static/src/legacy/xml/dialog.xml',
@@ -98,7 +97,6 @@
'web/static/src/legacy/js/core/mixins.js',
'web/static/src/legacy/js/core/service_mixins.js',
'web/static/src/legacy/js/core/widget.js',
'web/static/src/legacy/js/services/core.js',
('include', 'web._assets_bootstrap'),
@@ -1,7 +1,7 @@
/** @odoo-module */
import core from '@web/legacy/js/services/core';
import publicWidget from '@web/legacy/js/public/public_widget';
import { Component } from '@odoo/owl';
publicWidget.registry.PaymentExpressCheckoutForm = publicWidget.Widget.extend({
selector: 'form[name="o_payment_express_checkout_form"]',
@@ -19,7 +19,7 @@ publicWidget.registry.PaymentExpressCheckoutForm = publicWidget.Widget.extend({
await this._prepareExpressCheckoutForm(expressCheckoutForm.dataset);
}
// Monitor updates of the amount on eCommerce's cart pages.
core.bus.on('cart_amount_changed', this, this._updateAmount.bind(this));
Component.env.bus.addEventListener('cart_amount_changed', (ev) => this._updateAmount(...ev.detail));
},
//--------------------------------------------------------------------------
@@ -1,13 +1,12 @@
/** @odoo-module **/
import core from "@web/legacy/js/services/core";
import { renderToElement } from "@web/core/utils/render";
import dom from "@web/legacy/js/core/dom";
import publicWidget from "@web/legacy/js/public/public_widget";
import portalComposer from "@portal/js/portal_composer";
import { range } from "@web/core/utils/numbers";
import { markup } from "@odoo/owl";
import { Component, markup } from "@odoo/owl";
/**
* Widget PortalChatter
@@ -67,7 +66,7 @@ var PortalChatter = publicWidget.Widget.extend({
// bind bus event: this (portal.chatter) and 'portal.rating.composer' in portal_rating
// are separate and sibling widgets, this event is to be triggered from portal.rating.composer,
// hence bus event is bound to achieve usage of the event in another widget.
core.bus.on('reload_chatter_content', this, this._reloadChatterContent);
Component.env.bus.addEventListener('reload_chatter_content', (ev) => this._reloadChatterContent(ev.detail));
return Promise.all([this._super.apply(this, arguments), this._reloadComposer()]);
},
@@ -2,10 +2,10 @@
import { _t } from "@web/core/l10n/translation";
import { escape } from "@web/core/utils/strings";
import core from "@web/legacy/js/services/core";
import { renderToElement } from "@web/core/utils/render";
import publicWidget from "@web/legacy/js/public/public_widget";
import { post } from "@web/core/network/http_service";
import { Component } from "@odoo/owl";
/**
* Widget PortalComposer
@@ -197,7 +197,7 @@ var PortalComposer = publicWidget.Widget.extend({
*/
_chatterPostMessage: async function (route) {
const result = await this.rpc(route, this._prepareMessageData());
core.bus.trigger('reload_chatter_content', result);
Component.env.bus.trigger('reload_chatter_content', result);
return result;
},
});
-2
View File
@@ -140,7 +140,6 @@
'web/static/src/legacy/js/libs/autocomplete.js',
'web/static/src/legacy/js/libs/bootstrap.js',
'web/static/src/legacy/js/libs/jquery.js',
'web/static/src/legacy/js/core/bus.js',
'web/static/src/legacy/js/core/class.js',
'web/static/src/legacy/js/core/dialog.js',
'web/static/src/legacy/xml/dialog.xml',
@@ -148,7 +147,6 @@
'web/static/src/legacy/js/core/mixins.js',
'web/static/src/legacy/js/core/service_mixins.js',
'web/static/src/legacy/js/core/widget.js',
'web/static/src/legacy/js/services/core.js',
('include', 'web._assets_bootstrap_backend'),
'base/static/src/css/modules.css',
-4
View File
@@ -92,7 +92,6 @@ This module provides the core of the Odoo Web Client.
'web/static/src/legacy/js/libs/autocomplete.js',
'web/static/src/legacy/js/libs/bootstrap.js',
'web/static/src/legacy/js/libs/jquery.js',
'web/static/src/legacy/js/core/bus.js',
'web/static/src/legacy/js/core/class.js',
'web/static/src/legacy/js/core/dialog.js',
'web/static/src/legacy/xml/dialog.xml',
@@ -100,7 +99,6 @@ This module provides the core of the Odoo Web Client.
'web/static/src/legacy/js/core/mixins.js',
'web/static/src/legacy/js/core/service_mixins.js',
'web/static/src/legacy/js/core/widget.js',
'web/static/src/legacy/js/services/core.js',
'base/static/src/css/modules.css',
@@ -214,7 +212,6 @@ This module provides the core of the Odoo Web Client.
'web/static/src/legacy/js/libs/autocomplete.js',
'web/static/src/legacy/js/libs/bootstrap.js',
'web/static/src/legacy/js/libs/jquery.js',
'web/static/src/legacy/js/core/bus.js',
'web/static/src/legacy/js/core/class.js',
'web/static/src/legacy/js/core/dialog.js',
'web/static/src/legacy/xml/dialog.xml',
@@ -222,7 +219,6 @@ This module provides the core of the Odoo Web Client.
'web/static/src/legacy/js/core/mixins.js',
'web/static/src/legacy/js/core/service_mixins.js',
'web/static/src/legacy/js/core/widget.js',
'web/static/src/legacy/js/services/core.js',
'web/static/src/env.js',
'web/static/src/core/utils/transitions.scss', # included early because used by other files
@@ -1,16 +0,0 @@
/** @odoo-module **/
import Class from "@web/legacy/js/core/class";
import mixins from "@web/legacy/js/core/mixins";
/**
* Event Bus used to bind events scoped in the current instance
*
* @class Bus
*/
export default Class.extend(mixins.EventDispatcherMixin, {
init: function (parent) {
mixins.EventDispatcherMixin.init.call(this);
this.setParent(parent);
},
});
@@ -1,6 +1,5 @@
/** @odoo-module **/
import core from "@web/legacy/js/services/core";
import dom from "@web/legacy/js/core/dom";
import Widget from "@web/legacy/js/core/widget";
import { _t } from "@web/core/l10n/translation";
@@ -100,8 +99,6 @@ var Dialog = Widget.extend({
this.renderHeader = options.renderHeader;
this.renderFooter = options.renderFooter;
this.onForceClose = options.onForceClose;
core.bus.on('close_dialogs', this, this.destroy.bind(this));
},
/**
* Wait for XML dependencies and instantiate the modal structure (except
@@ -211,9 +208,6 @@ var Dialog = Widget.extend({
if (options && options.shouldFocusButtons) {
self._onFocusControlButton();
}
// Notifies new webclient to adjust UI active element
core.bus.trigger("legacy_dialog_opened", self);
});
return self;
@@ -245,11 +239,6 @@ var Dialog = Widget.extend({
return;
}
if (this.el) {
// Notifies new webclient to adjust UI active element
core.bus.trigger("legacy_dialog_destroyed", this);
}
// Triggers the onForceClose event if the callback is defined
if (this.onForceClose) {
this.onForceClose();
@@ -11,7 +11,6 @@
import { uniqueId } from "@web/core/utils/functions";
import { delay } from "@web/core/utils/concurrency";
import core from "@web/legacy/js/services/core";
import { localization } from "@web/core/l10n/localization";
/**
@@ -27,7 +26,6 @@ function _notify(content, callbacks) {
c.widget.on_attach_callback(c.callback_args);
}
});
core.bus.trigger('DOM_updated', content);
}
var dom = {
@@ -139,12 +137,6 @@ var dom = {
$textarea.data("auto_resize", true);
$textarea.on('input focus change', resize);
if (options.parent) {
core.bus.on('DOM_updated', options.parent, function () {
resize();
removeVerticalResize();
});
}
},
/**
* @return {HTMLElement|null}
@@ -1,6 +0,0 @@
/** @odoo-module **/
import Bus from "@web/legacy/js/core/bus";
export const bus = new Bus();
export default { bus };
-15
View File
@@ -1,6 +1,5 @@
/** @odoo-module **/
import LegacyBus from "@web/legacy/js/core/bus";
import { assets, templates } from "@web/core/assets";
import { browser, makeRAMLocalStorage } from "@web/core/browser/browser";
import { patchTimeZone, patchWithCleanup } from "@web/../tests/helpers/utils";
@@ -201,19 +200,6 @@ function patchBodyAddEventListener() {
});
}
function patchLegacyBus() {
// patch core.bus.on to automatically remove listners bound on the legacy bus
// during a test (e.g. during the deployment of a service)
patchWithCleanup(LegacyBus.prototype, {
on() {
super.on(...arguments);
registerCleanup(() => {
this.off(...arguments);
});
},
});
}
function patchOdoo() {
patchWithCleanup(odoo, {
debug: "",
@@ -367,7 +353,6 @@ export async function setupTests() {
patchCookie();
patchBodyAddEventListener();
patchEventBus();
patchLegacyBus();
patchOdoo();
patchSessionInfo();
patchOwlApp();
-2
View File
@@ -79,7 +79,6 @@ Odoo Web Editor widget.
'web/static/src/legacy/js/libs/autocomplete.js',
'web/static/src/legacy/js/libs/bootstrap.js',
'web/static/src/legacy/js/libs/jquery.js',
'web/static/src/legacy/js/core/bus.js',
'web/static/src/legacy/js/core/class.js',
'web/static/src/legacy/js/core/dialog.js',
'web/static/src/legacy/xml/dialog.xml',
@@ -87,7 +86,6 @@ Odoo Web Editor widget.
'web/static/src/legacy/js/core/mixins.js',
'web/static/src/legacy/js/core/service_mixins.js',
'web/static/src/legacy/js/core/widget.js',
'web/static/src/legacy/js/services/core.js',
('include', 'web_editor.assets_wysiwyg'),
('include', 'web_editor.assets_legacy_wysiwyg'),
],
@@ -2,7 +2,6 @@
import { Mutex } from "@web/core/utils/concurrency";
import { clamp } from "@web/core/utils/numbers";
import core from "@web/legacy/js/services/core";
import Dialog from "@web/legacy/js/core/dialog";
import dom from "@web/legacy/js/core/dom";
import Widget from "@web/legacy/js/core/widget";
@@ -1968,8 +1967,6 @@ var SnippetsMenu = Widget.extend({
// Needed as bootstrap stop the propagation of click events for dropdowns
this.$document.on('mouseup.snippets_menu', '.dropdown-toggle', this._onClick);
core.bus.on('deactivate_snippet', this, this._onDeactivateSnippet);
// Adapt overlay covering when the window is resized / content changes
this.debouncedCoverUpdate = throttleForAnimation(() => {
this.updateCurrentSnippetEditorOverlay();
@@ -2108,7 +2105,6 @@ var SnippetsMenu = Widget.extend({
if (this.debouncedCoverUpdate) {
this.debouncedCoverUpdate.cancel();
}
core.bus.off('deactivate_snippet', this, this._onDeactivateSnippet);
$(document.body).off('click', this._checkEditorToolbarVisibilityCallback);
this.el.ownerDocument.body.classList.remove('editor_has_snippets');
// Dispose BS tooltips.
@@ -1,9 +1,9 @@
/** @odoo-module **/
import { debounce } from "@web/core/utils/timing";
import core from "@web/legacy/js/services/core";
import publicWidget from "@web/legacy/js/public/public_widget";
import { _t } from "@web/core/l10n/translation";
import { Component } from "@odoo/owl";
publicWidget.registry.websiteEventTrackReminder = publicWidget.Widget.extend({
selector: '.o_wetrack_js_reminder',
@@ -60,11 +60,14 @@ publicWidget.registry.websiteEventTrackReminder = publicWidget.Widget.extend({
type: 'info',
});
if (self.reminderOn) {
core.bus.trigger('open_notification_request', 'add_track_to_favorite', {
title: _t('Allow push notifications?'),
body: _t('You have to enable push notifications to get reminders for your favorite tracks.'),
delay: 0
});
Component.env.bus.trigger('open_notification_request', [
'add_track_to_favorite',
{
title: _t('Allow push notifications?'),
body: _t('You have to enable push notifications to get reminders for your favorite tracks.'),
delay: 0
},
]);
}
}
});
@@ -1,7 +1,7 @@
/** @odoo-module **/
import core from '@web/legacy/js/services/core';
import { _t } from '@web/core/l10n/translation';
import { Component } from '@odoo/owl';
import PaymentForm from '@payment/js/payment_form';
@@ -16,7 +16,7 @@ PaymentForm.include({
* @override
*/
async start() {
core.bus.on('update_shipping_cost', this, this._updateShippingCost);
Component.env.bus.addEventListener('update_shipping_cost', (ev) => this._updateShippingCost(ev.detail));
return await this._super.apply(this, arguments);
},
@@ -1,6 +1,5 @@
/** @odoo-module **/
import core from "@web/legacy/js/services/core";
import publicWidget from "@web/legacy/js/public/public_widget";
import VariantMixin from "@website_sale/js/variant_mixin";
import wSaleUtils from "@website_sale/js/website_sale_utils";
@@ -12,6 +11,7 @@ import { ProductImageViewer } from "@website_sale/js/components/website_sale_ima
import { jsonrpc } from "@web/core/network/rpc_service";
import { debounce, throttleForAnimation } from "@web/core/utils/timing";
import { listenSizeChange, SIZES, utils as uiUtils } from "@web/core/ui/ui_service";
import { Component } from "@odoo/owl";
export const WebsiteSale = publicWidget.Widget.extend(VariantMixin, cartHandlerMixin, {
selector: '.oe_website_sale',
@@ -209,7 +209,7 @@ export const WebsiteSale = publicWidget.Widget.extend(VariantMixin, cartHandlerM
product_id: parseInt($input.data('product-id'), 10),
set_qty: value,
display: true,
}).then(function (data) {
}).then((data) => {
$input.data('update_change', false);
var check_value = parseInt($input.val() || 0, 10);
if (isNaN(check_value)) {
@@ -228,7 +228,7 @@ export const WebsiteSale = publicWidget.Widget.extend(VariantMixin, cartHandlerM
wSaleUtils.updateCartNavBar(data);
wSaleUtils.showWarning(data.warning);
// Propagating the change to the express checkout forms
core.bus.trigger('cart_amount_changed', data.amount, data.minor_amount);
Component.env.bus.trigger('cart_amount_changed', [data.amount, data.minor_amount]);
});
},
/**
@@ -1,10 +1,10 @@
/** @odoo-module **/
import core from "@web/legacy/js/services/core";
import publicWidget from "@web/legacy/js/public/public_widget";
import { _t } from "@web/core/l10n/translation";
import { renderToElement } from "@web/core/utils/render";
import { KeepLast } from "@web/core/utils/concurrency";
import { Component } from "@odoo/owl";
publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
selector: '.oe_website_sale',
@@ -119,7 +119,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
* @param {float} amount : The new total amount of to be paid
*/
_updateShippingCost: function(amount) {
core.bus.trigger('update_shipping_cost', amount);
Component.env.bus.trigger('update_shipping_cost', amount);
},
/**
* Get the rate shipment of a carrier
@@ -249,7 +249,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
if (!this._isPayable(status)) {
return;
}
core.bus.trigger('enableButton');
Component.env.bus.trigger('enableButton');
},
/**
* @private
-2
View File
@@ -180,7 +180,6 @@ Featuring
'web/static/src/legacy/js/libs/bootstrap.js',
'web/static/src/legacy/js/libs/jquery.js',
'website/static/src/libs/zoomodoo/zoomodoo.js',
'web/static/src/legacy/js/core/bus.js',
'web/static/src/legacy/js/core/class.js',
'web/static/src/legacy/js/core/dialog.js',
'web/static/src/legacy/xml/dialog.xml',
@@ -188,7 +187,6 @@ Featuring
'web/static/src/legacy/js/core/mixins.js',
'web/static/src/legacy/js/core/service_mixins.js',
'web/static/src/legacy/js/core/widget.js',
'web/static/src/legacy/js/services/core.js',
'web/static/src/core/**/*.js',
'web/static/src/env.js',
'web/static/src/libs/pdfjs.js',