From 5698d1fab9cf36714f677ae6942201d5c9354798 Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Mon, 13 Jul 2020 13:03:23 +0000 Subject: [IMP] web: add Registry predicate Before this commit, any value could be added to registries and the class needed to be overridden to assert that added values would answer to a certain predicate. Now, the registry can be instantiated with a given predicate function that all added value must pass to be registered (default: all values are accepted). Existing implentations have been adapted: - FieldRegistry - FieldRegistryOwl. --- addons/web/static/src/js/fields/field_registry.js | 18 ++++++------------ addons/web/static/src/js/fields/field_registry_owl.js | 14 ++++---------- 2 files changed, 10 insertions(+), 22 deletions(-) (limited to 'addons/web/static/src/js/fields') diff --git a/addons/web/static/src/js/fields/field_registry.js b/addons/web/static/src/js/fields/field_registry.js index 925b405051e..ef174702579 100644 --- a/addons/web/static/src/js/fields/field_registry.js +++ b/addons/web/static/src/js/fields/field_registry.js @@ -1,18 +1,12 @@ odoo.define('web.field_registry', function (require) { -"use strict"; - -var Registry = require('web.Registry'); + "use strict"; -var FieldRegistry = Registry.extend({ - add: function (key, value, score) { - if (value.prototype instanceof owl.Component) { - throw new Error("This registry should not contain any Component. Use 'web.field_registry_owl' instead."); - } - return this._super(...arguments); - }, -}); + const Registry = require('web.Registry'); -return new FieldRegistry(); + return new Registry( + null, + (value) => !(value.prototype instanceof owl.Component) + ); }); odoo.define('web._field_registry', function (require) { diff --git a/addons/web/static/src/js/fields/field_registry_owl.js b/addons/web/static/src/js/fields/field_registry_owl.js index 907ea38a9d7..635db621829 100644 --- a/addons/web/static/src/js/fields/field_registry_owl.js +++ b/addons/web/static/src/js/fields/field_registry_owl.js @@ -3,16 +3,10 @@ odoo.define('web.field_registry_owl', function (require) { const Registry = require('web.Registry'); - const FieldRegistry = Registry.extend({ - add: function (key, value, score) { - if (!(value.prototype instanceof owl.Component)) { - throw new Error("This registry should only contain subclasses of Component"); - } - return this._super(...arguments); - }, - }); - - return new FieldRegistry(); + return new Registry( + null, + (value) => value.prototype instanceof owl.Component + ); }); odoo.define('web._field_registry_owl', function (require) { -- cgit v1.2.3