Browse Source

Merge pull request #1138 in VISUAL/fineui from ~TELLER/fineui:master to master

* commit '8e4dd67cf53faf79b2ce04a3547b7159fd786029':
  refactor: 去掉多余代码
es6
Teller 5 years ago
parent
commit
e749e713d2
  1. 70
      typescript/index.ts

70
typescript/index.ts

@ -33,73 +33,3 @@ export interface _BI extends _func, _i18n, _base {
HighlightBehavior: ClassConstructor<_HighlightBehavior>;
RedMarkBehavior: ClassConstructor<_RedMarkBehavior>;
}
interface Obj {
[key: string]: any;
}
declare let BI: Obj & _BI;
declare const Fix: Obj;
export type Constructor<T> = new(...args: any[]) => T;
/**
* widget
*/
export function shortcut () {
return function decorator<U> (Target: Constructor<U> & {xtype: string}): void {
BI.shortcut(Target.xtype, Target);
};
}
/**
* model
*/
export function model () {
return function decorator<U extends {new (...args:any[]):{}} & {xtype: string, context?: ReadonlyArray<string>}>(Target: U): void {
BI.model(Target.xtype, class extends Target {
context = Target.context;
});
};
}
/**
* _store属性
* @param Model model类
* @param opts
*/
export function store<T> (Model?: Constructor<T> & {xtype: string}, opts: { props?(this: unknown): { [key: string]: unknown } } = {}) {
return function classDecorator<U extends {new (...args:any[]):{}}>(constructor:U) {
return class extends constructor {
_store () {
const props = opts.props ? opts.props.apply(this) : undefined;
return BI.Models.getModel(Model.xtype, props);
}
};
};
}
/**
* Model基类
*/
export class Model<U extends {types?: {[key: string]: any}, context?: ReadonlyArray<string>} = {}> extends Fix.Model {
model: Pick<{[key in keyof U["types"]]: U["types"][key]}, U["context"][number]> & {[key in keyof ReturnType<this["state"]>]: ReturnType<this["state"]>[key]} & {[key in keyof this["computed"]]: ReturnType<this["computed"][key]>} & {[key: string]: unknown};
store: this["actions"];
state (): {[key: string]: any} {
return {};
}
context: U["context"];
actions:{[key: string]: (...args: any[]) => any};
childContext: ReadonlyArray<keyof (this["computed"] & ReturnType<this["state"]>)>;
TYPE: Pick<{[key in keyof this["computed"]]: ReturnType<this["computed"][key]>} & {[key in keyof ReturnType<this["state"]>]: ReturnType<this["state"]>[key]}, this["childContext"][number]>;
computed: {[key: string]: () => any};
}

Loading…
Cancel
Save