import { CreateStatePersistentConfigInterface, EnhancedState, StateIngestConfigInterface, StateObserversInterface } from '../../state'; import type { Collection, DefaultItem, ItemKey } from '../collection'; import { GroupIngestConfigInterface, GroupObserver } from './group.observer'; import type { Item } from '../item'; export declare class Group extends EnhancedState> { collection: () => Collection; static rebuildGroupSideEffectKey: string; _output: Array; nextGroupOutput: Array; _preciseItemKeys: Array; observers: GroupObservers; notFoundItemKeys: Array; loadedInitialValue: boolean; /** * An extension of the State Class that categorizes and preserves the ordering of structured data. * It allows us to cluster together data from a Collection as an array of Item keys. * * Note that a Group doesn't store the actual Items. It only keeps track of the Item keys * and retrieves the fitting Items when needed. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/) * * @public * @param collection - Collection to which the Group belongs. * @param initialItems - Key/Name identifiers of the Items to be clustered by the Group. * @param config - Configuration object */ constructor(collection: Collection, initialItems?: Array, config?: GroupConfigInterface); /** * Returns the values of the Items clustered by the Group. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/properties#output) * * @public */ get output(): Array; set output(value: DataType[]); /** * Returns a boolean indicating whether an Item with the specified `itemKey` * is clustered in the Group or not. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/methods/#has) * * @public * @param itemKey - Key/Name identifier of the Item. */ has(itemKey: ItemKey): boolean; /** * Returns the count of Items clustered by the Group. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/properties#size) * * @public */ get size(): number; /** * Removes an Item with the specified key/name identifier from the Group, * if it exists in the Group. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/methods#remove) * * @public * @param itemKeys - Key/Name identifier/s of the Item/s to be removed. * @param config - Configuration object */ remove(itemKeys: ItemKey | ItemKey[], config?: GroupRemoveConfigInterface): this; /** * Appends new Item/s to the end of the Group. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/methods#add) * * @public * @param itemKeys - Key/Name identifier/s of Item/s to be added. * @param config - Configuration object */ add(itemKeys: ItemKey | ItemKey[], config?: GroupAddConfigInterface): this; /** * Replaces the old `itemKey` with a new specified `itemKey`. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/methods#replace) * * @public * @param oldItemKey - Old `itemKey` to be replaced. * @param newItemKey - New `itemKey` to replace the before specified old `itemKey`. * @param config - Configuration object */ replace(oldItemKey: ItemKey, newItemKey: ItemKey, config?: StateIngestConfigInterface): this; /** * Retrieves all existing Items of the Group from the corresponding Collection and returns them. * Items that aren't present in the Collection are skipped. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/methods#getitems) * * @public */ getItems(): Array>; /** * Preserves the Group `value` in the corresponding external Storage. * * The Group key/name is used as the unique identifier for the Persistent. * If that is not desired or the Group has no unique identifier, * please specify a separate unique identifier for the Persistent. * * [Learn more..](https://agile-ts.org/docs/core/state/methods/#persist) * * @public * @param config - Configuration object */ persist(config?: GroupPersistConfigInterface>): this; /** * Rebuilds the output of the Group * and ingests it into the runtime. * * In doing so, it traverses the Group `value` (Item identifiers) * and fetches the fitting Items accordingly. * * [Learn more..](https://agile-ts.org/docs/core/collection/group/methods#rebuild) * * @internal * @param trackedChanges - Changes that were tracked between two rebuilds. * @param config - Configuration object */ rebuild(trackedChanges?: TrackedChangeInterface[], config?: GroupIngestConfigInterface): this; } export declare type GroupKey = string | number; export interface GroupObservers extends StateObserversInterface { /** * Observer responsible for the output of the Group. */ output: GroupObserver; } export interface GroupAddConfigInterface extends StateIngestConfigInterface { /** * In which way the `itemKey` should be added to the Group. * - 'push' = at the end * - 'unshift' = at the beginning * https://www.tutorialspoint.com/what-are-the-differences-between-unshift-and-push-methods-in-javascript * @default 'push' */ method?: 'unshift' | 'push'; /** * Whether to soft rebuild the Group. * -> only rebuild the parts of the Group that have actually changed * instead of rebuilding the whole Group. * @default true */ softRebuild?: boolean; } export interface GroupRemoveConfigInterface extends StateIngestConfigInterface { /** * Whether to soft rebuild the Group. * -> only rebuild the parts of the Group that have actually changed * instead of rebuilding the whole Group. * @default true */ softRebuild?: boolean; } export interface GroupConfigInterface { /** * Key/Name identifier of the Group. * @default undefined */ key?: GroupKey; /** * Whether the Group should be a placeholder * and therefore should only exist in the background. * @default false */ isPlaceholder?: boolean; } export interface GroupPersistConfigInterface extends CreateStatePersistentConfigInterface { /** * Whether to format the specified Storage key following the Collection Group Storage key pattern. * `_${collectionKey}_group_${groupKey}` * @default true */ followCollectionPersistKeyPattern?: boolean; } export declare enum TrackedChangeMethod { ADD = 0, REMOVE = 1, UPDATE = 2 } export interface TrackedChangeInterface { /** * What type of change the tracked change is. * @default undefined */ method: TrackedChangeMethod; /** * Item key of the tracked change. * @default undefined */ key: ItemKey; /** * Current index in the Group value of the tracked change. * @default undefined */ index: number; }