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

Parameter Default Description
T any

Constructors

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

Static Methods

Method Return Type Description
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

Property Type Description
colCount number
id string
matrixProducer IMatrixProducer<MatrixItem<T>>
rowCount number

Methods

Method Return Type Description
applyStashedOp(content) unknown 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.
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) void Subscribes the given IUndoConsumer to the matrix.
processCore(rawMessage, local, localOpMetadata) void
processGCDataCore(serializer) void Runs 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

Parameter Type Description
runtime IFluidDataStoreRuntime
id string
attributes IChannelAttributes

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

Parameter Type Description
content any Contents 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

Parameter Type Description
consumer IMatrixConsumer<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
Parameter Description
T

Parameters

Parameter Modifiers Type Description
runtime IFluidDataStoreRuntime The runtime the new object will be associated with
id optional string The 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

Parameter Type Description
row number
col number

Returns

Return type: MatrixItem<T>

getFactory

Signature

static getFactory(): SharedMatrixFactory;

Returns

Return type: SharedMatrixFactory

insertCols

Signature

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

Parameters

Parameter Type Description
colStart number
count number

insertRows

Signature

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

Parameters

Parameter Type Description
rowStart number
count number

loadCore

Signature

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

Parameters

Parameter Type Description
storage IChannelStorageService

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

Parameter Type Description
consumer IMatrixConsumer<MatrixItem<T>>

Returns

Return type: IMatrixReader<MatrixItem<T>>

openUndo

Subscribes the given IUndoConsumer to the matrix.

Signature

openUndo(consumer: IUndoConsumer): void;

Parameters

Parameter Type Description
consumer IUndoConsumer

processCore

Signature

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

Parameters

Parameter Type Description
rawMessage ISequencedDocumentMessage
local boolean
localOpMetadata unknown

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

Parameter Type Description
serializer SummarySerializer

removeCols

Signature

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

Parameters

Parameter Type Description
colStart number
count number

removeRows

Signature

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

Parameters

Parameter Type Description
rowStart number
count number

reSubmitCore

Signature

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

Parameters

Parameter Type Description
content any
localOpMetadata unknown

setCell

Signature

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

Parameters

Parameter Type Description
row number
col number
value MatrixItem<T>

setCells

Signature

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

Parameters

Parameter Type Description
rowStart number
colStart number
colCount number
values readonly (MatrixItem<T>)[]

submitLocalMessage

Signature

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

Parameters

Parameter Modifiers Type Description
message any
localOpMetadata optional any

summarizeCore

Signature

protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;

Parameters

Parameter Type Description
serializer IFluidSerializer

Returns

Return type: ISummaryTreeWithStats

toString

Signature

toString(): string;

Returns

Return type: string