2019-02-06 15:08:24 +01:00
|
|
|
import { IAjax } from "../services/ajax";
|
2019-02-05 14:39:45 +01:00
|
|
|
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";
|
2019-02-04 21:09:17 +01:00
|
|
|
|
2019-02-05 14:39:45 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Types
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
export interface Env extends WEnv {
|
|
|
|
|
// services
|
|
|
|
|
actionManager: IActionManager;
|
|
|
|
|
ajax: IAjax;
|
|
|
|
|
notifications: INotificationManager;
|
|
|
|
|
router: IRouter;
|
|
|
|
|
|
|
|
|
|
// registries
|
|
|
|
|
actionRegistry: Registry<ActionWidget>;
|
|
|
|
|
|
|
|
|
|
// helpers
|
|
|
|
|
rpc: IAjax["rpc"];
|
2019-02-05 08:56:33 +01:00
|
|
|
|
2019-02-05 14:39:45 +01:00
|
|
|
// configuration
|
|
|
|
|
debug: boolean;
|
|
|
|
|
isMobile: boolean;
|
2019-02-05 08:56:33 +01:00
|
|
|
}
|
2019-02-05 14:39:45 +01:00
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Widget classes
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
export class Widget<Props, State> extends Component<Env, Props, State> {}
|
|
|
|
|
|
2019-02-06 10:15:07 +01:00
|
|
|
export class PureWidget<P, S> extends PureComponent<Env, P, S> {
|
|
|
|
|
constructor(parent, props) {
|
|
|
|
|
super(parent, props);
|
|
|
|
|
(<any>this.__widget__).isMobile = this.env.isMobile;
|
|
|
|
|
}
|
|
|
|
|
shouldUpdate(nextProps: P): boolean {
|
|
|
|
|
if ((<any>this.__widget__).isMobile !== this.env.isMobile) {
|
|
|
|
|
(<any>this.__widget__).isMobile = this.env.isMobile;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.shouldUpdate(nextProps);
|
|
|
|
|
}
|
|
|
|
|
}
|