mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
move registry to services
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { EventBus } from "../core/event_bus";
|
||||
import { Widget } from "../core/widget";
|
||||
import { Env } from "../env";
|
||||
import { Registry } from "../registry";
|
||||
import { Registry } from "./registry";
|
||||
import { Type } from "../types";
|
||||
import { IRouter, Query } from "./router";
|
||||
|
||||
@@ -65,6 +65,7 @@ export class ActionManager extends EventBus implements IActionManager {
|
||||
this.router.on("query_changed", this, this.update);
|
||||
this.update(this.router.getQuery());
|
||||
}
|
||||
|
||||
doAction(request: ActionRequest) {
|
||||
if (typeof request === "number") {
|
||||
// this is an action ID
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Widget } from "../core/widget";
|
||||
import { Env } from "../env";
|
||||
import { Type } from "../types";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type ActionWidget = Type<Widget<Env, {}>>;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Registry code
|
||||
//------------------------------------------------------------------------------
|
||||
export class Registry {
|
||||
registries: { [key: string]: { [key: string]: any } } = {
|
||||
action: {}
|
||||
};
|
||||
|
||||
add(type: "action", name: string, action: ActionWidget): Registry {
|
||||
if (name in this.registries[type]) {
|
||||
throw new Error(`Key ${name} already exists!`);
|
||||
}
|
||||
this.registries[type][name] = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
getAction(name: string): ActionWidget {
|
||||
return this.registries.action[name];
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Main registry instance
|
||||
//------------------------------------------------------------------------------
|
||||
export const registry = new Registry();
|
||||
Reference in New Issue
Block a user