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:
@@ -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
|
||||
> {}
|
||||
|
||||
Reference in New Issue
Block a user