Skip to main content
Version: v1

SharedCell Class

The SharedCell distributed data structure can be used to store a single serializable value.

Signature​

export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>> implements ISharedCell<T>

Extends: SharedObject<ISharedCellEvents

Implements: ISharedCell

Type Parameters​

ParameterDefaultDescription
Tany

Remarks​

### Creation

To create a SharedCell, call the static create method:

const myCell = SharedCell.create(this.runtime, id);

### Usage

The value stored in the cell can be set with the .set() method and retrieved with the .get() method:

myCell.set(3);
console.log(myCell.get()); // 3

The value must only be plain JS objects or SharedObject handles (e.g. to another DDS or Fluid object). In collaborative scenarios, the value is settled with a policy of _last write wins_.

The .delete() method will delete the stored value from the cell:

myCell.delete();
console.log(myCell.get()); // undefined

The .empty() method will check if the value is undefined.

if (myCell.empty()) {
// myCell.get() will return undefined
} else {
// myCell.get() will return a non-undefined value
}

### Eventing

SharedCell is an EventEmitter, and will emit events when other clients make modifications. You should register for these events and respond appropriately as the data is modified. valueChanged will be emitted in response to a set, and delete will be emitted in response to a delete.

Constructors​

ConstructorDescription
(constructor)(id, runtime, attributes)Constructs a new shared cell. If the object is non-local an id and service interfaces will be provided

Static Methods​

MethodReturn TypeDescription
create(runtime, id)SharedCell<any>Create a new shared cell
getFactory()IChannelFactoryGet a factory for SharedCell to register with the data store.

Methods​

MethodReturn TypeDescription
delete()voidDelete the value from the cell.
empty()booleanChecks whether cell is empty or not.
get()Serializable<T> | undefinedRetrieves the cell value.
initializeLocalCore()voidInitialize a local instance of cell
loadCore(storage)Promise<void>
onDisconnect()voidCall back on disconnect
processCore(message, local, localOpMetadata)voidProcess a cell operation
set(value)voidSets the cell value.
summarizeCore(serializer)ISummaryTreeWithStatsCreate a summary for the cell

Constructor Details​

(constructor)​

Constructs a new shared cell. If the object is non-local an id and service interfaces will be provided

Signature​

constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);

Parameters​

ParameterTypeDescription
idstringoptional name of the shared map
runtimeIFluidDataStoreRuntimedata store runtime the shared map belongs to
attributesIChannelAttributes

Method Details​

create​

Create a new shared cell

Signature​

static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCell<any>;

Parameters​

ParameterModifiersTypeDescription
runtimeIFluidDataStoreRuntimedata store runtime the new shared map belongs to
idoptionalstringoptional name of the shared map

Returns​

newly create shared map (but not attached yet)

Return type: SharedCell<any>

delete​

Delete the value from the cell.

Signature​

delete(): void;

empty​

Checks whether cell is empty or not.

Signature​

empty(): boolean;

Returns​

  • true if the value of cell is undefined, false otherwise

Return type: boolean

get​

Retrieves the cell value.

Signature​

get(): Serializable<T> | undefined;

Returns​

  • the value of the cell

Return type: Serializable<T> | undefined

getFactory​

Get a factory for SharedCell to register with the data store.

Signature​

static getFactory(): IChannelFactory;

Returns​

a factory that creates and load SharedCell

Return type: IChannelFactory

initializeLocalCore​

Initialize a local instance of cell

Signature​

protected initializeLocalCore(): void;

loadCore​

Signature​

protected loadCore(storage: IChannelStorageService): Promise<void>;

Parameters​

ParameterTypeDescription
storageIChannelStorageService

Returns​

Return type: Promise<void>

onDisconnect​

Call back on disconnect

Signature​

protected onDisconnect(): void;

processCore​

Process a cell operation

Signature​

protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;

Parameters​

ParameterTypeDescription
messageISequencedDocumentMessagethe message to prepare
localbooleanwhether the message was sent by the local client
localOpMetadataunknownFor local client messages, this is the metadata that was submitted with the message. For messages from a remote client, this will be undefined.

set​

Sets the cell value.

Signature​

set(value: Serializable<T>): void;

Parameters​

ParameterTypeDescription
valueSerializable<T>a JSON-able or SharedObject value to set the cell to

summarizeCore​

Create a summary for the cell

Signature​

protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;

Parameters​

ParameterTypeDescription
serializerIFluidSerializer

Returns​

the summary of the current state of the cell

Return type: ISummaryTreeWithStats