适配了oak-domain声明的简化
This commit is contained in:
parent
abc5533b3e
commit
f8bfec396e
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDict, StorageSchema, OpRecord, DeduceSorterItem, AspectWrapper } from "oak-domain/lib/types";
|
||||
import { EntityDict, StorageSchema, OpRecord, AspectWrapper } from "oak-domain/lib/types";
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
import { NamedFilterItem, NamedSorterItem } from "../types/NamedCondition";
|
||||
|
|
@ -37,7 +37,7 @@ declare abstract class Node<ED extends EntityDict & BaseEntityDict, T extends ke
|
|||
isExecuting(): boolean;
|
||||
setExecuting(executing: boolean): void;
|
||||
getParent(): SingleNode<ED, keyof ED, Cxt, FrontCxt, AD> | ListNode<ED, T, Cxt, FrontCxt, AD> | VirtualNode<ED, Cxt, FrontCxt, AD> | undefined;
|
||||
protected getProjection(): ED[T]["Selection"]["data"];
|
||||
protected getProjection(): any;
|
||||
protected judgeRelation(attr: string): string | 0 | 1 | 2 | string[];
|
||||
protected contains(filter: ED[T]['Selection']['filter'], conditionalFilter: ED[T]['Selection']['filter']): boolean;
|
||||
protected repel(filter1: ED[T]['Selection']['filter'], filter2: ED[T]['Selection']['filter']): boolean;
|
||||
|
|
@ -97,7 +97,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
|
|||
constructSelection(withParent?: true): {
|
||||
data: ED[T]["Selection"]["data"];
|
||||
filter: ED[T]["Selection"]["filter"] | {};
|
||||
sorter: DeduceSorterItem<ED[T]["Schema"]>[];
|
||||
sorter: ED[T]["Selection"]["sorter"];
|
||||
validParentFilter: boolean;
|
||||
};
|
||||
refresh(pageNumber?: number, getCount?: true, append?: boolean): Promise<void>;
|
||||
|
|
@ -134,7 +134,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
|
|||
entity: T;
|
||||
operation: ED[T]['Operation'];
|
||||
}> | undefined;
|
||||
getProjection(withDecendants?: boolean): ED[T]["Selection"]["data"];
|
||||
getProjection(withDecendants?: boolean): any;
|
||||
refresh(): Promise<void>;
|
||||
clean(): void;
|
||||
getFilter(disableOperation?: boolean): ED[T]['Selection']['filter'] | undefined;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { EntityDict } from "oak-domain/lib/types";
|
||||
import { DeduceSorterItem } from "oak-domain/lib/types/Entity";
|
||||
export declare type NamedFilterItem<ED extends EntityDict, T extends keyof ED> = {
|
||||
filter: ED[T]['Selection']['filter'] | (() => ED[T]['Selection']['filter'] | undefined);
|
||||
['#name']?: string;
|
||||
};
|
||||
export declare type NamedSorterItem<ED extends EntityDict, T extends keyof ED> = {
|
||||
sorter: DeduceSorterItem<ED[T]['Schema']> | (() => DeduceSorterItem<ED[T]['Schema']> | undefined);
|
||||
sorter: NonNullable<ED[T]['Selection']['sorter']>[number] | (() => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined);
|
||||
['#name']?: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference types="wechat-miniprogram" />
|
||||
/// <reference types="react" />
|
||||
import { Aspect, EntityDict, DeduceSorterItem, CheckerType, AggregationResult } from "oak-domain/lib/types";
|
||||
import { Aspect, EntityDict, 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';
|
||||
|
|
@ -31,11 +31,11 @@ interface ComponentOption<ED extends EntityDict & BaseEntityDict, T extends keyo
|
|||
'#name'?: string;
|
||||
}>;
|
||||
sorters?: Array<{
|
||||
sorter: DeduceSorterItem<ED[T]['Schema']> | ((options: {
|
||||
sorter: NonNullable<ED[T]['Selection']['sorter']>[number] | ((options: {
|
||||
features: BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>> & FD;
|
||||
props: Partial<WechatMiniprogram.Component.PropertyOptionToData<TProperty>>;
|
||||
state: Record<string, any>;
|
||||
}) => DeduceSorterItem<ED[T]['Schema']>);
|
||||
}) => NonNullable<ED[T]['Selection']['sorter']>[number]);
|
||||
'#name'?: string;
|
||||
}>;
|
||||
formData?: (options: {
|
||||
|
|
@ -175,7 +175,7 @@ export declare type OakListComponentMethods<ED extends EntityDict & BaseEntityDi
|
|||
removeNamedFilterByName: (name: string, refresh?: boolean) => void;
|
||||
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => void;
|
||||
getSorters: () => ED[T]['Selection']['sorter'] | undefined;
|
||||
getSorterByName: (name: string) => DeduceSorterItem<ED[T]['Schema']> | undefined;
|
||||
getSorterByName: (name: string) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined;
|
||||
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
|
||||
removeNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
|
||||
removeNamedSorterByName: (name: string, refresh?: boolean) => void;
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export default class CheckerExecutor<ED extends EntityDict & BaseEntityDict,Cxt
|
|||
if (filter) {
|
||||
const filterr = typeof filter === 'function' ? filter(operation, context, {}) : filter;
|
||||
assert(!(filter instanceof Promise), `对${entity as string}的动作${action}上定义的checker,其filter返回了Promise,请注意将同步和异步的返回区分对待`);
|
||||
const isRepel = checkFilterRepel(entity, context, filterr, operation.filter, true);
|
||||
const isRepel = checkFilterRepel<ED, T, Cxt>(entity, context, filterr, operation.filter, true);
|
||||
assert(typeof isRepel === 'boolean');
|
||||
if (isRepel) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -147,8 +147,8 @@ function initializeWatchers<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|||
try {
|
||||
if (w.hasOwnProperty('actionData')) {
|
||||
const { entity, action, filter, actionData } = <BBWatcher<ED, keyof ED>>w;
|
||||
const filter2 = typeof filter === 'function' ? await filter() : filter;
|
||||
const data = typeof actionData === 'function' ? await (actionData as any)() : actionData; // 这里有个奇怪的编译错误,不理解 by Xc
|
||||
const filter2 = typeof filter === 'function' ? await (filter as Function)() : filter;
|
||||
const data = typeof actionData === 'function' ? await (actionData as Function)() : actionData; // 这里有个奇怪的编译错误,不理解 by Xc
|
||||
const result = await store.operate(entity, {
|
||||
id: await generateNewIdAsync(),
|
||||
action,
|
||||
|
|
@ -162,8 +162,8 @@ function initializeWatchers<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|||
}
|
||||
else {
|
||||
const { entity, projection, fn, filter } = <WBWatcher<ED, keyof ED, Cxt>>w;
|
||||
const filter2 = typeof filter === 'function' ? await filter() : filter;
|
||||
const projection2 = typeof projection === 'function' ? await projection() : projection;
|
||||
const filter2 = typeof filter === 'function' ? await (filter as Function)() : filter;
|
||||
const projection2 = typeof projection === 'function' ? await (projection as Function)() : projection;
|
||||
const rows = await store.select(entity, {
|
||||
data: projection2 as any,
|
||||
filter: filter2,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { cloneDeep, pull, unset, merge, uniq } from "oak-domain/lib/utils/lodash
|
|||
import { addFilterSegment, combineFilters, contains, repel, same } from "oak-domain/lib/store/filter";
|
||||
import { createOperationsFromModies } from 'oak-domain/lib/store/modi';
|
||||
import { judgeRelation } from "oak-domain/lib/store/relation";
|
||||
import { EntityDict, StorageSchema, OpRecord, CreateOpResult, RemoveOpResult, DeduceSorterItem, AspectWrapper } from "oak-domain/lib/types";
|
||||
import { EntityDict, StorageSchema, OpRecord, CreateOpResult, RemoveOpResult, AspectWrapper } from "oak-domain/lib/types";
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ abstract class Node<
|
|||
}
|
||||
|
||||
protected getProjection() {
|
||||
return typeof this.projection === 'function' ? this.projection() : cloneDeep(this.projection);
|
||||
return typeof this.projection === 'function' ? (this.projection as Function)() : cloneDeep(this.projection);
|
||||
}
|
||||
|
||||
protected judgeRelation(attr: string) {
|
||||
|
|
@ -822,7 +822,7 @@ class ListNode<
|
|||
if (operation.action === 'create') {
|
||||
const { data } = operation;
|
||||
assert(!(data instanceof Array));
|
||||
createdIds.push(data.id);
|
||||
createdIds.push(data.id!);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -989,7 +989,7 @@ class ListNode<
|
|||
if (!this.dirty) {
|
||||
return;
|
||||
}
|
||||
const childOperations: Record<string, ED[T]['Update']> = {};
|
||||
const childOperations: Record<string, ED[T]['Operation']> = {};
|
||||
for (const id in this.children) {
|
||||
const childOperation = this.children[id].composeOperations();
|
||||
if (childOperation) {
|
||||
|
|
@ -1037,14 +1037,14 @@ class ListNode<
|
|||
const sorterArr = sorters.map((ele) => {
|
||||
const { sorter } = ele;
|
||||
if (typeof sorter === 'function') {
|
||||
return sorter();
|
||||
return (sorter as Function)();
|
||||
}
|
||||
return sorter;
|
||||
}).filter((ele) => !!ele) as DeduceSorterItem<ED[T]['Schema']>[];
|
||||
}).filter((ele) => !!ele) as ED[T]['Selection']['sorter'];
|
||||
const filterArr = filters.map((ele) => {
|
||||
const { filter } = ele;
|
||||
if (typeof filter === 'function') {
|
||||
return filter();
|
||||
return (filter as Function)();
|
||||
}
|
||||
return filter;
|
||||
});
|
||||
|
|
@ -1434,7 +1434,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
return;
|
||||
}
|
||||
const filter = this.getFilter();
|
||||
const operation: ED[T]['Update'] = this.operation ? cloneDeep(this.operation.operation) : {
|
||||
const operation: ED[T]['Operation'] = this.operation ? cloneDeep(this.operation.operation) : {
|
||||
id: generateNewId(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export async function onPathSet<
|
|||
filter:
|
||||
typeof filter === 'function'
|
||||
? () =>
|
||||
filter.call(this, {
|
||||
(filter as Function).call(this, {
|
||||
features,
|
||||
props: this.props,
|
||||
state: this.state,
|
||||
|
|
@ -57,7 +57,7 @@ export async function onPathSet<
|
|||
if (!proj && projection) {
|
||||
proj = typeof projection === 'function'
|
||||
? () =>
|
||||
projection.call(this, {
|
||||
(projection as Function).call(this, {
|
||||
features,
|
||||
props: this.props,
|
||||
state: this.state,
|
||||
|
|
@ -76,7 +76,7 @@ export async function onPathSet<
|
|||
sorter:
|
||||
typeof sorter === 'function'
|
||||
? () =>
|
||||
sorter.call(this, {
|
||||
(sorter as Function).call(this, {
|
||||
features,
|
||||
props: this.props,
|
||||
state: this.state,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/// <reference path="../node_modules/@types/wechat-miniprogram/index.d.ts" />
|
||||
import assert from 'assert';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
import { Aspect, Context, DeduceSorterItem, EntityDict } from 'oak-domain/lib/types';
|
||||
import { Aspect, EntityDict } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { BasicFeatures } from './features';
|
||||
import { Feature } from './types/Feature';
|
||||
|
|
@ -439,10 +439,8 @@ const oakBehavior = Behavior<
|
|||
}
|
||||
return sorter;
|
||||
})
|
||||
.filter((ele) => !!ele) as DeduceSorterItem<
|
||||
EDD[keyof EDD]['Schema']
|
||||
>[];
|
||||
return sorters;
|
||||
.filter((ele) => !!ele);
|
||||
return sorters as EDD[keyof EDD]['Selection']['sorter'];
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import React from 'react';
|
|||
import { withRouter, PullToRefresh } from './platforms/web';
|
||||
import { get } from 'oak-domain/lib/utils/lodash';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
import { Action, Aspect, CheckerType, DeduceSorterItem, EntityDict } from 'oak-domain/lib/types';
|
||||
import { Action, Aspect, CheckerType, EntityDict } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { BasicFeatures } from './features';
|
||||
import { NamedFilterItem, NamedSorterItem } from './types/NamedCondition';
|
||||
|
|
@ -374,7 +374,7 @@ abstract class OakComponentBase<
|
|||
);
|
||||
const filters = namedFilters.map(({ filter }) => {
|
||||
if (typeof filter === 'function') {
|
||||
return filter();
|
||||
return (filter as Function)();
|
||||
}
|
||||
return filter;
|
||||
});
|
||||
|
|
@ -390,7 +390,7 @@ abstract class OakComponentBase<
|
|||
);
|
||||
if (filter?.filter) {
|
||||
if (typeof filter.filter === 'function') {
|
||||
return filter.filter();
|
||||
return (filter.filter as Function)();
|
||||
}
|
||||
return filter.filter;
|
||||
}
|
||||
|
|
@ -436,11 +436,11 @@ abstract class OakComponentBase<
|
|||
const sorters = namedSorters
|
||||
.map(({ sorter }) => {
|
||||
if (typeof sorter === 'function') {
|
||||
return sorter();
|
||||
return (sorter as Function)();
|
||||
}
|
||||
return sorter;
|
||||
})
|
||||
.filter((ele) => !!ele) as DeduceSorterItem<ED[T]['Schema']>[];
|
||||
.filter((ele) => !!ele) as ED[T]['Selection']['sorter'][];
|
||||
return sorters;
|
||||
}
|
||||
}
|
||||
|
|
@ -453,7 +453,7 @@ abstract class OakComponentBase<
|
|||
);
|
||||
if (sorter?.sorter) {
|
||||
if (typeof sorter.sorter === 'function') {
|
||||
return sorter.sorter();
|
||||
return (sorter.sorter as Function)();
|
||||
}
|
||||
return sorter.sorter;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { EntityDict } from "oak-domain/lib/types";
|
||||
import { DeduceSorterItem } from "oak-domain/lib/types/Entity";
|
||||
|
||||
export type NamedFilterItem<ED extends EntityDict, T extends keyof ED> = {
|
||||
filter: ED[T]['Selection']['filter'] | (() => ED[T]['Selection']['filter'] | undefined);
|
||||
|
|
@ -7,6 +6,6 @@ export type NamedFilterItem<ED extends EntityDict, T extends keyof ED> = {
|
|||
};
|
||||
|
||||
export type NamedSorterItem<ED extends EntityDict, T extends keyof ED> = {
|
||||
sorter: DeduceSorterItem<ED[T]['Schema']> | (() => DeduceSorterItem<ED[T]['Schema']> | undefined);
|
||||
sorter: NonNullable<ED[T]['Selection']['sorter']>[number] | (() => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined);
|
||||
['#name']?: string;
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Aspect, EntityDict, DeduceSorterItem, CheckerType, AggregationResult } from "oak-domain/lib/types";
|
||||
import { Aspect, EntityDict, 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';
|
||||
|
|
@ -41,11 +41,11 @@ interface ComponentOption<
|
|||
'#name'?: string;
|
||||
}>;
|
||||
sorters?: Array<{
|
||||
sorter: DeduceSorterItem<ED[T]['Schema']> | ((options: {
|
||||
sorter: NonNullable<ED[T]['Selection']['sorter']>[number] | ((options: {
|
||||
features: BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>> & FD;
|
||||
props: Partial<WechatMiniprogram.Component.PropertyOptionToData<TProperty>>;
|
||||
state: Record<string, any>;
|
||||
}) => DeduceSorterItem<ED[T]['Schema']>)
|
||||
}) => NonNullable<ED[T]['Selection']['sorter']>[number])
|
||||
'#name'?: string;
|
||||
}>;
|
||||
formData?: (options: {
|
||||
|
|
@ -293,7 +293,7 @@ export type OakListComponentMethods<ED extends EntityDict & BaseEntityDict, T ex
|
|||
getSorters: () => ED[T]['Selection']['sorter'] | undefined;
|
||||
getSorterByName: (
|
||||
name: string
|
||||
) => DeduceSorterItem<ED[T]['Schema']> | undefined;
|
||||
) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined;
|
||||
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
|
||||
removeNamedSorter: (
|
||||
filter: NamedSorterItem<ED, T>,
|
||||
|
|
|
|||
Loading…
Reference in New Issue