import { IDictionary, IRawModel } from 'datx-utils'; import { IObservableArray } from 'mobx'; import { IIdentifier } from './interfaces/IIdentifier'; import { IModelConstructor } from './interfaces/IModelConstructor'; import { IRawCollection } from './interfaces/IRawCollection'; import { IType } from './interfaces/IType'; import { TFilterFn } from './interfaces/TFilterFn'; import { PureModel } from './PureModel'; export declare class PureCollection { /** * List of models available in the collection * * @static * @type {Array} * @memberof Collection */ static types: Array; static views: IDictionary<{ modelType: IType | PureModel; sortMethod?: string | ((PureModel: any) => any); unique?: boolean; mixins?: Array<(view: any) => any>; }>; static defaultModel?: typeof PureModel; private readonly __data; private readonly __views; private __dataMap; private __dataList; constructor(data?: Array | IRawCollection); /** * Function for inserting raw models into the collection. Used when hydrating the collection * * @param {Array} data Raw model data * @returns {Array} A list of initialized models * @memberof Collection */ insert(data: Array>): Array; /** * Add an existing model to the collection * * @template T * @param {T} data Model to be added * @returns {T} Added model * @memberof Collection */ add(data: T): T; /** * Add an array of existing models to the collection * * @template T * @param {Array} data Array of models to be added * @returns {Array} Added models * @memberof Collection */ add(data: Array): Array; /** * Add an array of new models to the collection * * @template T * @param {Array} data Array of new data to be added * @param {(IType|IModelConstructor)} model Model type to be added * @returns {Array} Added models * @memberof Collection */ add(data: Array, model: IType | IModelConstructor): Array; /** * Add a new model to the collection * * @template T * @param {(IRawModel|IDictionary)} data New data to be added * @param {(IType|IModelConstructor)} model Model type to be added * @returns {T} Added model * @memberof Collection */ add(data: IRawModel | IDictionary, model: IType | IModelConstructor): T; /** * Find a model based on the defined type and identifier * * @param {(IType|typeof PureModel|PureModel)} type Model type * @param {IIdentifier} id Model identifier * @returns {(PureModel|null)} The first matching model * @memberof Collection */ findOne(type: IType | T | IModelConstructor, id: IIdentifier | PureModel): T | null; /** * Find a model based on the defined type and (optional) identifier * * @deprecated Use `findOne` instead * @param {(IType|typeof PureModel|PureModel)} type Model type * @param {IIdentifier} [id] Model identifier * @returns {(PureModel|null)} The first matching model * @memberof Collection */ find(type: IType | T | IModelConstructor, id?: IIdentifier | PureModel): T | null; /** * Find a model based on a matching function * * @param {TFilterFn} test Function used to match the model * @returns {(PureModel|null)} The first matching model * @memberof Collection */ find(test: TFilterFn): T | null; /** * Filter models based on a matching function * * @param {TFilterFn} test Function used to match the models * @returns {(PureModel|null)} The matching models * @memberof Collection */ filter(test: TFilterFn): Array; /** * Find all matching models or all models if no type is given * * @param {(IType|typeof PureModel)} [model] Model type to select * @returns {Array} List of matching models * @memberof Collection */ findAll(model?: IType | IModelConstructor): IObservableArray; /** * Check if a model is in the collection * * @param {PureModel} model Model to check * @returns {boolean} The given model is in the collection * @memberof Collection */ hasItem(model: PureModel): boolean; /** * Remove the model based on the type and identifier * * @param {(IType|typeof PureModel)} type Model type * @param {IIdentifier} id Model identifier * @memberof Collection */ removeOne(type: IType | typeof PureModel, id: IIdentifier): any; /** * Remove the given model from the collection * * @param {PureModel} model Model to be removed from the collection * @memberof Collection */ removeOne(model: PureModel): any; /** * Remove the first model based on the type and (optional) identifier * * @deprecated Use `removeOne` instead * @param {(IType|typeof PureModel)} type Model type * @param {IIdentifier} [id] Model identifier * @memberof Collection */ remove(type: IType | typeof PureModel, id?: IIdentifier): any; /** * Remove the given model from the collection * * @deprecated Use `removeOne` instead * @param {PureModel} model Model to be removed from the collection * @memberof Collection */ remove(model: PureModel): any; /** * Remove all models of the given model type from the collection * * @param {(IType|typeof PureModel)} type Model type * @memberof Collection */ removeAll(type: IType | typeof PureModel): void; /** * A total count of models in the collection * * @readonly * @type {number} * @memberof Collection */ readonly length: number; /** * Get the serializable value of the collection * * @returns {IRawCollection} Pure JS value of the collection * @memberof Collection */ toJSON(): IRawCollection; readonly snapshot: IRawCollection; /** * Reset the collection (remove all models) * * @memberof Collection */ reset(): void; getAllModels(): PureModel[]; /** * Add a view to the collection * * @template T Model type of the view * @param {string} name View name * @param {(IModelConstructor|IType)} type Model type the view will represent * @param {({ * sortMethod?: string|((item: T) => any), * models?: Array, * unique?: boolean, * mixins?: Array<(view: any) => any>, * })} [{sortMethod, models, unique, mixins}={}] View options * @returns {View} The created view * @memberof PureCollection */ addView(name: string, type: IModelConstructor | IType, { sortMethod, models, unique, mixins, }?: { sortMethod?: string | ((item: T) => any); models?: Array; unique?: boolean; mixins?: Array<(view: any) => any>; }): any; private __addArray; private __addSingle; private __insertModel; private __removeModel; private __findOneByType; private __findByType; private __changeModelId; }