mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add action cache to action manager
This commit is contained in:
@@ -43,6 +43,8 @@ export function actionManagerMixin<T extends ReturnType<typeof rpcMixin>>(
|
|||||||
Base: T
|
Base: T
|
||||||
) {
|
) {
|
||||||
return class extends Base {
|
return class extends Base {
|
||||||
|
actionCache: { [key: number]: Promise<ActionDescription> } = {};
|
||||||
|
|
||||||
async doAction(request: ActionRequest) {
|
async doAction(request: ActionRequest) {
|
||||||
if (typeof request === "number") {
|
if (typeof request === "number") {
|
||||||
await this.loadAction(request);
|
await this.loadAction(request);
|
||||||
@@ -68,13 +70,16 @@ export function actionManagerMixin<T extends ReturnType<typeof rpcMixin>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAction(id: number) {
|
loadAction(id: number): Promise<ActionDescription> {
|
||||||
return this.rpc({
|
if (id in this.actionCache) {
|
||||||
|
return this.actionCache[id];
|
||||||
|
}
|
||||||
|
return (this.actionCache[id] = this.rpc({
|
||||||
route: "web/action/load",
|
route: "web/action/load",
|
||||||
params: {
|
params: {
|
||||||
action_id: id
|
action_id: id
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { makeTestStore } from "../helpers";
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Tests
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
test("does not reload action if already done", async () => {
|
||||||
|
const routes: string[] = [];
|
||||||
|
const store = makeTestStore({ rpc: async route => routes.push(route) });
|
||||||
|
expect(routes).toEqual([]);
|
||||||
|
|
||||||
|
store.doAction(32);
|
||||||
|
|
||||||
|
expect(routes).toEqual(["web/action/load"]);
|
||||||
|
|
||||||
|
store.doAction(32);
|
||||||
|
|
||||||
|
expect(routes).toEqual(["web/action/load"]);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user