UNPKG

@farris/devkit-vue

Version:
181 lines (180 loc) 4.61 kB
import { Type } from '../common/index'; import { EntitySchema } from './entity-schema/index'; import { EntityPath } from './entity-path/index'; import { EntityChange, EntityChangeHistory } from './entity-change/index'; import { Entity } from './entity'; import { EntityList } from './entity-list'; import { EntityStateQuery } from './entity-state-query'; import { EntityStateUpdater } from './entity-state-updater'; import { EntityPagination, Pagination } from './types'; /** * 实体状态 */ declare abstract class EntityState<T extends Entity> { /** * 副作用管理器 */ private effectManager; private entityPagination; /** * 实体描述 */ protected entitySchema: EntitySchema; /** * 根实体列表 */ protected entityList: EntityList<T>; /** * 实体类型 */ entityType: Type<T>; /** * 实体状态查询器 */ entityQuery: EntityStateQuery; /** * 实体更新器 */ entityUpdater: EntityStateUpdater; /** * 变更历史记录 */ entityChangeHistory: EntityChangeHistory; /** * 构造函数 */ constructor(entityType: Type<T>); /** * 获取实体列表 */ getEntityList(): EntityList<T>; /** * 根据path获取实体列表 */ getEntityListByPath(path: string | EntityPath): EntityList<Entity>; /** * 获取根实体集合 */ getEntities(): T[]; /** * 根据Path获取根实体集合 */ getEntitiesByPath(path: string | EntityPath): T[]; /** * 根据ID获取根实体 */ getEntityById(id: string): T | undefined; /** * 根据Path获取实体 */ getEntityByPath(path: string | EntityPath): T | undefined; /** * 根据Path获取字段值 */ getValueByPath(path: string | EntityPath): any; /** * 根据ID获取根实体 */ getCurrentEntity(): T; /** * 根据Path获取实体 */ getCurrentEntityByPath(path: string | EntityPath): Entity; /** * 加载根实体集合 */ loadEntities(entities: T[]): void; /** * 根据Path加载实体集合 */ loadEntitesByPath(path: string | EntityPath, entities: Entity[]): void; /** * 加载根实体集合 */ appendEntities(entities: T[]): void; /** * 根据Path加载实体集合 */ appendEntitesByPath(path: string | EntityPath, entities: Entity[]): void; /** * 根据ID删除根实体 */ removeEntityById(id: string): void; /** * 根据父Paht和ID删除实体 */ removeEntityByPath(path: string | EntityPath, id: string): void; /** * 根据ID批量删除根实体 */ removeEntitiesByIds(ids: string[]): void; /** * 根据path和ID批量删除实体 */ removeEntitiesByPath(path: string | EntityPath, ids: string[]): void; /** * 根据ID更新实体 */ updateEntityById(id: string, values: any): void; /** * 根据Path更新实体 */ updateEntityByPath(path: string, values: any): void; /** * 根据path更新字段值 */ setValueByPath(path: string, value: any): void; /** * 设置当前根实体 */ changeCurrentEntityById(id: string): void; /** * 根据Path设置当前实体 */ changeCurrentEntityByPath(path: string | EntityPath, id: string): void; /** * 构造实体路径 */ createPath(path: string | string[] | EntityPath, isEntityListPath?: boolean): EntityPath; /** * 触发变更 */ triggerChanges(change: EntityChange): void; /** * 监听变更 */ watchChanges(changeEffectFunc: (change: EntityChange) => void): Function; /** * 获取实体类型 */ getEntityType(): Type<T>; /** * 获取实体结构描述 */ getEntitySchema(): EntitySchema; /** * 更新实体分页配置 * @param entityPagination */ setEntityPagination(entityPagination: EntityPagination): void; /** * 获取实体分页配置 * @returns */ getEntityPagination(): EntityPagination; /** * 更新指定实体分页信息 * @param path * @param pagination */ setPaginationByPath(path: string | string[] | EntityPath, pagination: Partial<Pagination>): void; getPaginationByPath(path: string | string[] | EntityPath): Pagination; /** * 转换为JSON */ toJSON(): { entityList: any[]; currentEntity: any; }; } export { EntityState };