增加了aggregate方法

This commit is contained in:
Xu Chang 2023-01-07 19:50:59 +08:00
parent eff364b78b
commit fa8f9933c2
9 changed files with 57 additions and 4 deletions

View File

@ -16,6 +16,7 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends A
data: Partial<ED[T]['Schema']>[];
count?: number | undefined;
}>;
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): Promise<any>;
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option?: OP, callback?: (result: Awaited<ReturnType<AD['operate']>>) => void): Promise<any>;
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter'>, option?: OP, callback?: (result: Awaited<ReturnType<AD['count']>>) => void): Promise<any>;
private sync;

View File

@ -61,6 +61,23 @@ var Cache = /** @class */ (function (_super) {
});
});
};
Cache.prototype.aggregate = function (entity, aggregation, option) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var result;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.exec('aggregate', {
entity: entity,
aggregation: aggregation,
option: option,
})];
case 1:
result = _a.sent();
return [2 /*return*/, result];
}
});
});
};
Cache.prototype.operate = function (entity, operation, option, callback) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {

View File

@ -375,6 +375,16 @@ var oakBehavior = Behavior({
remove: function (beforeExecute, afterExecute) {
return this.features.runningTree.remove(this.state.oakFullpath, beforeExecute, afterExecute);
},
aggregate: function (aggregation) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.features.cache.aggregate(this.state.oakEntity, aggregation)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
},
},
observers: {
oakPath: function (data) {

View File

@ -360,6 +360,9 @@ function createComponent(option, features) {
execute: function (action, messageProps) {
return _this.execute(action, messageProps);
},
aggregate: function (aggregation) {
return _this.features.cache.aggregate(_this.state.oakEntity, aggregation);
},
refresh: function () {
return _this.refresh();
},

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

@ -1,6 +1,6 @@
/// <reference types="wechat-miniprogram" />
/// <reference types="react" />
import { Aspect, EntityDict, DeduceSorterItem, CheckerType } from "oak-domain/lib/types";
import { Aspect, EntityDict, DeduceSorterItem, CheckerType, AggregationResult } from "oak-domain/lib/types";
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { CommonAspectDict } from 'oak-common-aspect';
import { Feature } from './Feature';
@ -156,6 +156,7 @@ export declare type OakCommonComponentMethods<ED extends EntityDict & BaseEntity
entity: T;
}[] | undefined;
refresh: () => Promise<void>;
aggregate: (aggregation: ED[T]['Aggregation']) => Promise<AggregationResult<ED[T]['Schema']>>;
};
export declare type OakSingleComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
setId: (id: string) => void;
@ -212,7 +213,7 @@ export declare type OakComponentData<ED extends EntityDict & BaseEntityDict, T e
oakDisablePulldownRefresh: boolean;
};
export declare type MakeOakComponent<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature>> = <T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption>(options: OakComponentOption<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod>) => React.ComponentType<any>;
export declare type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh';
export declare type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh' | 'aggregate';
export declare type WebComponentListMethodNames = 'loadMore' | 'setFilters' | 'addNamedFilter' | 'removeNamedFilter' | 'removeNamedFilterByName' | 'setNamedSorters' | 'addNamedSorter' | 'removeNamedSorter' | 'removeNamedSorterByName' | 'setPageSize' | 'setCurrentPage' | 'addItem' | 'removeItem' | 'updateItem';
export declare type WebComponentSingleMethodNames = 'update' | 'remove';
export declare type WebComponentProps<ED extends EntityDict & BaseEntityDict, T extends keyof ED, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}> = {

View File

@ -78,6 +78,20 @@ export class Cache<
};
}
async aggregate<T extends keyof ED, OP extends SelectOption>(
entity: T,
aggregation: ED[T]['Aggregation'],
option?: OP,
) {
const result = await this.exec('aggregate', {
entity,
aggregation,
option,
});
return result;
}
async operate<T extends keyof ED, OP extends OperateOption>(
entity: T,
operation: ED[T]['Operation'],

View File

@ -564,6 +564,9 @@ const oakBehavior = Behavior<
afterExecute
);
},
async aggregate(aggregation) {
return await this.features.cache.aggregate(this.state.oakEntity, aggregation);
},
},
observers: {
oakPath(data) {

View File

@ -615,6 +615,9 @@ export function createComponent<
) => {
return this.execute(action, messageProps);
},
aggregate: (aggregation: ED[T]['Aggregation']) => {
return this.features.cache.aggregate(this.state.oakEntity, aggregation);
},
refresh: () => {
return this.refresh();
},

View File

@ -1,4 +1,4 @@
import { Aspect, EntityDict, DeduceSorterItem, CheckerType } from "oak-domain/lib/types";
import { Aspect, EntityDict, DeduceSorterItem, CheckerType, AggregationResult } from "oak-domain/lib/types";
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { CommonAspectDict } from 'oak-common-aspect';
import { Feature } from './Feature';
@ -264,6 +264,7 @@ export type OakCommonComponentMethods<
path?: string
) => { operation: ED[T]['Operation']; entity: T }[] | undefined;
refresh: () => Promise<void>;
aggregate: (aggregation: ED[T]['Aggregation']) => Promise<AggregationResult<ED[T]['Schema']>>;
};
export type OakSingleComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
@ -370,7 +371,7 @@ export type MakeOakComponent<
) => React.ComponentType<any>;
// 暴露给组件的方法
export type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh';
export type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh' | 'aggregate';
// 暴露给list组件的方法
export type WebComponentListMethodNames = 'loadMore' | 'setFilters' | 'addNamedFilter' | 'removeNamedFilter' | 'removeNamedFilterByName' | 'setNamedSorters'