odoo
odoo copied to clipboard
[REF] html_editor: clean the resource API for plugins
This commit change the resource API for the plugins in 3 ways.
1) The disposal of resources
Instead of
class MyPlugin extends Plugin {
/** @type { (p: MyPlugin) => Record<string, any> } */
static resources = (p) => ({
my_handlers: p.handler.bind(p)
})
}
We now have
class MyPlugin extends Plugin {
resources = {
my_handlers: this.handler.bind(this)
}
}
2) Resource getter
To access a specific resource within a plugin, instead of
this.resources['my_handler']
We now have
this.getResource('my_handler')
If no other plugin disposed the specified resource, the getter will return an empty array.
3) Sequences for all resources
This commit give the ability to specify a sequence for any resource item, removing the need for the consumer of the resource to have to setup it.
Instead of
class MyPluginA extends Plugin {
resources = {
my_handlers: {handler: this.handler.bind(this), sequence: 100}
my_data: {id: 'some-id', sequence: 100}
}
}
class MyPluginB extends Plugin {
constructor() {
this.handlers = this.getResource('my_handlers')
.sort((a, b) => a.sequence - b.sequence)
}
myMethod() {
for (const {handler} of this.myHandlers) {
handler();
}
}
}
We now have
class MyPluginA extends Plugin {
resources = {
my_handlers: withSequence(100, this.handler.bind(this)),
my_data: withSequence(100, {id: 'some-id'}),
}
}
class MyPluginB extends Plugin {
myMethod() {
for (const handler of this.getResource('my_handlers')) {
handler();
}
}
}
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr
@goaman @fdardenne 'ci/runbot' failed on this reviewed PR.
@robodoo r+
@robodoo r+
