@fluidframework/counter 2.0.0-internal.7.2.2 → 2.0.0-internal.7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -2
- package/api-extractor.json +2 -8
- package/api-report/counter.api.md +2 -5
- package/dist/counter-alpha.d.ts +153 -0
- package/dist/counter-beta.d.ts +153 -0
- package/dist/counter-public.d.ts +153 -0
- package/dist/counter-untrimmed.d.ts +153 -0
- package/dist/{counter.js → counter.cjs} +3 -47
- package/dist/counter.cjs.map +1 -0
- package/dist/counter.d.ts +1 -45
- package/dist/counter.d.ts.map +1 -1
- package/dist/{counterFactory.js → counterFactory.cjs} +3 -3
- package/dist/counterFactory.cjs.map +1 -0
- package/dist/{index.js → index.cjs} +3 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/{interfaces.js → interfaces.cjs} +1 -1
- package/dist/interfaces.cjs.map +1 -0
- package/dist/interfaces.d.ts +36 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
- package/dist/packageVersion.cjs.map +1 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/counter-alpha.d.ts +153 -0
- package/lib/counter-beta.d.ts +153 -0
- package/lib/counter-public.d.ts +153 -0
- package/lib/counter-untrimmed.d.ts +153 -0
- package/lib/counter.d.ts +1 -45
- package/lib/counter.d.ts.map +1 -1
- package/lib/{counter.js → counter.mjs} +3 -47
- package/lib/counter.mjs.map +1 -0
- package/lib/{counterFactory.js → counterFactory.mjs} +3 -3
- package/lib/counterFactory.mjs.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.mjs +6 -0
- package/lib/index.mjs.map +1 -0
- package/lib/interfaces.d.ts +36 -1
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/{interfaces.js → interfaces.mjs} +1 -1
- package/lib/interfaces.mjs.map +1 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
- package/lib/packageVersion.mjs.map +1 -0
- package/package.json +51 -22
- package/src/counter.ts +1 -45
- package/src/index.ts +1 -1
- package/src/interfaces.ts +36 -1
- package/src/packageVersion.ts +1 -1
- package/tsc-multi.test.json +4 -0
- package/tsconfig.json +5 -3
- package/dist/counter.js.map +0 -1
- package/dist/counterFactory.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces.js.map +0 -1
- package/dist/packageVersion.js.map +0 -1
- package/lib/counter.js.map +0 -1
- package/lib/counterFactory.js.map +0 -1
- package/lib/index.js +0 -12
- package/lib/index.js.map +0 -1
- package/lib/interfaces.js.map +0 -1
- package/lib/packageVersion.js.map +0 -1
- package/tsconfig.esnext.json +0 -7
|
@@ -9,45 +9,10 @@ const core_utils_1 = require("@fluidframework/core-utils");
|
|
|
9
9
|
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
10
10
|
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
11
11
|
const shared_object_base_1 = require("@fluidframework/shared-object-base");
|
|
12
|
-
const counterFactory_1 = require("./counterFactory");
|
|
12
|
+
const counterFactory_1 = require("./counterFactory.cjs");
|
|
13
13
|
const snapshotFileName = "header";
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
18
|
-
*
|
|
19
|
-
* @example Creating a `SharedCounter`
|
|
20
|
-
*
|
|
21
|
-
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
22
|
-
* with a runtime and string ID:
|
|
23
|
-
*
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const factory = SharedCounter.getFactory();
|
|
26
|
-
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* The initial value of a new `SharedCounter` is 0.
|
|
30
|
-
* If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
|
|
31
|
-
* attaching the Container, or before inserting it into an existing shared object.
|
|
32
|
-
*
|
|
33
|
-
* @example Using the `SharedCounter`
|
|
34
|
-
*
|
|
35
|
-
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
36
|
-
* negative number:
|
|
37
|
-
*
|
|
38
|
-
* ```typescript
|
|
39
|
-
* counter.increment(10); // add 10 to the counter value
|
|
40
|
-
* counter.increment(-5); // subtract 5 from the counter value
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* To observe changes to the value (including those from remote clients), register for the
|
|
44
|
-
* {@link ISharedCounterEvents | incremented} event:
|
|
45
|
-
*
|
|
46
|
-
* ```typescript
|
|
47
|
-
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
48
|
-
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
15
|
+
* {@inheritDoc ISharedCounter}
|
|
51
16
|
*
|
|
52
17
|
* @public
|
|
53
18
|
*/
|
|
@@ -105,8 +70,6 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
105
70
|
* Create a summary for the counter.
|
|
106
71
|
*
|
|
107
72
|
* @returns The summary of the current state of the counter.
|
|
108
|
-
*
|
|
109
|
-
* @internal
|
|
110
73
|
*/
|
|
111
74
|
summarizeCore(serializer) {
|
|
112
75
|
// Get a serializable form of data
|
|
@@ -118,8 +81,6 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
118
81
|
}
|
|
119
82
|
/**
|
|
120
83
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
121
|
-
*
|
|
122
|
-
* @internal
|
|
123
84
|
*/
|
|
124
85
|
async loadCore(storage) {
|
|
125
86
|
const content = await (0, driver_utils_1.readAndParse)(storage, snapshotFileName);
|
|
@@ -127,8 +88,6 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
127
88
|
}
|
|
128
89
|
/**
|
|
129
90
|
* Called when the object has disconnected from the delta stream.
|
|
130
|
-
*
|
|
131
|
-
* @internal
|
|
132
91
|
*/
|
|
133
92
|
onDisconnect() { }
|
|
134
93
|
/**
|
|
@@ -138,8 +97,6 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
138
97
|
* @param local - Whether or not the message was sent by the local client.
|
|
139
98
|
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
140
99
|
* For messages from a remote client, this will be `undefined`.
|
|
141
|
-
*
|
|
142
|
-
* @internal
|
|
143
100
|
*/
|
|
144
101
|
processCore(message, local, localOpMetadata) {
|
|
145
102
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
@@ -158,7 +115,6 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
158
115
|
}
|
|
159
116
|
/**
|
|
160
117
|
* {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
161
|
-
* @internal
|
|
162
118
|
*/
|
|
163
119
|
applyStashedOp(op) {
|
|
164
120
|
const counterOp = op;
|
|
@@ -169,4 +125,4 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
169
125
|
}
|
|
170
126
|
}
|
|
171
127
|
exports.SharedCounter = SharedCounter;
|
|
172
|
-
//# sourceMappingURL=counter.
|
|
128
|
+
//# sourceMappingURL=counter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter.cjs","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { type ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\ttype IFluidDataStoreRuntime,\n\ttype IChannelStorageService,\n\ttype IChannelFactory,\n\ttype IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { type ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport {\n\tcreateSingleBlobSummary,\n\ttype IFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { type ISharedCounter, type ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the operation (op) format for incrementing the {@link SharedCounter}.\n */\ninterface IIncrementOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n}\n\n/**\n * @remarks Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n\t/**\n\t * The value of the counter.\n\t */\n\tvalue: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc ISharedCounter}\n *\n * @public\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n\t/**\n\t * Create a new {@link SharedCounter}.\n\t *\n\t * @param runtime - The data store runtime to which the new `SharedCounter` will belong.\n\t * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.\n\t *\n\t * @returns newly create shared counter (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter {\n\t\treturn runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n\t}\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_counter_\");\n\t}\n\n\t/**\n\t * Get a factory for {@link SharedCounter} to register with the data store.\n\t *\n\t * @returns a factory that creates and load SharedCounter\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new CounterFactory();\n\t}\n\n\tprivate _value: number = 0;\n\n\t/**\n\t * {@inheritDoc ISharedCounter.value}\n\t */\n\tpublic get value(): number {\n\t\treturn this._value;\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedCounter.increment}\n\t */\n\tpublic increment(incrementAmount: number): void {\n\t\t// Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n\t\t// increments are applied affects the result. A more-robust solution would be required to support this.\n\t\tif (incrementAmount % 1 !== 0) {\n\t\t\tthrow new Error(\"Must increment by a whole number\");\n\t\t}\n\n\t\tconst op: IIncrementOperation = {\n\t\t\ttype: \"increment\",\n\t\t\tincrementAmount,\n\t\t};\n\n\t\tthis.incrementCore(incrementAmount);\n\t\tthis.submitLocalMessage(op);\n\t}\n\n\tprivate incrementCore(incrementAmount: number): void {\n\t\tthis._value += incrementAmount;\n\t\tthis.emit(\"incremented\", incrementAmount, this._value);\n\t}\n\n\t/**\n\t * Create a summary for the counter.\n\t *\n\t * @returns The summary of the current state of the counter.\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Get a serializable form of data\n\t\tconst content: ICounterSnapshotFormat = {\n\t\t\tvalue: this.value,\n\t\t};\n\n\t\t// And then construct the summary for it\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n\t\tthis._value = content.value;\n\t}\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * Process a counter operation (op).\n\t *\n\t * @param message - The message to prepare.\n\t * @param local - Whether or not the message was sent by the local client.\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be `undefined`.\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (message.type === MessageType.Operation && !local) {\n\t\t\tconst op = message.contents as IIncrementOperation;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"increment\": {\n\t\t\t\t\tthis.incrementCore(op.incrementAmount);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(op: unknown): void {\n\t\tconst counterOp = op as IIncrementOperation;\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\n\t\t// eslint-disable-next-line unicorn/numeric-separators-style\n\t\tassert(counterOp.type === \"increment\", 0x3ec /* Op type is not increment */);\n\n\t\tthis.incrementCore(counterOp.incrementAmount);\n\t}\n}\n"]}
|
package/dist/counter.d.ts
CHANGED
|
@@ -8,42 +8,7 @@ import { type ISummaryTreeWithStats } from "@fluidframework/runtime-definitions"
|
|
|
8
8
|
import { type IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
|
|
9
9
|
import { type ISharedCounter, type ISharedCounterEvents } from "./interfaces";
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
14
|
-
*
|
|
15
|
-
* @example Creating a `SharedCounter`
|
|
16
|
-
*
|
|
17
|
-
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
18
|
-
* with a runtime and string ID:
|
|
19
|
-
*
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const factory = SharedCounter.getFactory();
|
|
22
|
-
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* The initial value of a new `SharedCounter` is 0.
|
|
26
|
-
* If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
|
|
27
|
-
* attaching the Container, or before inserting it into an existing shared object.
|
|
28
|
-
*
|
|
29
|
-
* @example Using the `SharedCounter`
|
|
30
|
-
*
|
|
31
|
-
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
32
|
-
* negative number:
|
|
33
|
-
*
|
|
34
|
-
* ```typescript
|
|
35
|
-
* counter.increment(10); // add 10 to the counter value
|
|
36
|
-
* counter.increment(-5); // subtract 5 from the counter value
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* To observe changes to the value (including those from remote clients), register for the
|
|
40
|
-
* {@link ISharedCounterEvents | incremented} event:
|
|
41
|
-
*
|
|
42
|
-
* ```typescript
|
|
43
|
-
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
44
|
-
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
45
|
-
* });
|
|
46
|
-
* ```
|
|
11
|
+
* {@inheritDoc ISharedCounter}
|
|
47
12
|
*
|
|
48
13
|
* @public
|
|
49
14
|
*/
|
|
@@ -78,20 +43,14 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
78
43
|
* Create a summary for the counter.
|
|
79
44
|
*
|
|
80
45
|
* @returns The summary of the current state of the counter.
|
|
81
|
-
*
|
|
82
|
-
* @internal
|
|
83
46
|
*/
|
|
84
47
|
protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
|
|
85
48
|
/**
|
|
86
49
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
87
|
-
*
|
|
88
|
-
* @internal
|
|
89
50
|
*/
|
|
90
51
|
protected loadCore(storage: IChannelStorageService): Promise<void>;
|
|
91
52
|
/**
|
|
92
53
|
* Called when the object has disconnected from the delta stream.
|
|
93
|
-
*
|
|
94
|
-
* @internal
|
|
95
54
|
*/
|
|
96
55
|
protected onDisconnect(): void;
|
|
97
56
|
/**
|
|
@@ -101,13 +60,10 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
101
60
|
* @param local - Whether or not the message was sent by the local client.
|
|
102
61
|
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
103
62
|
* For messages from a remote client, this will be `undefined`.
|
|
104
|
-
*
|
|
105
|
-
* @internal
|
|
106
63
|
*/
|
|
107
64
|
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
|
|
108
65
|
/**
|
|
109
66
|
* {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
110
|
-
* @internal
|
|
111
67
|
*/
|
|
112
68
|
protected applyStashedOp(op: unknown): void;
|
|
113
69
|
}
|
package/dist/counter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AACnG,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAEN,KAAK,gBAAgB,EACrB,YAAY,EACZ,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAsB9E
|
|
1
|
+
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AACnG,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAEN,KAAK,gBAAgB,EACrB,YAAY,EACZ,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAsB9E;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,YAAY,CAAC,oBAAoB,CAAE,YAAW,cAAc;IAC9F;;;;;;;OAOG;WACW,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,aAAa;gBAKhF,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB;IAK/B;;;;OAIG;WACW,UAAU,IAAI,eAAe;IAI3C,OAAO,CAAC,MAAM,CAAa;IAE3B;;OAEG;IACH,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED;;OAEG;IACI,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI;IAgB/C,OAAO,CAAC,aAAa;IAKrB;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAU5E;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;OAEG;IACH,SAAS,CAAC,YAAY,IAAI,IAAI;IAE9B;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO,GACtB,IAAI;IAkBP;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI;CAU3C"}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.CounterFactory = void 0;
|
|
8
|
-
const counter_1 = require("./counter");
|
|
9
|
-
const packageVersion_1 = require("./packageVersion");
|
|
8
|
+
const counter_1 = require("./counter.cjs");
|
|
9
|
+
const packageVersion_1 = require("./packageVersion.cjs");
|
|
10
10
|
/**
|
|
11
11
|
* {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedCounter}.
|
|
12
12
|
*
|
|
@@ -55,4 +55,4 @@ CounterFactory.Attributes = {
|
|
|
55
55
|
snapshotFormatVersion: "0.1",
|
|
56
56
|
packageVersion: packageVersion_1.pkgVersion,
|
|
57
57
|
};
|
|
58
|
-
//# sourceMappingURL=counterFactory.
|
|
58
|
+
//# sourceMappingURL=counterFactory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counterFactory.cjs","sourceRoot":"","sources":["../src/counterFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,2CAA0C;AAE1C,yDAA8C;AAE9C;;;;GAIG;AACH,MAAa,cAAc;IAe1B;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,cAAc,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACpB,OAAO,cAAc,CAAC,UAAU,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAChB,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAE9B,MAAM,OAAO,GAAG,IAAI,uBAAa,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3D,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,QAAgC,EAAE,EAAU;QACzD,MAAM,OAAO,GAAG,IAAI,uBAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACjE,OAAO,CAAC,eAAe,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC;IAChB,CAAC;;AAlDF,wCAmDC;AAlDA;;GAEG;AACoB,mBAAI,GAAG,2CAA2C,CAAC;AAE1E;;GAEG;AACoB,yBAAU,GAAuB;IACvD,IAAI,EAAE,cAAc,CAAC,IAAI;IACzB,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,2BAAU;CAC1B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype IChannelAttributes,\n\ttype IFluidDataStoreRuntime,\n\ttype IChannelServices,\n\ttype IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { SharedCounter } from \"./counter\";\nimport { type ISharedCounter } from \"./interfaces\";\nimport { pkgVersion } from \"./packageVersion\";\n\n/**\n * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedCounter}.\n *\n * @sealed\n */\nexport class CounterFactory implements IChannelFactory {\n\t/**\n\t * Static value for {@link CounterFactory.\"type\"}.\n\t */\n\tpublic static readonly Type = \"https://graph.microsoft.com/types/counter\";\n\n\t/**\n\t * Static value for {@link CounterFactory.attributes}.\n\t */\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: CounterFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.\"type\"}\n\t */\n\tpublic get type(): string {\n\t\treturn CounterFactory.Type;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}\n\t */\n\tpublic get attributes(): IChannelAttributes {\n\t\treturn CounterFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<ISharedCounter> {\n\t\tconst counter = new SharedCounter(id, runtime, attributes);\n\t\tawait counter.load(services);\n\t\treturn counter;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n\t */\n\tpublic create(document: IFluidDataStoreRuntime, id: string): ISharedCounter {\n\t\tconst counter = new SharedCounter(id, document, this.attributes);\n\t\tcounter.initializeLocal();\n\t\treturn counter;\n\t}\n}\n"]}
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.SharedCounter = void 0;
|
|
8
8
|
/**
|
|
9
|
-
* This library contains the {@link SharedCounter} distributed data structure.
|
|
9
|
+
* This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
|
|
10
10
|
* A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
|
|
11
11
|
*
|
|
12
12
|
* @packageDocumentation
|
|
13
13
|
*/
|
|
14
|
-
var counter_1 = require("./counter");
|
|
14
|
+
var counter_1 = require("./counter.cjs");
|
|
15
15
|
Object.defineProperty(exports, "SharedCounter", { enumerable: true, get: function () { return counter_1.SharedCounter; } });
|
|
16
|
-
//# sourceMappingURL=index.
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;GAKG;AAEH,yCAA0C;AAAjC,wGAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.\n * A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.\n *\n * @packageDocumentation\n */\n\nexport { SharedCounter } from \"./counter\";\nexport type { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* This library contains the {@link SharedCounter} distributed data structure.
|
|
6
|
+
* This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
|
|
7
7
|
* A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
|
|
8
8
|
*
|
|
9
9
|
* @packageDocumentation
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.cjs","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type ISharedObject, type ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Events sent by {@link SharedCounter}.\n *\n * @public\n */\nexport interface ISharedCounterEvents extends ISharedObjectEvents {\n\t/**\n\t * This event is raised when the counter is incremented or decremented.\n\t *\n\t * @param event - The event name.\n\t * @param listener - An event listener.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"incremented\", listener: (incrementAmount: number, newValue: number) => void);\n}\n\n/**\n * A shared object that holds a number that can be incremented or decremented.\n *\n * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.\n *\n * @example Creating a `SharedCounter`\n *\n * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}\n * with a runtime and string ID:\n *\n * ```typescript\n * const factory = SharedCounter.getFactory();\n * const counter = factory.create(this.runtime, id) as SharedCounter;\n * ```\n *\n * The initial value of a new `SharedCounter` is 0.\n * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before\n * attaching the Container, or before inserting it into an existing shared object.\n *\n * @example Using the `SharedCounter`\n *\n * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or\n * negative number:\n *\n * ```typescript\n * counter.increment(10); // add 10 to the counter value\n * counter.increment(-5); // subtract 5 from the counter value\n * ```\n *\n * To observe changes to the value (including those from remote clients), register for the\n * {@link ISharedCounterEvents | incremented} event:\n *\n * ```typescript\n * counter.on(\"incremented\", (incrementAmount, newValue) => {\n * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);\n * });\n * ```\n *\n * @public\n */\nexport interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {\n\t/**\n\t * The counter value.\n\t *\n\t * @remarks Must be a whole number.\n\t */\n\tvalue: number;\n\n\t/**\n\t * Increments or decrements the value.\n\t * Must only increment or decrement by a whole number value.\n\t *\n\t * @param incrementAmount - A whole number to increment or decrement by.\n\t */\n\tincrement(incrementAmount: number): void;\n}\n"]}
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -20,7 +20,42 @@ export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
|
20
20
|
(event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* A shared object that holds a number that can be incremented or decremented.
|
|
24
|
+
*
|
|
25
|
+
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
26
|
+
*
|
|
27
|
+
* @example Creating a `SharedCounter`
|
|
28
|
+
*
|
|
29
|
+
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
30
|
+
* with a runtime and string ID:
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const factory = SharedCounter.getFactory();
|
|
34
|
+
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* The initial value of a new `SharedCounter` is 0.
|
|
38
|
+
* If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
|
|
39
|
+
* attaching the Container, or before inserting it into an existing shared object.
|
|
40
|
+
*
|
|
41
|
+
* @example Using the `SharedCounter`
|
|
42
|
+
*
|
|
43
|
+
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
44
|
+
* negative number:
|
|
45
|
+
*
|
|
46
|
+
* ```typescript
|
|
47
|
+
* counter.increment(10); // add 10 to the counter value
|
|
48
|
+
* counter.increment(-5); // subtract 5 from the counter value
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* To observe changes to the value (including those from remote clients), register for the
|
|
52
|
+
* {@link ISharedCounterEvents | incremented} event:
|
|
53
|
+
*
|
|
54
|
+
* ```typescript
|
|
55
|
+
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
56
|
+
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
24
59
|
*
|
|
25
60
|
* @public
|
|
26
61
|
*/
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAElG;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAChE;;;;;;;OAOG;IACH,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,OAAE;CACtF;AAED
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAElG;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAChE;;;;;;;OAOG;IACH,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,OAAE;CACtF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,WAAW,cAAe,SAAQ,aAAa,CAAC,oBAAoB,CAAC;IAC1E;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC"}
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/counter";
|
|
11
|
-
exports.pkgVersion = "2.0.0-internal.7.
|
|
12
|
-
//# sourceMappingURL=packageVersion.
|
|
11
|
+
exports.pkgVersion = "2.0.0-internal.7.3.0";
|
|
12
|
+
//# sourceMappingURL=packageVersion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageVersion.cjs","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,yBAAyB,CAAC;AACpC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/counter\";\nexport const pkgVersion = \"2.0.0-internal.7.3.0\";\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/counter";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.7.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.7.3.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
|
|
3
|
+
* A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { IChannelAttributes } from '@fluidframework/datastore-definitions';
|
|
9
|
+
import { IChannelFactory } from '@fluidframework/datastore-definitions';
|
|
10
|
+
import { IChannelStorageService } from '@fluidframework/datastore-definitions';
|
|
11
|
+
import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
|
|
12
|
+
import { IFluidSerializer } from '@fluidframework/shared-object-base';
|
|
13
|
+
import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
|
|
14
|
+
import { ISharedObject } from '@fluidframework/shared-object-base';
|
|
15
|
+
import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
|
|
16
|
+
import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
|
|
17
|
+
import { SharedObject } from '@fluidframework/shared-object-base';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A shared object that holds a number that can be incremented or decremented.
|
|
21
|
+
*
|
|
22
|
+
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
23
|
+
*
|
|
24
|
+
* @example Creating a `SharedCounter`
|
|
25
|
+
*
|
|
26
|
+
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
27
|
+
* with a runtime and string ID:
|
|
28
|
+
*
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const factory = SharedCounter.getFactory();
|
|
31
|
+
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* The initial value of a new `SharedCounter` is 0.
|
|
35
|
+
* If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
|
|
36
|
+
* attaching the Container, or before inserting it into an existing shared object.
|
|
37
|
+
*
|
|
38
|
+
* @example Using the `SharedCounter`
|
|
39
|
+
*
|
|
40
|
+
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
41
|
+
* negative number:
|
|
42
|
+
*
|
|
43
|
+
* ```typescript
|
|
44
|
+
* counter.increment(10); // add 10 to the counter value
|
|
45
|
+
* counter.increment(-5); // subtract 5 from the counter value
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* To observe changes to the value (including those from remote clients), register for the
|
|
49
|
+
* {@link ISharedCounterEvents | incremented} event:
|
|
50
|
+
*
|
|
51
|
+
* ```typescript
|
|
52
|
+
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
53
|
+
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
60
|
+
/**
|
|
61
|
+
* The counter value.
|
|
62
|
+
*
|
|
63
|
+
* @remarks Must be a whole number.
|
|
64
|
+
*/
|
|
65
|
+
value: number;
|
|
66
|
+
/**
|
|
67
|
+
* Increments or decrements the value.
|
|
68
|
+
* Must only increment or decrement by a whole number value.
|
|
69
|
+
*
|
|
70
|
+
* @param incrementAmount - A whole number to increment or decrement by.
|
|
71
|
+
*/
|
|
72
|
+
increment(incrementAmount: number): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Events sent by {@link SharedCounter}.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export declare interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
81
|
+
/**
|
|
82
|
+
* This event is raised when the counter is incremented or decremented.
|
|
83
|
+
*
|
|
84
|
+
* @param event - The event name.
|
|
85
|
+
* @param listener - An event listener.
|
|
86
|
+
*
|
|
87
|
+
* @eventProperty
|
|
88
|
+
*/
|
|
89
|
+
(event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* {@inheritDoc ISharedCounter}
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
|
|
98
|
+
/**
|
|
99
|
+
* Create a new {@link SharedCounter}.
|
|
100
|
+
*
|
|
101
|
+
* @param runtime - The data store runtime to which the new `SharedCounter` will belong.
|
|
102
|
+
* @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
|
|
103
|
+
*
|
|
104
|
+
* @returns newly create shared counter (but not attached yet)
|
|
105
|
+
*/
|
|
106
|
+
static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
|
|
107
|
+
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
|
|
108
|
+
/**
|
|
109
|
+
* Get a factory for {@link SharedCounter} to register with the data store.
|
|
110
|
+
*
|
|
111
|
+
* @returns a factory that creates and load SharedCounter
|
|
112
|
+
*/
|
|
113
|
+
static getFactory(): IChannelFactory;
|
|
114
|
+
private _value;
|
|
115
|
+
/**
|
|
116
|
+
* {@inheritDoc ISharedCounter.value}
|
|
117
|
+
*/
|
|
118
|
+
get value(): number;
|
|
119
|
+
/**
|
|
120
|
+
* {@inheritDoc ISharedCounter.increment}
|
|
121
|
+
*/
|
|
122
|
+
increment(incrementAmount: number): void;
|
|
123
|
+
private incrementCore;
|
|
124
|
+
/**
|
|
125
|
+
* Create a summary for the counter.
|
|
126
|
+
*
|
|
127
|
+
* @returns The summary of the current state of the counter.
|
|
128
|
+
*/
|
|
129
|
+
protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
|
|
130
|
+
/**
|
|
131
|
+
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
132
|
+
*/
|
|
133
|
+
protected loadCore(storage: IChannelStorageService): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Called when the object has disconnected from the delta stream.
|
|
136
|
+
*/
|
|
137
|
+
protected onDisconnect(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Process a counter operation (op).
|
|
140
|
+
*
|
|
141
|
+
* @param message - The message to prepare.
|
|
142
|
+
* @param local - Whether or not the message was sent by the local client.
|
|
143
|
+
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
144
|
+
* For messages from a remote client, this will be `undefined`.
|
|
145
|
+
*/
|
|
146
|
+
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
|
|
147
|
+
/**
|
|
148
|
+
* {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
149
|
+
*/
|
|
150
|
+
protected applyStashedOp(op: unknown): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { }
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
|
|
3
|
+
* A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { IChannelAttributes } from '@fluidframework/datastore-definitions';
|
|
9
|
+
import { IChannelFactory } from '@fluidframework/datastore-definitions';
|
|
10
|
+
import { IChannelStorageService } from '@fluidframework/datastore-definitions';
|
|
11
|
+
import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
|
|
12
|
+
import { IFluidSerializer } from '@fluidframework/shared-object-base';
|
|
13
|
+
import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
|
|
14
|
+
import { ISharedObject } from '@fluidframework/shared-object-base';
|
|
15
|
+
import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
|
|
16
|
+
import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
|
|
17
|
+
import { SharedObject } from '@fluidframework/shared-object-base';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A shared object that holds a number that can be incremented or decremented.
|
|
21
|
+
*
|
|
22
|
+
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
23
|
+
*
|
|
24
|
+
* @example Creating a `SharedCounter`
|
|
25
|
+
*
|
|
26
|
+
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
27
|
+
* with a runtime and string ID:
|
|
28
|
+
*
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const factory = SharedCounter.getFactory();
|
|
31
|
+
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* The initial value of a new `SharedCounter` is 0.
|
|
35
|
+
* If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
|
|
36
|
+
* attaching the Container, or before inserting it into an existing shared object.
|
|
37
|
+
*
|
|
38
|
+
* @example Using the `SharedCounter`
|
|
39
|
+
*
|
|
40
|
+
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
41
|
+
* negative number:
|
|
42
|
+
*
|
|
43
|
+
* ```typescript
|
|
44
|
+
* counter.increment(10); // add 10 to the counter value
|
|
45
|
+
* counter.increment(-5); // subtract 5 from the counter value
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* To observe changes to the value (including those from remote clients), register for the
|
|
49
|
+
* {@link ISharedCounterEvents | incremented} event:
|
|
50
|
+
*
|
|
51
|
+
* ```typescript
|
|
52
|
+
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
53
|
+
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
60
|
+
/**
|
|
61
|
+
* The counter value.
|
|
62
|
+
*
|
|
63
|
+
* @remarks Must be a whole number.
|
|
64
|
+
*/
|
|
65
|
+
value: number;
|
|
66
|
+
/**
|
|
67
|
+
* Increments or decrements the value.
|
|
68
|
+
* Must only increment or decrement by a whole number value.
|
|
69
|
+
*
|
|
70
|
+
* @param incrementAmount - A whole number to increment or decrement by.
|
|
71
|
+
*/
|
|
72
|
+
increment(incrementAmount: number): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Events sent by {@link SharedCounter}.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export declare interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
81
|
+
/**
|
|
82
|
+
* This event is raised when the counter is incremented or decremented.
|
|
83
|
+
*
|
|
84
|
+
* @param event - The event name.
|
|
85
|
+
* @param listener - An event listener.
|
|
86
|
+
*
|
|
87
|
+
* @eventProperty
|
|
88
|
+
*/
|
|
89
|
+
(event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* {@inheritDoc ISharedCounter}
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
|
|
98
|
+
/**
|
|
99
|
+
* Create a new {@link SharedCounter}.
|
|
100
|
+
*
|
|
101
|
+
* @param runtime - The data store runtime to which the new `SharedCounter` will belong.
|
|
102
|
+
* @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
|
|
103
|
+
*
|
|
104
|
+
* @returns newly create shared counter (but not attached yet)
|
|
105
|
+
*/
|
|
106
|
+
static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
|
|
107
|
+
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
|
|
108
|
+
/**
|
|
109
|
+
* Get a factory for {@link SharedCounter} to register with the data store.
|
|
110
|
+
*
|
|
111
|
+
* @returns a factory that creates and load SharedCounter
|
|
112
|
+
*/
|
|
113
|
+
static getFactory(): IChannelFactory;
|
|
114
|
+
private _value;
|
|
115
|
+
/**
|
|
116
|
+
* {@inheritDoc ISharedCounter.value}
|
|
117
|
+
*/
|
|
118
|
+
get value(): number;
|
|
119
|
+
/**
|
|
120
|
+
* {@inheritDoc ISharedCounter.increment}
|
|
121
|
+
*/
|
|
122
|
+
increment(incrementAmount: number): void;
|
|
123
|
+
private incrementCore;
|
|
124
|
+
/**
|
|
125
|
+
* Create a summary for the counter.
|
|
126
|
+
*
|
|
127
|
+
* @returns The summary of the current state of the counter.
|
|
128
|
+
*/
|
|
129
|
+
protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
|
|
130
|
+
/**
|
|
131
|
+
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
132
|
+
*/
|
|
133
|
+
protected loadCore(storage: IChannelStorageService): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Called when the object has disconnected from the delta stream.
|
|
136
|
+
*/
|
|
137
|
+
protected onDisconnect(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Process a counter operation (op).
|
|
140
|
+
*
|
|
141
|
+
* @param message - The message to prepare.
|
|
142
|
+
* @param local - Whether or not the message was sent by the local client.
|
|
143
|
+
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
144
|
+
* For messages from a remote client, this will be `undefined`.
|
|
145
|
+
*/
|
|
146
|
+
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
|
|
147
|
+
/**
|
|
148
|
+
* {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
149
|
+
*/
|
|
150
|
+
protected applyStashedOp(op: unknown): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { }
|