move Env definition to Widget

This commit is contained in:
Géry Debongnie
2019-02-05 14:39:45 +01:00
parent 3fd00f72af
commit 311141a9e3
7 changed files with 72 additions and 75 deletions
+37 -21
View File
@@ -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
> {}