import { ReplicatedData } from '.'; import { Serializable } from '../serializable'; /** @public */ export declare namespace ReplicatedMap { /** * Generator for default values. * * @remarks * * This is invoked by get when the current map has no Replicated Data defined for the key. * * If this returns a Replicated Data object, it will be added to the map. * * Care should be taken when using this, since it means that the get method can trigger elements to be created. If * using default values, the get method should not be used in queries where an empty value for the Replicated Data * means the value is not present. * * @typeParam Key - Type of keys for the Replicated Map * @typeParam Value - Type of values for the Replicated Map * @param key - The key the default value is being generated for * @returns The default value, or undefined if no default value should be returned */ type DefaultValueCallback = (key: Key) => Value | undefined; /** * Callback for handling elements iterated through by {@link ReplicatedMap.forEach}. * * @typeParam Key - Type of keys for the Replicated Map * @typeParam Value - Type of values for the Replicated Map * @param value - The Replicated Data value * @param key - The key * @param map - This Replicated Map */ type ForEachCallback = (value: Value, key: Key, map: ReplicatedMap) => void; } /** * A Replicated Map data type. * * @remarks * * ReplicatedMaps are a mapping of keys (which can be any {@link Serializable}) to Replicated Data * types. Values of the map are merged together. Elements can be added and removed, however, when an * element is removed and then added again, it's possible that the old value will be merged with the * new, depending on whether the remove was replicated to all nodes before the add was. * * Note that while the map may contain different types of Replicated Data for different keys, a * given key may not change its type, and doing so will likely result in the Replicated Data * entering a non mergable state, from which it can't recover. * * @typeParam Key - Type of keys for the Replicated Map * @typeParam Value - Type of values for the Replicated Map * * @public */ export declare class ReplicatedMap implements ReplicatedData, Iterable<[Key, Value]> { private currentValue; private delta; /** * Generator for default values. * * @remarks * * This is invoked by get when the current map has no Replicated Data defined for the key. * * If this returns a Replicated Data object, it will be added to the map. * * Care should be taken when using this, since it means that the get method can trigger elements to be created. If * using default values, the get method should not be used in queries where an empty value for the Replicated Data * means the value is not present. */ defaultValue: ReplicatedMap.DefaultValueCallback; /** * Check whether this map contains a value of the given key. * * @param key - The key to check * @returns True if this map contains a value of the given key */ has: (key: Key) => boolean; /** * The number of entries in this map. */ get size(): number; /** * Execute the given callback for each element. * * @param callback - The callback to handle each element */ forEach: (callback: ReplicatedMap.ForEachCallback) => void; /** * Return an (iterable) iterator of the entries of this map. * * @returns (iterable) iterator of map entries */ entries: () => IterableIterator<[Key, Value]>; /** * Return an iterator of the entries of this map. * * @returns iterator of map entries */ [Symbol.iterator]: () => IterableIterator<[Key, Value]>; /** * Return an iterator of the values of this map. * * @returns iterator of map values */ values: () => IterableIterator; /** * Return an iterator of the keys of this map. * * @returns iterator of map keys */ keys: () => IterableIterator; /** * Get the value at the given key. * * @param key - The key to get * @returns The Replicated Data value, or undefined if no value is defined at that key */ get: (key: Key) => Value | undefined; private untyped; private asObjectProxy; /** * A representation of this map as an object. * * @remarks * * All entries whose keys are strings will be properties of this object, and setting any property of the object will * insert that property as a key into the map. */ get asObject(): { [key: string]: Value; }; /** * Set the given value for the given key. * * @param key - The key to set * @param value - The value to set * @returns This map */ set: (key: Key, value: Value) => ReplicatedMap; /** * Delete the value at the given key. * * @param key - The key to delete. * @returns This map */ delete: (key: Key) => ReplicatedMap; /** * Clear all entries from this map. * * @returns This map */ clear: () => ReplicatedMap; toString: () => string; }