[ADD] developer: add a reference page on hooks (js)
closes odoo/documentation#1224
X-original-commit: eea6a94411
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
This commit is contained in:
parent
642f68cad1
commit
e9a6934319
@ -13,6 +13,7 @@ Javascript
|
|||||||
javascript/registries
|
javascript/registries
|
||||||
javascript/services
|
javascript/services
|
||||||
javascript/generic_components
|
javascript/generic_components
|
||||||
|
javascript/hooks
|
||||||
javascript/javascript_cheatsheet
|
javascript/javascript_cheatsheet
|
||||||
javascript/javascript_reference
|
javascript/javascript_reference
|
||||||
javascript/mobile
|
javascript/mobile
|
||||||
|
49
content/developer/reference/javascript/hooks.rst
Normal file
49
content/developer/reference/javascript/hooks.rst
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
=====
|
||||||
|
Hooks
|
||||||
|
=====
|
||||||
|
|
||||||
|
`Owl hooks <https://github.com/odoo/owl/blob/master/doc/reference/hooks.md>`_ are a
|
||||||
|
way to factorize code, even if it depends on some component lifecycle. Most hooks
|
||||||
|
provided by Owl are related to the lifecycle of a component, but some of them (such as
|
||||||
|
`useComponent <https://github.com/odoo/owl/blob/master/doc/reference/hooks.md#usecomponent>`_)
|
||||||
|
provide a way to build specific hooks.
|
||||||
|
|
||||||
|
Using these hooks, it is possible to build many customized hooks that help solve
|
||||||
|
a specific problem, or make some common tasks easier. The rest of this page
|
||||||
|
documents the list of hooks provided by the Odoo web framework.
|
||||||
|
|
||||||
|
useBus
|
||||||
|
======
|
||||||
|
|
||||||
|
Location
|
||||||
|
--------
|
||||||
|
|
||||||
|
`@web/core/utils/hooks`
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Add and clear an event listener to a bus. This hook ensures that
|
||||||
|
the listener is properly cleared when the component is unmounted.
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
import { useBus } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
class MyComponent {
|
||||||
|
setup() {
|
||||||
|
useBus(this.env.bus, "some-event", event => {
|
||||||
|
console.log(event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
API
|
||||||
|
---
|
||||||
|
|
||||||
|
.. js:function:: useBus(bus, eventName, callback)
|
||||||
|
|
||||||
|
:param EventBus bus: the target event bus
|
||||||
|
:param string eventName: the name of the event that we want to listen to
|
||||||
|
:param function callback: listener callback
|
||||||
|
|
Loading…
Reference in New Issue
Block a user