Skip to main content
Version: v1

SharedMatrix Class

A SharedMatrix holds a rectangular 2D array of values. Supported operations include setting values and inserting/removing rows and columns.

Matrix values may be any Fluid serializable type, which is the set of JSON serializable types extended to include IFluidHandles.

Fluid's SharedMatrix implementation works equally well for dense and sparse matrix data and physically stores data in Z-order to leverage CPU caches and prefetching when reading in either row or column major order. (See README.md for more details.)

Signature

export declare class SharedMatrix<T = any> extends SharedObject implements IMatrixProducer<MatrixItem<T>>, IMatrixReader<MatrixItem<T>>, IMatrixWriter<MatrixItem<T>>

Extends: SharedObject

Implements: IMatrixProducer<MatrixItem<T>>, IMatrixReader<MatrixItem<T>>, IMatrixWriter<MatrixItem

Type Parameters

ParameterDefaultDescription
Tany

Constructors

ConstructorDescription
(constructor)(runtime, id, attributes)Constructs a new instance of the SharedMatrix class

Static Methods

MethodReturn TypeDescription
create(runtime, id)SharedMatrix<T>Creates a local version of the channel. Calling attach on the object later will insert it into the object stream.
getFactory()SharedMatrixFactory

Properties

PropertyTypeDescription
colCountnumber
idstring
matrixProducerIMatrixProducer<MatrixItem<T>>
rowCountnumber

Methods

MethodReturn TypeDescription
applyStashedOp(content)unknownApply changes from an op. Used when rehydrating an attached container with pending changes. This prepares the SharedObject for seeing an ACK for the op or resubmitting the op upon reconnection.
closeMatrix(consumer)void
didAttach()void
getCell(row, col)MatrixItem<T>
insertCols(colStart, count)void
insertRows(rowStart, count)void
loadCore(storage)Promise<void>
onConnect()void
onDisconnect()void
openMatrix(consumer)IMatrixReader<MatrixItem<T>>
openUndo(consumer)voidSubscribes the given IUndoConsumer to the matrix.
processCore(rawMessage, local, localOpMetadata)void
processGCDataCore(serializer)voidRuns serializer on the GC data for this SharedMatrix. All the IFluidHandle's stored in the cells represent routes to other objects.
removeCols(colStart, count)void
removeRows(rowStart, count)void
reSubmitCore(content, localOpMetadata)void
setCell(row, col, value)void
setCells(rowStart, colStart, colCount, values)void
submitLocalMessage(message, localOpMetadata)void
summarizeCore(serializer)ISummaryTreeWithStats
toString()string

Constructor Details

(constructor)

Constructs a new instance of the SharedMatrix class

Signature

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

Parameters

ParameterTypeDescription
runtimeIFluidDataStoreRuntime
idstring
attributesIChannelAttributes

Property Details

colCount

Signature

get colCount(): number;

Type: number

id

Signature

id: string;

Type: string

matrixProducer

Signature

get matrixProducer(): IMatrixProducer<MatrixItem<T>>;

Type: IMatrixProducer<MatrixItem<T>>

rowCount

Signature

get rowCount(): number;

Type: number

Method Details

applyStashedOp

Apply changes from an op. Used when rehydrating an attached container with pending changes. This prepares the SharedObject for seeing an ACK for the op or resubmitting the op upon reconnection.

Signature

protected applyStashedOp(content: any): unknown;

Parameters

ParameterTypeDescription
contentanyContents of a stashed op.

Returns

localMetadata of the op, to be passed to process() or resubmit() when the op is ACKed or resubmitted, respectively

Return type: unknown

closeMatrix

Signature

closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void;

Parameters

ParameterTypeDescription
consumerIMatrixConsumer<MatrixItem<T>>

create

Creates a local version of the channel. Calling attach on the object later will insert it into the object stream.

Signature

static create<T>(runtime: IFluidDataStoreRuntime, id?: string): SharedMatrix<T>;
Type Parameters
ParameterDescription
T

Parameters

ParameterModifiersTypeDescription
runtimeIFluidDataStoreRuntimeThe runtime the new object will be associated with
idoptionalstringThe unique ID of the new object

Returns

The newly created object.

Return type: SharedMatrix<T>

didAttach

Signature

protected didAttach(): void;

getCell

Signature

getCell(row: number, col: number): MatrixItem<T>;

Parameters

ParameterTypeDescription
rownumber
colnumber

Returns

Return type: MatrixItem<T>

getFactory

Signature

static getFactory(): SharedMatrixFactory;

Returns

Return type: SharedMatrixFactory

insertCols

Signature

insertCols(colStart: number, count: number): void;

Parameters

ParameterTypeDescription
colStartnumber
countnumber

insertRows

Signature

insertRows(rowStart: number, count: number): void;

Parameters

ParameterTypeDescription
rowStartnumber
countnumber

loadCore

Signature

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

Parameters

ParameterTypeDescription
storageIChannelStorageService

Returns

Return type: Promise<void>

onConnect

Signature

protected onConnect(): void;

onDisconnect

Signature

protected onDisconnect(): void;

openMatrix

Signature

openMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): IMatrixReader<MatrixItem<T>>;

Parameters

ParameterTypeDescription
consumerIMatrixConsumer<MatrixItem<T>>

Returns

Return type: IMatrixReader<MatrixItem<T>>

openUndo

Subscribes the given IUndoConsumer to the matrix.

Signature

openUndo(consumer: IUndoConsumer): void;

Parameters

ParameterTypeDescription
consumerIUndoConsumer

processCore

Signature

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

Parameters

ParameterTypeDescription
rawMessageISequencedDocumentMessage
localboolean
localOpMetadataunknown

processGCDataCore

Runs serializer on the GC data for this SharedMatrix. All the IFluidHandle's stored in the cells represent routes to other objects.

Signature

protected processGCDataCore(serializer: SummarySerializer): void;

Parameters

ParameterTypeDescription
serializerSummarySerializer

removeCols

Signature

removeCols(colStart: number, count: number): void;

Parameters

ParameterTypeDescription
colStartnumber
countnumber

removeRows

Signature

removeRows(rowStart: number, count: number): void;

Parameters

ParameterTypeDescription
rowStartnumber
countnumber

reSubmitCore

Signature

protected reSubmitCore(content: any, localOpMetadata: unknown): void;

Parameters

ParameterTypeDescription
contentany
localOpMetadataunknown

setCell

Signature

setCell(row: number, col: number, value: MatrixItem<T>): void;

Parameters

ParameterTypeDescription
rownumber
colnumber
valueMatrixItem<T>

setCells

Signature

setCells(rowStart: number, colStart: number, colCount: number, values: readonly (MatrixItem<T>)[]): void;

Parameters

ParameterTypeDescription
rowStartnumber
colStartnumber
colCountnumber
valuesreadonly (MatrixItem<T>)[]

submitLocalMessage

Signature

protected submitLocalMessage(message: any, localOpMetadata?: any): void;

Parameters

ParameterModifiersTypeDescription
messageany
localOpMetadataoptionalany

summarizeCore

Signature

protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;

Parameters

ParameterTypeDescription
serializerIFluidSerializer

Returns

Return type: ISummaryTreeWithStats

toString

Signature

toString(): string;

Returns

Return type: string