MapKernel Class
Packages > @fluidframework/map > MapKernel
A SharedMap is a map-like distributed data structure.
Signature:
export declare class MapKernel implements IValueTypeCreator
Implements: IValueTypeCreator
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(runtime, handle, submitMessage, isAttached, valueTypes, eventEmitter) | Create a new shared map kernel. |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
eventEmitter | TypedEventEmitter<ISharedMapEvents> | ||
size | number | The number of key/value pairs stored in the map. |
Methods
Method | Modifiers | Description |
---|---|---|
[Symbol.iterator]() | Get an iterator over the entries in this map. | |
clear() | Clear all data from the map. | |
createValueType(key, type, params) | Create a new value type at the given key. | |
delete(key) | Delete a key from the map. | |
entries() | Get an iterator over the entries in this map. | |
forEach(callbackFn) | Executes the given callback on each entry in the map. | |
get(key) | Retrieves the given key from the map. | |
getSerializableStorage() | ||
getSerializedStorage() | Serializes the data stored in the shared map to a JSON string | |
has(key) | Check if a key exists in the map. | |
keys() | Get an iterator over the keys in this map. | |
populate(json) | ||
populateFromSerializable(json) | Populate the kernel with the given map data. | |
serialize() | ||
set(key, value) | Sets the value stored at key to the provided value. | |
tryProcessMessage(message, local, localOpMetadata) | Process the given op if a handler is registered. | |
trySubmitMessage(op, localOpMetadata) | Submit the given op if a handler is registered. | |
values() | Get an iterator over the values in this map. | |
wait(key) | A form of get except it will only resolve the promise once the key exists in the map. |
Constructors
MapKernel.(constructor)
Create a new shared map kernel.
Signature:
constructor(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, submitMessage: (op: any, localOpMetadata: unknown) => void, isAttached: () => boolean, valueTypes: Readonly<IValueType<any>[]>, eventEmitter?: TypedEventEmitter<ISharedMapEvents>);
Parameters
Parameter | Type | Description |
---|---|---|
runtime | IFluidDataStoreRuntime | The data store runtime the shared object using the kernel will be associated with |
handle | IFluidHandle | The handle of the shared object using the kernel |
submitMessage | (op: any, localOpMetadata: unknown) => void | A callback to submit a message through the shared object |
isAttached | () => boolean | To query whether the shared object should generate ops |
valueTypes | Readonly<IValueType |
The value types to register |
eventEmitter | TypedEventEmitter<ISharedMapEvents> | The object that will emit map events |
Properties
eventEmitter
Signature:
readonly eventEmitter: TypedEventEmitter<ISharedMapEvents>;
size
The number of key/value pairs stored in the map.
Signature:
get size(): number;
Methods
[Symbol.iterator]
Get an iterator over the entries in this map.
Signature:
[Symbol.iterator](): IterableIterator<[string, any]>;
Returns:
IterableIterator<[string, any]>
The iterator
clear
Clear all data from the map.
Signature:
clear(): void;
Returns:
void
createValueType
Create a new value type at the given key.
Signature:
createValueType(key: string, type: string, params: any): this;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | Key to create the value type at |
type | string | Type of the value type to create |
params | any | Initialization params for the value type |
Returns:
this
delete
Delete a key from the map.
Signature:
delete(key: string): boolean;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | Key to delete |
Returns:
boolean
True if the key existed and was deleted, false if it did not exist
entries
Get an iterator over the entries in this map.
Signature:
entries(): IterableIterator<[string, any]>;
Returns:
IterableIterator<[string, any]>
The iterator
forEach
Executes the given callback on each entry in the map.
Signature:
forEach(callbackFn: (value: any, key: string, map: Map<string, any>) => void): void;
Parameters
Parameter | Type | Description |
---|---|---|
callbackFn | (value: any, key: string, map: Map |
Callback function |
Returns:
void
get
Retrieves the given key from the map.
Signature:
get<T = any>(key: string): T;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | Key to retrieve from |
Returns:
T
The stored value, or undefined if the key is not set
getSerializableStorage
Signature:
getSerializableStorage(): IMapDataObjectSerializable;
Returns:
getSerializedStorage
Serializes the data stored in the shared map to a JSON string
Signature:
getSerializedStorage(): IMapDataObjectSerialized;
Returns:
A JSON string containing serialized map data
has
Check if a key exists in the map.
Signature:
has(key: string): boolean;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The key to check |
Returns:
boolean
True if the key exists, false otherwise
keys
Get an iterator over the keys in this map.
Signature:
keys(): IterableIterator<string>;
Returns:
IterableIterator<string>
The iterator
populate
Signature:
populate(json: string): void;
Parameters
Parameter | Type | Description |
---|---|---|
json | string |
Returns:
void
populateFromSerializable
Populate the kernel with the given map data.
Signature:
populateFromSerializable(json: IMapDataObjectSerializable): void;
Parameters
Parameter | Type | Description |
---|---|---|
json | IMapDataObjectSerializable |
Returns:
void
serialize
Signature:
serialize(): string;
Returns:
string
set
Sets the value stored at key to the provided value.
Signature:
set(key: string, value: any): void;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | Key to set at |
value | any | Value to set |
Returns:
void
The ISharedMap itself
tryProcessMessage
Process the given op if a handler is registered.
Signature:
tryProcessMessage(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): boolean;
Parameters
Parameter | Type | Description |
---|---|---|
message | ISequencedDocumentMessage | The message to process |
local | boolean | Whether the message originated from the local client |
localOpMetadata | unknown | For local client messages, this is the metadata that was submitted with the message. For messages from a remote client, this will be undefined. |
Returns:
boolean
True if the operation was processed, false otherwise.
trySubmitMessage
Submit the given op if a handler is registered.
Signature:
trySubmitMessage(op: any, localOpMetadata: unknown): boolean;
Parameters
Parameter | Type | Description |
---|---|---|
op | any | The operation to attempt to submit |
localOpMetadata | unknown | The local metadata associated with the op. This is kept locally by the runtime and not sent to the server. This will be sent back when this message is received back from the server. This is also sent if we are asked to resubmit the message. |
Returns:
boolean
True if the operation was submitted, false otherwise.
values
Get an iterator over the values in this map.
Signature:
values(): IterableIterator<any>;
Returns:
IterableIterator<any>
The iterator
wait
A form of get except it will only resolve the promise once the key exists in the map.
Signature:
wait<T = any>(key: string): Promise<T>;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | Key to retrieve from |
Returns:
Promise<T>
The stored value once available