增加了对options中features的定义及实现
This commit is contained in:
parent
6b93deba6c
commit
2daed01a18
|
|
@ -1785,10 +1785,10 @@ var VirtualNode = /** @class */ (function (_super) {
|
||||||
if (child instanceof SingleNode || child instanceof ListNode) {
|
if (child instanceof SingleNode || child instanceof ListNode) {
|
||||||
var entity = child.getEntity();
|
var entity = child.getEntity();
|
||||||
if (child instanceof SingleNode) {
|
if (child instanceof SingleNode) {
|
||||||
(0, assert_1.assert)(path === entity || path.startsWith("".concat(entity, ":")), "oakPath\u300C".concat(path, "\u300D\u4E0D\u7B26\u5408\u547D\u540D\u89C4\u8303\uFF0C\u8BF7\u4EE5\u300C").concat(entity, "\u300D\u4E3A\u547D\u540D\u8D77\u59CB\u6807\u8BC6"));
|
(0, assert_1.assert)(path === entity || path.startsWith("".concat(entity, ":")), "oakPath\u300C".concat(path, "\u300D\u4E0D\u7B26\u5408\u547D\u540D\u89C4\u8303\uFF0C\u8BF7\u4EE5\u300C").concat(entity, ":\u300D\u4E3A\u547D\u540D\u8D77\u59CB\u6807\u8BC6"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(0, assert_1.assert)(path === "".concat(entity, "s") || path.startsWith("".concat(entity, "s:")), "oakPath\u300C".concat(path, "\u300D\u4E0D\u7B26\u5408\u547D\u540D\u89C4\u8303\uFF0C\u8BF7\u4EE5\u300C").concat(entity, "s\u300D\u4E3A\u547D\u540D\u8D77\u59CB\u6807\u8BC6"));
|
(0, assert_1.assert)(path === "".concat(entity, "s") || path.startsWith("".concat(entity, "s:")), "oakPath\u300C".concat(path, "\u300D\u4E0D\u7B26\u5408\u547D\u540D\u89C4\u8303\uFF0C\u8BF7\u4EE5\u300C").concat(entity, "s:\u300D\u4E3A\u547D\u540D\u8D77\u59CB\u6807\u8BC6"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -505,6 +505,9 @@ function createComponent(option, features) {
|
||||||
if (option.entity) {
|
if (option.entity) {
|
||||||
this.subscribed.push(features.cache.subscribe(function () { return _this.reRender(); }));
|
this.subscribed.push(features.cache.subscribe(function () { return _this.reRender(); }));
|
||||||
}
|
}
|
||||||
|
if (option.features) {
|
||||||
|
option.features.forEach(function (ele) { return _this.subscribed.push(features[ele].subscribe(function () { return _this.reRender(); })); });
|
||||||
|
}
|
||||||
attached && attached.call(this);
|
attached && attached.call(this);
|
||||||
},
|
},
|
||||||
detached: function () {
|
detached: function () {
|
||||||
|
|
|
||||||
|
|
@ -641,7 +641,11 @@ function createComponent(option, features) {
|
||||||
}
|
}
|
||||||
this.reRender();
|
this.reRender();
|
||||||
_a.label = 3;
|
_a.label = 3;
|
||||||
case 3: return [2 /*return*/];
|
case 3:
|
||||||
|
if (option.features) {
|
||||||
|
option.features.forEach(function (ele) { return _this.subscribed.push(features[ele].subscribe(function () { return _this.reRender(); })); });
|
||||||
|
}
|
||||||
|
return [2 /*return*/];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,26 @@ declare type FullPropertyToData<T extends AllFullProperty> = ValueType<T['type']
|
||||||
declare type PropertyOptionToData<P extends PropertyOption> = {
|
declare type PropertyOptionToData<P extends PropertyOption> = {
|
||||||
[name in keyof P]: PropertyToData<P[name]>;
|
[name in keyof P]: PropertyToData<P[name]>;
|
||||||
};
|
};
|
||||||
|
declare type CascadeEntity<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
|
||||||
|
aggr?: ED[T]['Aggregation'];
|
||||||
|
selection?: ED[T]['Selection'];
|
||||||
|
actions?: [
|
||||||
|
{
|
||||||
|
action: ED[T]['Action'];
|
||||||
|
filters?: Array<{
|
||||||
|
filter: ED[T]['Selection']['filter'];
|
||||||
|
'#name'?: string;
|
||||||
|
}>;
|
||||||
|
data?: Partial<ED[T]['CreateSingle']['data']>;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
interface ComponentOption<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, IsList extends boolean, TData extends DataOption, TProperty extends PropertyOption> {
|
interface ComponentOption<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, IsList extends boolean, TData extends DataOption, TProperty extends PropertyOption> {
|
||||||
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => T);
|
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => T);
|
||||||
path?: string;
|
path?: string;
|
||||||
isList: IsList;
|
isList: IsList;
|
||||||
|
features?: (keyof (FD & BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>))[];
|
||||||
|
cascadeEntities?: (this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => Record<keyof ED[T]['Schema'], CascadeEntity<ED, keyof ED>>;
|
||||||
projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => ED[T]['Selection']['data']);
|
projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => ED[T]['Selection']['data']);
|
||||||
append?: boolean;
|
append?: boolean;
|
||||||
pagination?: Pagination;
|
pagination?: Pagination;
|
||||||
|
|
|
||||||
|
|
@ -1777,10 +1777,10 @@ class VirtualNode<
|
||||||
if (child instanceof SingleNode || child instanceof ListNode) {
|
if (child instanceof SingleNode || child instanceof ListNode) {
|
||||||
const entity = child.getEntity() as string;
|
const entity = child.getEntity() as string;
|
||||||
if (child instanceof SingleNode) {
|
if (child instanceof SingleNode) {
|
||||||
assert(path === entity || path.startsWith(`${entity}:`), `oakPath「${path}」不符合命名规范,请以「${entity}」为命名起始标识`);
|
assert(path === entity || path.startsWith(`${entity}:`), `oakPath「${path}」不符合命名规范,请以「${entity}:」为命名起始标识`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(path === `${entity}s` || path.startsWith(`${entity}s:`), `oakPath「${path}」不符合命名规范,请以「${entity}s」为命名起始标识`);
|
assert(path === `${entity}s` || path.startsWith(`${entity}s:`), `oakPath「${path}」不符合命名规范,请以「${entity}s:」为命名起始标识`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -761,6 +761,15 @@ export function createComponent<
|
||||||
features.cache.subscribe(() => this.reRender())
|
features.cache.subscribe(() => this.reRender())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (option.features) {
|
||||||
|
option.features.forEach(
|
||||||
|
ele => this.subscribed.push(
|
||||||
|
features[ele].subscribe(
|
||||||
|
() => this.reRender()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
attached && attached.call(this);
|
attached && attached.call(this);
|
||||||
},
|
},
|
||||||
detached() {
|
detached() {
|
||||||
|
|
|
||||||
|
|
@ -906,6 +906,15 @@ export function createComponent<
|
||||||
}
|
}
|
||||||
this.reRender();
|
this.reRender();
|
||||||
}
|
}
|
||||||
|
if (option.features) {
|
||||||
|
option.features.forEach(
|
||||||
|
ele => this.subscribed.push(
|
||||||
|
features[ele].subscribe(
|
||||||
|
() => this.reRender()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ type ValueType<T extends PropertyType> = T extends null
|
||||||
? AnyObject
|
? AnyObject
|
||||||
: T extends FunctionConstructor
|
: T extends FunctionConstructor
|
||||||
? Function
|
? Function
|
||||||
:never
|
: never
|
||||||
type FullProperty<T extends PropertyType> = {
|
type FullProperty<T extends PropertyType> = {
|
||||||
/** 属性类型 */
|
/** 属性类型 */
|
||||||
type: T
|
type: T
|
||||||
|
|
@ -82,6 +82,21 @@ type PropertyOptionToData<P extends PropertyOption> = {
|
||||||
[name in keyof P]: PropertyToData<P[name]>
|
[name in keyof P]: PropertyToData<P[name]>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CascadeEntity<
|
||||||
|
ED extends EntityDict & BaseEntityDict,
|
||||||
|
T extends keyof ED> = {
|
||||||
|
aggr?: ED[T]['Aggregation'],
|
||||||
|
selection?: ED[T]['Selection'],
|
||||||
|
actions?: [{
|
||||||
|
action: ED[T]['Action'],
|
||||||
|
filters?: Array<{
|
||||||
|
filter: ED[T]['Selection']['filter'];
|
||||||
|
'#name'?: string;
|
||||||
|
}>;
|
||||||
|
data?: Partial<ED[T]['CreateSingle']['data']>;
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
interface ComponentOption<
|
interface ComponentOption<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
T extends keyof ED,
|
T extends keyof ED,
|
||||||
|
|
@ -93,10 +108,12 @@ interface ComponentOption<
|
||||||
IsList extends boolean,
|
IsList extends boolean,
|
||||||
TData extends DataOption,
|
TData extends DataOption,
|
||||||
TProperty extends PropertyOption,
|
TProperty extends PropertyOption,
|
||||||
> {
|
> {
|
||||||
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => T);
|
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => T);
|
||||||
path?: string;
|
path?: string;
|
||||||
isList: IsList;
|
isList: IsList;
|
||||||
|
features?: (keyof (FD & BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>))[];
|
||||||
|
cascadeEntities?: (this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => Record<keyof ED[T]['Schema'], CascadeEntity<ED, keyof ED>>,
|
||||||
projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => ED[T]['Selection']['data']);
|
projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => ED[T]['Selection']['data']);
|
||||||
append?: boolean;
|
append?: boolean;
|
||||||
pagination?: Pagination;
|
pagination?: Pagination;
|
||||||
|
|
@ -147,7 +164,7 @@ export type ComponentData<
|
||||||
T extends keyof ED,
|
T extends keyof ED,
|
||||||
FormedData extends DataOption,
|
FormedData extends DataOption,
|
||||||
TData extends DataOption
|
TData extends DataOption
|
||||||
> = TData & FormedData & OakComponentData<ED, T>;
|
> = TData & FormedData & OakComponentData<ED, T>;
|
||||||
|
|
||||||
export type ComponentPublicThisType<
|
export type ComponentPublicThisType<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
|
|
@ -162,7 +179,7 @@ export type ComponentPublicThisType<
|
||||||
TProperty extends PropertyOption = {},
|
TProperty extends PropertyOption = {},
|
||||||
TMethod extends MethodOption = {},
|
TMethod extends MethodOption = {},
|
||||||
EMethod extends Record<string, Function> = {}
|
EMethod extends Record<string, Function> = {}
|
||||||
> = {
|
> = {
|
||||||
subscribed: Array<() => void>;
|
subscribed: Array<() => void>;
|
||||||
features: FD & BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>;
|
features: FD & BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||||
state: ComponentData<ED, T, FormedData, TData>;
|
state: ComponentData<ED, T, FormedData, TData>;
|
||||||
|
|
@ -176,7 +193,7 @@ export type ComponentPublicThisType<
|
||||||
detail?: DetailType,
|
detail?: DetailType,
|
||||||
options?: WechatMiniprogram.Component.TriggerEventOption
|
options?: WechatMiniprogram.Component.TriggerEventOption
|
||||||
) => void;
|
) => void;
|
||||||
} & TMethod & EMethod & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
|
} & TMethod & EMethod & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
|
||||||
|
|
||||||
export type ComponentFullThisType<
|
export type ComponentFullThisType<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
|
|
@ -184,7 +201,7 @@ export type ComponentFullThisType<
|
||||||
IsList extends boolean,
|
IsList extends boolean,
|
||||||
Cxt extends AsyncContext<ED>,
|
Cxt extends AsyncContext<ED>,
|
||||||
FrontCxt extends SyncContext<ED>
|
FrontCxt extends SyncContext<ED>
|
||||||
> = {
|
> = {
|
||||||
subscribed: Array<() => void>;
|
subscribed: Array<() => void>;
|
||||||
features: BasicFeatures<ED, Cxt, FrontCxt, CommonAspectDict<ED, Cxt>>;
|
features: BasicFeatures<ED, Cxt, FrontCxt, CommonAspectDict<ED, Cxt>>;
|
||||||
state: OakComponentData<ED, T>;
|
state: OakComponentData<ED, T>;
|
||||||
|
|
@ -198,7 +215,7 @@ export type ComponentFullThisType<
|
||||||
detail?: DetailType,
|
detail?: DetailType,
|
||||||
options?: WechatMiniprogram.Component.TriggerEventOption
|
options?: WechatMiniprogram.Component.TriggerEventOption
|
||||||
) => void;
|
) => void;
|
||||||
} & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
|
} & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
|
||||||
|
|
||||||
export type OakComponentOption<
|
export type OakComponentOption<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
|
|
@ -213,7 +230,7 @@ export type OakComponentOption<
|
||||||
TProperty extends PropertyOption,
|
TProperty extends PropertyOption,
|
||||||
TMethod extends Record<string, Function>,
|
TMethod extends Record<string, Function>,
|
||||||
EMethod extends Record<string, Function> = {}
|
EMethod extends Record<string, Function> = {}
|
||||||
> = ComponentOption<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty> &
|
> = ComponentOption<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty> &
|
||||||
Partial<{
|
Partial<{
|
||||||
methods: TMethod;
|
methods: TMethod;
|
||||||
lifetimes: {
|
lifetimes: {
|
||||||
|
|
@ -273,7 +290,7 @@ export type OakNavigateToParameters<ED extends EntityDict & BaseEntityDict, T ex
|
||||||
export type OakCommonComponentMethods<
|
export type OakCommonComponentMethods<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
T extends keyof ED
|
T extends keyof ED
|
||||||
> = {
|
> = {
|
||||||
setDisablePulldownRefresh: (able: boolean) => void;
|
setDisablePulldownRefresh: (able: boolean) => void;
|
||||||
sub: (type: string, callback: Function) => void;
|
sub: (type: string, callback: Function) => void;
|
||||||
unsub: (type: string, callback: Function) => void;
|
unsub: (type: string, callback: Function) => void;
|
||||||
|
|
@ -326,7 +343,7 @@ export type OakCommonComponentMethods<
|
||||||
) => { operation: ED[T]['Operation']; entity: T }[] | undefined;
|
) => { operation: ED[T]['Operation']; entity: T }[] | undefined;
|
||||||
refresh: () => Promise<void>;
|
refresh: () => Promise<void>;
|
||||||
aggregate: (aggregation: ED[T]['Aggregation']) => Promise<AggregationResult<ED[T]['Schema']>>;
|
aggregate: (aggregation: ED[T]['Aggregation']) => Promise<AggregationResult<ED[T]['Schema']>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OakSingleComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
|
export type OakSingleComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
|
||||||
setId: (id: string) => void;
|
setId: (id: string) => void;
|
||||||
|
|
@ -377,7 +394,7 @@ export type OakComponentOnlyMethods = {
|
||||||
export type OakComponentData<
|
export type OakComponentData<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
T extends keyof ED
|
T extends keyof ED
|
||||||
> = {
|
> = {
|
||||||
oakExecutable: boolean | Error;
|
oakExecutable: boolean | Error;
|
||||||
oakExecuting: boolean;
|
oakExecuting: boolean;
|
||||||
oakFocused: {
|
oakFocused: {
|
||||||
|
|
@ -392,16 +409,16 @@ export type OakComponentData<
|
||||||
oakFullpath: string;
|
oakFullpath: string;
|
||||||
oakLegalActions?: ED[T]['Action'][];
|
oakLegalActions?: ED[T]['Action'][];
|
||||||
oakDisablePulldownRefresh: boolean;
|
oakDisablePulldownRefresh: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OakListComoponetData<
|
export type OakListComoponetData<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
T extends keyof ED
|
T extends keyof ED
|
||||||
> = {
|
> = {
|
||||||
oakFilters?: NonNullable<ED[T]['Selection']['filter']>[];
|
oakFilters?: NonNullable<ED[T]['Selection']['filter']>[];
|
||||||
oakSorters?: NonNullable<ED[T]['Selection']['sorter']>[];
|
oakSorters?: NonNullable<ED[T]['Selection']['sorter']>[];
|
||||||
oakPagination?: Pagination;
|
oakPagination?: Pagination;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MakeOakComponent<
|
export type MakeOakComponent<
|
||||||
ED extends EntityDict & BaseEntityDict,
|
ED extends EntityDict & BaseEntityDict,
|
||||||
|
|
@ -409,14 +426,14 @@ export type MakeOakComponent<
|
||||||
FrontCxt extends SyncContext<ED>,
|
FrontCxt extends SyncContext<ED>,
|
||||||
AD extends Record<string, Aspect<ED, Cxt>>,
|
AD extends Record<string, Aspect<ED, Cxt>>,
|
||||||
FD extends Record<string, Feature>
|
FD extends Record<string, Feature>
|
||||||
> = <
|
> = <
|
||||||
T extends keyof ED,
|
T extends keyof ED,
|
||||||
FormedData extends DataOption,
|
FormedData extends DataOption,
|
||||||
IsList extends boolean,
|
IsList extends boolean,
|
||||||
TData extends DataOption,
|
TData extends DataOption,
|
||||||
TProperty extends PropertyOption,
|
TProperty extends PropertyOption,
|
||||||
TMethod extends MethodOption
|
TMethod extends MethodOption
|
||||||
>(
|
>(
|
||||||
options: OakComponentOption<
|
options: OakComponentOption<
|
||||||
ED,
|
ED,
|
||||||
T,
|
T,
|
||||||
|
|
@ -430,7 +447,7 @@ export type MakeOakComponent<
|
||||||
TProperty,
|
TProperty,
|
||||||
TMethod
|
TMethod
|
||||||
>
|
>
|
||||||
) => React.ComponentType<any>;
|
) => React.ComponentType<any>;
|
||||||
|
|
||||||
// 暴露给组件的方法
|
// 暴露给组件的方法
|
||||||
export type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh' | 'aggregate' | 'checkOperation';
|
export type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh' | 'aggregate' | 'checkOperation';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue