UNPKG

simpleddp-node

Version:

The aim of this library is to simplify the process of working with meteor server over DDP protocol using external JS environments

125 lines (124 loc) 3.9 kB
import { ddpReducer } from './ddpReducer.js'; import { ddpReactiveDocument } from './ddpReactiveDocument.js'; import { ddpCollection } from './ddpCollection'; /** * A reactive collection class. */ export declare class ddpReactiveCollection<T> { private _skip; private _limit; private _sort; private _length; private _data; private _rawData; private _reducers; private _tickers; private _ones; private _first; private _syncFunc; private _changeHandler; private started; constructor(ddpCollectionInstance: ddpCollection<T>, settings?: { skip?: number; limit?: number; sort?: false | ((a: T, b: T) => number); }, filter?: boolean | ((value: T, index: number, array: T[]) => any)); /** * Removes document from the local collection copies. */ private _removeItem; /** * Adds document to local the collection this._rawData according to used sorting if specified. */ private _smartUpdate; /** * Adds reducer. */ private _activateReducer; /** * Adds reactive object. */ private _activateReactiveObject; /** * Removes reducer. */ private _deactivateReducer; /** * Removes reactive object. */ private _deactivateReactiveObject; /** * Sends new object state for every associated reactive object. */ _updateReactiveObjects(): void; /** * Updates ddpReactiveCollection settings. */ settings(settings: { skip?: number; limit?: typeof Infinity; sort?: false | ((a: T, b: T) => number); }): this; /** * Updates the skip parameter only. */ skip(n: number): this; /** * Updates the limit parameter only. */ limit(n: number): this; /** * Stops reactivity. Also stops associated reactive objects. */ stop(): void; /** * Starts reactivity. This method is being called on instance creation. * Also starts every associated reactive object. */ start(): void; /** * Sorts local collection according to specified function. * Specified function form {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort}. * @public * @param {Function} f - A function used for sorting. * @return {this} */ sort(f: false | ((a: T, b: T) => number)): this; /** * Returns reactive local collection with applied sorting, skip and limit. * This returned array is being mutated within this class instance. * @public * @return {Array} - Local collection with applied sorting, skip and limit. */ data(): Array<any>; /** * Runs a function every time a change occurs. * @param {Function} f - Function which recieves new collection at each change. * @public */ onChange(f: {}): { start: () => void; stop: () => void; }; /** * Maps reactive local collection to another reactive array. * Specified function form {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map}. * @public */ map<T, R>(f: (arg0: T, arg1?: number, arg2?: T[]) => R): ddpReducer<[accumulator: any[], el: any, i: number, a: any[]], any[], never[], T_1>; /** * Reduces reactive local collection. * Specified function form {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce}. */ reduce(f: (args_0: any[], args_1: any, args_2: number, args_3: any[]) => unknown, initialValue: any): ddpReducer<[args_0: any[], args_1: any, args_2: number, args_3: any[]], unknown, any, T>; /** * Reactive length of the local collection. */ count(): object; /** * Returns a reactive object which fields are always the same as the first object in the collection. */ one(settings: { preserve: any; } | null): ddpReactiveDocument<T>; }