Registries¶
Registries are (ordered) key/value maps. They are the main web client extension points: many features provided by the Odoo javascript framework simply look up into a registry whenever it needs a definition for some object (such as fields, views, client actions or services). Customizing the web client is then simply done by adding specific values in the correct registry.
import { Registry } from "@web/core/registry";
const myRegistry = new Registry();
myRegistry.add("hello", "odoo");
console.log(myRegistry.get("hello"));
A useful feature of registries is that they maintain a set of sub registries,
obtained by the category
method. If the sub registry does not exist yet, it
is created on the fly. All registries used by the web client are obtained
in such a way from one root registry, exported in @web/core/registry
.
import { registry } from "@web/core/registry";
const fieldRegistry = registry.category("fields");
const serviceRegistry = registry.category("services");
const viewRegistry = registry.category("views");
Registry API¶
- class Registry()¶
Creates a new registry. Note that a registry is an event bus, so one can listen to the
UPDATE
event if necessary. Registries are ordered: thegetAll
method returns a list of values ordered according to their sequence number.- Registry.add(key, value[, options])¶
- Argumentais
key (
string()
) – key for the new entryvalue (
any()
) – value for the new entryoptions (
Object()
) – options[options.force] (
boolean()
) – do not throw if key already exists[options.sequence] (
number()
) – sequence number (useful to order entries)
- Grąžinamos reikšmės
Registry
Inserts a value at a specific key. If the key is already used, this method throws an error (unless the option
force
is set to true). The optionsequence
is useful to insert the value at a specific position. This method also triggers anUPDATE
event.Returns the same registry, so
add
method calls can be chained.
- Registry.get(key[, defaultValue])¶
- Argumentais
key (
string()
) – key for the entryany (
defaultValue()
) – return value if no entry for key exists
Returns the value corresponding to the
key
argument. If the registry does not contain that key, this method returnsdefaultValue
if given, or throws an error otherwise.
- Registry.contains(key)¶
- Argumentais
key (
string()
) – key for the entry
- Grąžinamos reikšmės
boolean
Returns
true
ifkey
is present in the registry
- Registry.getAll()¶
- Grąžinamos reikšmės
any[]
Returns the list of all elements in the registry. It is ordered according to the sequence numbers.
- Registry.remove(key)¶
- Argumentais
key (
string()
) – the key for the entry that should be removed
Removes a key/value pair from the registry. This operation triggers an
UPDATE
event.
- Registry.category(subcategory)¶
- Argumentais
subcategory (
string()
) – the name for the sub category
- Grąžinamos reikšmės
Registry
Returns the sub registry associated with the
subcategory
. If it does not exist yet, the sub registry is created on the fly.
Reference List¶
Category |
Content |
---|---|
implementation for all available effects |
|
utility functions to format values (mostly used for field values) |
|
top level components |
|
utility functions to parse values (mostly used for field values) |
|
all services that should be activated |
|
components displayed in the systray zone in the navbar |
|
menu items displayed in the user menu (top right of navbar) |
Effect registry¶
The effects
registry contains the implementations of all available effects.
See the section on the effect service
for more details.
Formatter registry¶
The formatters
registry contains functions to format values. Each formatter
has the following API:
- format(value[, options])¶
- Argumentais
value (
T | false()
) – a value of a specific type, orfalse
if no value is givenoptions (
Object()
) – various options
- Grąžinamos reikšmės
string
Formats a value and returns a string
Taip pat žiūrėkite
Main components registry¶
The main component registry (main_components
) is useful for adding top level
components in the web client. The webclient has a MainComponentsContainer
as
direct child. This component is basically a live representation of the ordered
list of components registered in the main components registry.
- API
interface { Component: Owl Component class props?: any }
For example, the LoadingIndicator
component can be added in the registry like
this:
registry.category("main_components").add("LoadingIndicator", {
Component: LoadingIndicator,
});
Parser registry¶
The parsers
registry contains functions to parse values. Each parser
has the following API:
- parse(value[, options])
- Argumentais
value (
string()
) – a string representing a valueoptions (
Object()
) – various options (parser specific)
- Grąžinamos reikšmės
T a valid value
Parses a string and returns a value. If the string does not represent a valid value, parsers can fail and throw errors.
Taip pat žiūrėkite
Service registry¶
The service registry (category: services
) contains all
services that should be activated by the Odoo
framework.
import { registry } from "@web/core/registry";
const myService = {
dependencies: [...],
start(env, deps) {
// some code here
}
};
registry.category("services").add("myService", myService);
Systray registry¶
The systray is the zone on the right of the navbar that contains various small components, that usually display some sort of information (like the number of unread messages), notifications and/or let the user interact with them.
The systray
registry contains a description of these systray items, as objects
with the following three keys:
Component
: the component class that represents the item. Its root element should be a<li>
tag, otherwise it might not be styled properly.props (optional)
: props that should be given to the componentisDisplayed (optional)
: a function that takes the env and returns a boolean. If true, the systray item is displayed. Otherwise it is removed.
For example:
import { registry } from "@web/core/registry";
class MySystrayItem extends Component {
// some component ...
}
registry.category("systray").add("myAddon.myItem", {
Component: MySystrayItem,
});
The systray registry is an ordered registry (with the sequence
number):
const item = {
Component: MySystrayItem
};
registry.category("systray").add("myaddon.some_description", item, { sequence: 43 });
The sequence number defaults to 50. If given, this number will be used to order the items. The lowest sequence is on the right and the highest sequence is on the left in the systray menu.