mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add comments, add debug flag to environment
This commit is contained in:
@@ -1,13 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* We define here a simple event bus: it can
|
||||||
|
* - emit events
|
||||||
|
* - add/remove listeners.
|
||||||
|
*
|
||||||
|
* This is a useful pattern of communication in some cases.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Types
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
export type Callback = (...args: any[]) => void;
|
export type Callback = (...args: any[]) => void;
|
||||||
|
|
||||||
interface Subscription {
|
export interface Subscription {
|
||||||
owner: any;
|
owner: any;
|
||||||
callback: Callback;
|
callback: Callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//------------------------------------------------------------------------------
|
||||||
* Simple event bus: it can emit events, and add/remove listeners.
|
// EventBus
|
||||||
*/
|
//------------------------------------------------------------------------------
|
||||||
export class EventBus {
|
export class EventBus {
|
||||||
private subscriptions: { [eventType: string]: Subscription[] } = {};
|
private subscriptions: { [eventType: string]: Subscription[] } = {};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import { idGenerator } from "./core/utils";
|
|||||||
import { WEnv } from "./core/widget";
|
import { WEnv } from "./core/widget";
|
||||||
import { ActionManager, IActionManager } from "./services/action_manager";
|
import { ActionManager, IActionManager } from "./services/action_manager";
|
||||||
import { Ajax, IAjax } from "./services/ajax";
|
import { Ajax, IAjax } from "./services/ajax";
|
||||||
import { Router, IRouter } from "./services/router";
|
import { IRouter, Router } from "./services/router";
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Types
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
export interface Menu {
|
export interface Menu {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -11,13 +15,23 @@ export interface Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Env extends WEnv {
|
export interface Env extends WEnv {
|
||||||
|
// services
|
||||||
actionManager: IActionManager;
|
actionManager: IActionManager;
|
||||||
ajax: IAjax;
|
ajax: IAjax;
|
||||||
router: IRouter;
|
router: IRouter;
|
||||||
menus: Menu[];
|
menus: Menu[];
|
||||||
|
|
||||||
|
// helpers
|
||||||
rpc: IAjax["rpc"];
|
rpc: IAjax["rpc"];
|
||||||
|
|
||||||
|
// configuration
|
||||||
|
debug: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Code
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
export function makeEnvironment(): Env {
|
export function makeEnvironment(): Env {
|
||||||
const qweb = new QWeb();
|
const qweb = new QWeb();
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
@@ -33,13 +47,12 @@ export function makeEnvironment(): Env {
|
|||||||
qweb,
|
qweb,
|
||||||
getID: idGenerator(),
|
getID: idGenerator(),
|
||||||
|
|
||||||
// services
|
|
||||||
ajax,
|
ajax,
|
||||||
router,
|
router,
|
||||||
actionManager,
|
actionManager,
|
||||||
menus,
|
menus,
|
||||||
|
|
||||||
// helpers
|
rpc: ajax.rpc,
|
||||||
rpc: ajax.rpc
|
debug: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,25 +5,29 @@ import { CRM } from "../widgets/crm";
|
|||||||
import { Discuss } from "../widgets/discuss";
|
import { Discuss } from "../widgets/discuss";
|
||||||
import { Query, IRouter } from "./router";
|
import { Query, IRouter } from "./router";
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Types
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
interface Type<T> extends Function {
|
interface Type<T> extends Function {
|
||||||
new (...args: any[]): T;
|
new (...args: any[]): T;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ClientAction {
|
export interface ClientAction {
|
||||||
type: "client";
|
type: "client";
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ActWindowAction {
|
export interface ActWindowAction {
|
||||||
type: "act_window";
|
type: "act_window";
|
||||||
views: string[];
|
views: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionEvent = "action_ready";
|
export type ActionEvent = "action_ready";
|
||||||
|
|
||||||
export interface IActionManager {
|
export interface IActionManager {
|
||||||
doAction(actionID: number);
|
doAction(actionID: number): void;
|
||||||
on(event: ActionEvent, owner: any, callback: Callback);
|
on(event: ActionEvent, owner: any, callback: Callback): void;
|
||||||
getCurrentAction(): ActionWidget | null;
|
getCurrentAction(): ActionWidget | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +44,10 @@ const actions: any[] = [
|
|||||||
{ id: 2, title: "CRM", Widget: CRM }
|
{ id: 2, title: "CRM", Widget: CRM }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Action Manager
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
export class ActionManager extends EventBus implements IActionManager {
|
export class ActionManager extends EventBus implements IActionManager {
|
||||||
router: IRouter;
|
router: IRouter;
|
||||||
currentAction: ActionWidget | null = null;
|
currentAction: ActionWidget | null = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user