Skip to content

Commit a3478e8

Browse files
committed
[FIX] rpc: fix code examples for tutorial and service
closes #13234 X-original-commit: 2712116 Signed-off-by: Florent Dardenne (dafl) <[email protected]>
1 parent d05afb2 commit a3478e8

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

content/developer/reference/frontend/services.rst

+5-8
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,13 @@ component later. For example:
9595

9696
.. code-block:: javascript
9797
98-
import { useService } from "@web/core/utils/hooks";
98+
import { rpc } from "@web/core/network/rpc";
9999
100100
class MyComponent extends Component {
101101
setup() {
102-
const rpc = useService("rpc");
103-
104102
onWillStart(async () => {
105-
this.someValue = await rpc(...);
106-
});
103+
const result = await rpc(...);
104+
})
107105
}
108106
}
109107
@@ -623,11 +621,10 @@ argument and optionally, a ``params`` object can be given as a second argument.
623621

624622
.. code-block:: javascript
625623
626-
// in setup
627-
this.rpc = useService("rpc");
624+
import { rpc } from "@web/core/network/rpc";
628625
629626
// somewhere else, in an async function:
630-
const result = await this.rpc("/my/route", { some: "value" });
627+
const result = await rpc("/my/route", { some: "value" });
631628
632629
.. note::
633630

content/developer/tutorials/discover_js_framework/02_build_a_dashboard.rst

+10-9
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,23 @@ Let's improve the dashboard by adding a few dashboard items to display *real* bu
199199
The `awesome_dashboard` addon provides a `/awesome_dashboard/statistics` route that is meant
200200
to return some interesting information.
201201

202-
To call a specific controller, we need to use the :ref:`rpc service <frontend/services/rpc>`.
202+
To call a specific controller, we need to use the :ref:`rpc <frontend/services/rpc>` function.
203203
It only exports a single function that perform the request: :code:`rpc(route, params, settings)`.
204204
A basic request could look like this:
205205

206206
.. code-block:: js
207207
208+
import { rpc } from "@web/core/network/rpc";
209+
// ...
210+
208211
setup() {
209-
this.rpc = useService("rpc");
210-
onWillStart(async () => {
211-
const result = await this.rpc("/my/controller", {a: 1, b: 2});
212-
// ...
213-
});
212+
onWillStart(async () => {
213+
const result = await rpc("/my/controller", {a: 1, b: 2});
214+
})
215+
// ...
214216
}
215217
216-
#. Update `Dashboard` so that it uses the `rpc` service.
217-
#. Call the statistics route `/awesome_dashboard/statistics` in the `onWillStart` hook.
218+
#. Update `Dashboard` so that it uses the `rpc` function and call the statistics route `/awesome_dashboard/statistics`.
218219
#. Display a few cards in the dashboard containing:
219220

220221
- Number of new orders this month
@@ -227,7 +228,7 @@ A basic request could look like this:
227228
:align: center
228229

229230
.. seealso::
230-
`Code: rpc service <{GITHUB_PATH}/addons/web/static/src/core/network/rpc_service.js>`_
231+
`Code: rpc <{GITHUB_PATH}/addons/web/static/src/core/network/rpc.js>`_
231232

232233
5. Cache network calls, create a service
233234
========================================

0 commit comments

Comments
 (0)