SharedCounter Class
Packages > @fluidframework/counter > SharedCounter
Implementation of a counter shared object
Signature:
export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter
Extends: SharedObject<ISharedCounterEvents>
Implements: ISharedCounter
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
value | number | The counter value. |
Methods
Method | Modifiers | Description |
---|---|---|
create(runtime, id) | static |
Create a new shared counter |
getFactory() | static |
Get a factory for SharedCounter to register with the data store. |
increment(incrementAmount) | Increments or decrements the value. Must only increment or decrement by a whole number value. | |
loadCore(branchId, storage) | Load counter from snapshot | |
onDisconnect() | Call back on disconnect | |
processCore(message, local, localOpMetadata) | Process a counter operation | |
registerCore() | ||
snapshot() | Create a snapshot for the counter |
Properties
value
The counter value.
Signature:
get value(): number;
Methods
create
Create a new shared counter
Signature:
static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
Parameters
Parameter | Type | Description |
---|---|---|
runtime | IFluidDataStoreRuntime | data store runtime the new shared counter belongs to |
id | string | optional name of the shared counter |
Returns:
newly create shared counter (but not attached yet)
getFactory
Get a factory for SharedCounter to register with the data store.
Signature:
static getFactory(): IChannelFactory;
Returns:
a factory that creates and load SharedCounter
increment
Increments or decrements the value. Must only increment or decrement by a whole number value.
Signature:
increment(incrementAmount: number): void;
Parameters
Parameter | Type | Description |
---|---|---|
incrementAmount | number | a whole number to increment or decrement by |
Returns:
void
loadCore
Load counter from snapshot
Signature:
protected loadCore(branchId: string | undefined, storage: IChannelStorageService): Promise<void>;
Parameters
Parameter | Type | Description |
---|---|---|
branchId | string | undefined | Not used |
storage | IChannelStorageService | the storage to get the snapshot from |
Returns:
Promise<void>
- promise that resolved when the load is completed
onDisconnect
Call back on disconnect
Signature:
protected onDisconnect(): void;
Returns:
void
processCore
Process a counter operation
Signature:
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
Parameters
Parameter | Type | Description |
---|---|---|
message | ISequencedDocumentMessage | the message to prepare |
local | boolean | whether the message was sent by 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:
void
registerCore
Signature:
protected registerCore(): void;
Returns:
void
snapshot
Create a snapshot for the counter
Signature:
snapshot(): ITree;
Returns:
the snapshot of the current state of the counter