增加了对options中features的定义及实现

This commit is contained in:
Xu Chang 2023-02-19 12:17:19 +08:00
parent 6b93deba6c
commit 2daed01a18
8 changed files with 192 additions and 134 deletions

View File

@ -1785,10 +1785,10 @@ var VirtualNode = /** @class */ (function (_super) {
if (child instanceof SingleNode || child instanceof ListNode) {
var entity = child.getEntity();
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 {
(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"));
}
}
};

View File

@ -505,6 +505,9 @@ function createComponent(option, features) {
if (option.entity) {
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);
},
detached: function () {

View File

@ -641,7 +641,11 @@ function createComponent(option, features) {
}
this.reRender();
_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*/];
}
});
});

16
lib/types/Page.d.ts vendored
View File

@ -38,10 +38,26 @@ declare type FullPropertyToData<T extends AllFullProperty> = ValueType<T['type']
declare type PropertyOptionToData<P extends PropertyOption> = {
[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> {
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => T);
path?: string;
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']);
append?: boolean;
pagination?: Pagination;

View File

@ -1777,10 +1777,10 @@ class VirtualNode<
if (child instanceof SingleNode || child instanceof ListNode) {
const entity = child.getEntity() as string;
if (child instanceof SingleNode) {
assert(path === entity || path.startsWith(`${entity}:`), `oakPath「${path}」不符合命名规范,请以「${entity}」为命名起始标识`);
assert(path === entity || path.startsWith(`${entity}:`), `oakPath「${path}」不符合命名规范,请以「${entity}:」为命名起始标识`);
}
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:」为命名起始标识`);
}
}
}

View File

@ -761,6 +761,15 @@ export function createComponent<
features.cache.subscribe(() => this.reRender())
);
}
if (option.features) {
option.features.forEach(
ele => this.subscribed.push(
features[ele].subscribe(
() => this.reRender()
)
)
);
}
attached && attached.call(this);
},
detached() {

View File

@ -906,6 +906,15 @@ export function createComponent<
}
this.reRender();
}
if (option.features) {
option.features.forEach(
ele => this.subscribed.push(
features[ele].subscribe(
() => this.reRender()
)
)
);
}
}
componentWillUnmount() {

View File

@ -82,6 +82,21 @@ type PropertyOptionToData<P extends PropertyOption> = {
[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<
ED extends EntityDict & BaseEntityDict,
T extends keyof ED,
@ -97,6 +112,8 @@ interface ComponentOption<
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty>) => T);
path?: string;
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']);
append?: boolean;
pagination?: Pagination;