ch2.5 Cache network calls, create a service

This commit is contained in:
Matt Marcha 2024-09-20 14:34:34 -10:00
parent 7d74834fb7
commit 100ce00a11
2 changed files with 19 additions and 2 deletions

View file

@ -17,9 +17,9 @@ class AwesomeDashboard extends Component {
this.action = useService("action"); this.action = useService("action");
this.rpc = useService('rpc'); this.stats = useService('awesome_dashboard.statistics');
onWillStart(async () => { onWillStart(async () => {
this.stats = await this.rpc("/awesome_dashboard/statistics"); this.stats = await this.stats.loadStatistics();
}); });
} }

View file

@ -0,0 +1,17 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { memoize } from "@web/core/utils/functions"
const statisticsService = {
dependencies: ["rpc"],
async: ["loadStatistics"],
start(env, { rpc }) {
return {
loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")),
};
},
};
registry.category("services").add("awesome_dashboard.statistics", statisticsService);