mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
move Env definition to Widget
This commit is contained in:
@@ -269,3 +269,26 @@ export class Component<
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class PureComponent<T extends WEnv, Props, State> extends Component<
|
||||
T,
|
||||
Props,
|
||||
State
|
||||
> {
|
||||
shouldUpdate(nextProps: Props): boolean {
|
||||
for (let k in nextProps) {
|
||||
if (nextProps[k] !== this.props[k]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
async updateState(nextState: Partial<State>) {
|
||||
for (let k in nextState) {
|
||||
if (nextState[k] !== this.state[k]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return super.updateState(nextState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,11 @@
|
||||
import { Ajax, IAjax } from "./core/ajax";
|
||||
import { WEnv } from "./core/component";
|
||||
import {
|
||||
INotificationManager,
|
||||
NotificationManager
|
||||
} from "./core/notifications";
|
||||
import { Ajax } from "./core/ajax";
|
||||
import { NotificationManager } from "./core/notifications";
|
||||
import { QWeb } from "./core/qweb_vdom";
|
||||
import { Registry } from "./core/registry";
|
||||
import { IRouter, Router } from "./core/router";
|
||||
import { Router } from "./core/router";
|
||||
import { idGenerator, memoize } from "./core/utils";
|
||||
import { actionRegistry } from "./registries";
|
||||
import {
|
||||
ActionManager,
|
||||
ActionWidget,
|
||||
IActionManager
|
||||
} from "./services/action_manager";
|
||||
import { CRM } from "./widgets/crm";
|
||||
import { Discuss } from "./widgets/discuss";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export interface Menu {
|
||||
title: string;
|
||||
actionID: number;
|
||||
}
|
||||
|
||||
export interface Env extends WEnv {
|
||||
// services
|
||||
actionManager: IActionManager;
|
||||
ajax: IAjax;
|
||||
notifications: INotificationManager;
|
||||
router: IRouter;
|
||||
|
||||
// registries
|
||||
actionRegistry: Registry<ActionWidget>;
|
||||
|
||||
// helpers
|
||||
rpc: IAjax["rpc"];
|
||||
|
||||
// configuration
|
||||
debug: boolean;
|
||||
isMobile: boolean;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Code
|
||||
//------------------------------------------------------------------------------
|
||||
import { ActionManager } from "./services/action_manager";
|
||||
import { Env } from "./widgets/widget";
|
||||
|
||||
/**
|
||||
* makeEnvironment returns the main environment for the application.
|
||||
@@ -59,9 +18,6 @@ export interface Env extends WEnv {
|
||||
* this function will actually return the same environment.
|
||||
*/
|
||||
export const makeEnvironment = memoize(async function(): Promise<Env> {
|
||||
// main application registry
|
||||
actionRegistry.add("discuss", Discuss).add("crm", CRM);
|
||||
|
||||
// services
|
||||
const qweb = new QWeb();
|
||||
const router = new Router();
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Registry } from "./core/registry";
|
||||
import { ActionWidget } from "./services/action_manager";
|
||||
import { CRM } from "./widgets/crm";
|
||||
import { Discuss } from "./widgets/discuss";
|
||||
|
||||
export const actionRegistry: Registry<ActionWidget> = new Registry();
|
||||
|
||||
actionRegistry.add("discuss", Discuss).add("crm", CRM);
|
||||
|
||||
@@ -1,24 +1,40 @@
|
||||
import { Component } from "../core/component";
|
||||
import { Env } from "../env";
|
||||
import { IAjax } from "../core/ajax";
|
||||
import { Component, PureComponent, WEnv } from "../core/component";
|
||||
import { INotificationManager } from "../core/notifications";
|
||||
import { Registry } from "../core/registry";
|
||||
import { IRouter } from "../core/router";
|
||||
import { ActionWidget, IActionManager } from "../services/action_manager";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export interface Env extends WEnv {
|
||||
// services
|
||||
actionManager: IActionManager;
|
||||
ajax: IAjax;
|
||||
notifications: INotificationManager;
|
||||
router: IRouter;
|
||||
|
||||
// registries
|
||||
actionRegistry: Registry<ActionWidget>;
|
||||
|
||||
// helpers
|
||||
rpc: IAjax["rpc"];
|
||||
|
||||
// configuration
|
||||
debug: boolean;
|
||||
isMobile: boolean;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Widget classes
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export class Widget<Props, State> extends Component<Env, Props, State> {}
|
||||
|
||||
// TODO: move this to PureComponent in core
|
||||
export class PureWidget<Props, State> extends Widget<Props, State> {
|
||||
shouldUpdate(nextProps: Props): boolean {
|
||||
for (let k in nextProps) {
|
||||
if (nextProps[k] !== this.props[k]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
async updateState(nextState: Partial<State>) {
|
||||
for (let k in nextState) {
|
||||
if (nextState[k] !== this.state[k]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return super.updateState(nextState);
|
||||
}
|
||||
}
|
||||
export class PureWidget<Props, State> extends PureComponent<
|
||||
Env,
|
||||
Props,
|
||||
State
|
||||
> {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { QWeb } from "../src/ts/core/qweb_vdom";
|
||||
import { idGenerator } from "../src/ts/core/utils";
|
||||
import { WEnv } from "../src/ts/core/component";
|
||||
import { Env } from "../src/ts/env";
|
||||
import { Env } from "../src/ts/widgets/widget";
|
||||
import { IAjax, RPCQuery } from "../src/ts/core/ajax";
|
||||
import { Registry } from "../src/ts/core/registry";
|
||||
import { NotificationManager } from "../src/ts/core/notifications";
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Env } from "../../src/ts/env";
|
||||
import { HomeMenu, Props } from "../../src/ts/widgets/home_menu";
|
||||
import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
|
||||
|
||||
@@ -7,7 +6,7 @@ import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
let fixture: HTMLElement;
|
||||
let env: Env;
|
||||
let env: ReturnType<typeof makeTestEnv>;
|
||||
let props: Props;
|
||||
let templates: string;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Env } from "../../src/ts/env";
|
||||
import { INotification } from "../../src/ts/core/notifications";
|
||||
import { Notification } from "../../src/ts/widgets/notification";
|
||||
import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
|
||||
@@ -8,7 +7,7 @@ import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
let fixture: HTMLElement;
|
||||
let env: Env;
|
||||
let env: ReturnType<typeof makeTestEnv>;
|
||||
let templates: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
|
||||
Reference in New Issue
Block a user