mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add registry
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { QWeb } from "./core/qweb_vdom";
|
||||
import { idGenerator, memoize } from "./core/utils";
|
||||
import { WEnv } from "./core/widget";
|
||||
import { registry } from "./registry";
|
||||
import { ActionManager, IActionManager } from "./services/action_manager";
|
||||
import { Ajax, IAjax } from "./services/ajax";
|
||||
import { IRouter, Router } from "./services/router";
|
||||
@@ -46,7 +47,7 @@ export const makeEnvironment = memoize(function(): Env {
|
||||
const qweb = new QWeb();
|
||||
const router = new Router();
|
||||
const ajax = new Ajax();
|
||||
const actionManager = new ActionManager(router);
|
||||
const actionManager = new ActionManager(router, registry);
|
||||
const menus = [
|
||||
{ title: "Discuss", actionID: 1 },
|
||||
{ title: "CRM", actionID: 2 }
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
///<amd-module name="main" />
|
||||
|
||||
import { RootWidget } from "./widgets/root_widget";
|
||||
import { makeEnvironment } from "./env";
|
||||
import { registry } from "./registry";
|
||||
import { Discuss } from "./widgets/discuss";
|
||||
import { RootWidget } from "./widgets/root_widget";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Prepare application registry
|
||||
//------------------------------------------------------------------------------
|
||||
registry.addAction("discuss", Discuss);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Application bootstrapping
|
||||
//------------------------------------------------------------------------------
|
||||
document.addEventListener("DOMContentLoaded", async function() {
|
||||
const env = makeEnvironment();
|
||||
const rootWidget = new RootWidget(env);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Widget } from "./core/widget";
|
||||
import { Env } from "./env";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
interface Type<T> extends Function {
|
||||
new (...args: any[]): T;
|
||||
}
|
||||
|
||||
type ActionWidget = Type<Widget<Env>>;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Registry code
|
||||
//------------------------------------------------------------------------------
|
||||
export class Registry {
|
||||
actions: { [key: string]: ActionWidget } = {};
|
||||
|
||||
addAction(name: string, action: ActionWidget): Registry {
|
||||
return this.addToRegistry(this.actions, name, action);
|
||||
}
|
||||
|
||||
private addToRegistry<T>(
|
||||
map: { [k: string]: T },
|
||||
name: string,
|
||||
elem: T
|
||||
): Registry {
|
||||
if (name in map) {
|
||||
throw new Error(`Key ${name} already exists!`);
|
||||
}
|
||||
map[name] = elem;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export const registry = new Registry();
|
||||
@@ -1,6 +1,7 @@
|
||||
import { EventBus, Callback } from "../core/event_bus";
|
||||
import { Widget } from "../core/widget";
|
||||
import { Env } from "../env";
|
||||
import { Registry } from "../registry";
|
||||
import { CRM } from "../widgets/crm";
|
||||
import { Discuss } from "../widgets/discuss";
|
||||
import { Query, IRouter } from "./router";
|
||||
@@ -50,11 +51,13 @@ const actions: any[] = [
|
||||
|
||||
export class ActionManager extends EventBus implements IActionManager {
|
||||
router: IRouter;
|
||||
registry: Registry;
|
||||
currentAction: ActionWidget | null = null;
|
||||
|
||||
constructor(router: IRouter) {
|
||||
constructor(router: IRouter, registry: Registry) {
|
||||
super();
|
||||
this.router = router;
|
||||
this.registry = registry;
|
||||
const query = this.router.getQuery();
|
||||
this.update(query);
|
||||
this.router.on("query_changed", this, this.update);
|
||||
|
||||
Reference in New Issue
Block a user