@fluidframework/counter 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277

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.
Files changed (88) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +117 -0
  4. package/README.md +197 -1
  5. package/api-extractor-esm.json +4 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +2 -2
  8. package/api-report/counter.api.md +46 -0
  9. package/dist/counter-alpha.d.ts +150 -0
  10. package/dist/counter-beta.d.ts +25 -0
  11. package/dist/counter-public.d.ts +25 -0
  12. package/dist/counter-untrimmed.d.ts +150 -0
  13. package/dist/{counter.js → counter.cjs} +32 -55
  14. package/dist/counter.cjs.map +1 -0
  15. package/dist/counter.d.ts +20 -51
  16. package/dist/counter.d.ts.map +1 -1
  17. package/dist/{counterFactory.js → counterFactory.cjs} +21 -4
  18. package/dist/counterFactory.cjs.map +1 -0
  19. package/dist/counterFactory.d.ts +20 -3
  20. package/dist/counterFactory.d.ts.map +1 -1
  21. package/dist/index.cjs +16 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +4 -4
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/{interfaces.js → interfaces.cjs} +1 -1
  26. package/dist/interfaces.cjs.map +1 -0
  27. package/dist/interfaces.d.ts +45 -7
  28. package/dist/interfaces.d.ts.map +1 -1
  29. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  30. package/dist/packageVersion.cjs.map +1 -0
  31. package/dist/packageVersion.d.ts +1 -1
  32. package/dist/packageVersion.d.ts.map +1 -1
  33. package/dist/tsdoc-metadata.json +11 -0
  34. package/lib/counter-alpha.d.mts +143 -0
  35. package/lib/counter-beta.d.mts +18 -0
  36. package/lib/counter-public.d.mts +18 -0
  37. package/lib/counter-untrimmed.d.mts +143 -0
  38. package/lib/counter.d.mts +69 -0
  39. package/lib/counter.d.mts.map +1 -0
  40. package/lib/{counter.js → counter.mjs} +33 -56
  41. package/lib/counter.mjs.map +1 -0
  42. package/lib/counterFactory.d.mts +38 -0
  43. package/lib/counterFactory.d.mts.map +1 -0
  44. package/lib/{counterFactory.js → counterFactory.mjs} +21 -4
  45. package/lib/counterFactory.mjs.map +1 -0
  46. package/lib/index.d.mts +7 -0
  47. package/lib/index.d.mts.map +1 -0
  48. package/lib/index.mjs +6 -0
  49. package/lib/index.mjs.map +1 -0
  50. package/lib/interfaces.d.mts +75 -0
  51. package/lib/interfaces.d.mts.map +1 -0
  52. package/lib/{interfaces.js → interfaces.mjs} +1 -1
  53. package/lib/interfaces.mjs.map +1 -0
  54. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +2 -2
  55. package/lib/packageVersion.d.mts.map +1 -0
  56. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  57. package/lib/packageVersion.mjs.map +1 -0
  58. package/package.json +133 -60
  59. package/prettier.config.cjs +8 -0
  60. package/src/counter.ts +157 -163
  61. package/src/counterFactory.ts +53 -35
  62. package/src/index.ts +4 -4
  63. package/src/interfaces.ts +62 -24
  64. package/src/packageVersion.ts +1 -1
  65. package/tsc-multi.test.json +4 -0
  66. package/tsconfig.json +11 -13
  67. package/dist/counter.js.map +0 -1
  68. package/dist/counterFactory.js.map +0 -1
  69. package/dist/index.js +0 -25
  70. package/dist/index.js.map +0 -1
  71. package/dist/interfaces.js.map +0 -1
  72. package/dist/packageVersion.js.map +0 -1
  73. package/lib/counter.d.ts +0 -100
  74. package/lib/counter.d.ts.map +0 -1
  75. package/lib/counter.js.map +0 -1
  76. package/lib/counterFactory.d.ts +0 -21
  77. package/lib/counterFactory.d.ts.map +0 -1
  78. package/lib/counterFactory.js.map +0 -1
  79. package/lib/index.d.ts +0 -13
  80. package/lib/index.d.ts.map +0 -1
  81. package/lib/index.js +0 -13
  82. package/lib/index.js.map +0 -1
  83. package/lib/interfaces.d.ts +0 -37
  84. package/lib/interfaces.d.ts.map +0 -1
  85. package/lib/interfaces.js.map +0 -1
  86. package/lib/packageVersion.d.ts.map +0 -1
  87. package/lib/packageVersion.js.map +0 -1
  88. package/tsconfig.esnext.json +0 -7
package/.eslintrc.js CHANGED
@@ -4,10 +4,8 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- "extends": [
8
- require.resolve("@fluidframework/eslint-config-fluid")
9
- ],
10
- "parserOptions": {
11
- "project": ["./tsconfig.json", "./src/test/tsconfig.json"]
12
- },
13
- }
7
+ extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
8
+ parserOptions: {
9
+ project: ["./tsconfig.json", "./src/test/tsconfig.json"],
10
+ },
11
+ };
package/.mocharc.js ADDED
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const getFluidTestMochaConfig = require("@fluidframework/mocha-test-setup/mocharc-common");
9
+
10
+ const packageDir = __dirname;
11
+ const config = getFluidTestMochaConfig(packageDir);
12
+ module.exports = config;
package/CHANGELOG.md ADDED
@@ -0,0 +1,117 @@
1
+ # @fluidframework/counter
2
+
3
+ ## 2.0.0-internal.8.0.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.0.0-internal.7.4.0
8
+
9
+ Dependency updates only.
10
+
11
+ ## 2.0.0-internal.7.3.0
12
+
13
+ Dependency updates only.
14
+
15
+ ## 2.0.0-internal.7.2.0
16
+
17
+ Dependency updates only.
18
+
19
+ ## 2.0.0-internal.7.1.0
20
+
21
+ Dependency updates only.
22
+
23
+ ## 2.0.0-internal.7.0.0
24
+
25
+ ### Major Changes
26
+
27
+ - Dependencies on @fluidframework/protocol-definitions package updated to 3.0.0 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
28
+
29
+ This included the following changes from the protocol-definitions release:
30
+
31
+ - Updating signal interfaces for some planned improvements. The intention is split the interface between signals
32
+ submitted by clients to the server and the resulting signals sent from the server to clients.
33
+ - A new optional type member is available on the ISignalMessage interface and a new ISentSignalMessage interface has
34
+ been added, which will be the typing for signals sent from the client to the server. Both extend a new
35
+ ISignalMessageBase interface that contains common members.
36
+ - The @fluidframework/common-definitions package dependency has been updated to version 1.0.0.
37
+
38
+ - Server upgrade: dependencies on Fluid server packages updated to 2.0.1 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
39
+
40
+ Dependencies on the following Fluid server package have been updated to version 2.0.1:
41
+
42
+ - @fluidframework/gitresources: 2.0.1
43
+ - @fluidframework/server-kafka-orderer: 2.0.1
44
+ - @fluidframework/server-lambdas: 2.0.1
45
+ - @fluidframework/server-lambdas-driver: 2.0.1
46
+ - @fluidframework/server-local-server: 2.0.1
47
+ - @fluidframework/server-memory-orderer: 2.0.1
48
+ - @fluidframework/protocol-base: 2.0.1
49
+ - @fluidframework/server-routerlicious: 2.0.1
50
+ - @fluidframework/server-routerlicious-base: 2.0.1
51
+ - @fluidframework/server-services: 2.0.1
52
+ - @fluidframework/server-services-client: 2.0.1
53
+ - @fluidframework/server-services-core: 2.0.1
54
+ - @fluidframework/server-services-ordering-kafkanode: 2.0.1
55
+ - @fluidframework/server-services-ordering-rdkafka: 2.0.1
56
+ - @fluidframework/server-services-ordering-zookeeper: 2.0.1
57
+ - @fluidframework/server-services-shared: 2.0.1
58
+ - @fluidframework/server-services-telemetry: 2.0.1
59
+ - @fluidframework/server-services-utils: 2.0.1
60
+ - @fluidframework/server-test-utils: 2.0.1
61
+ - tinylicious: 2.0.1
62
+
63
+ - Minimum TypeScript version now 5.1.6 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
64
+
65
+ The minimum supported TypeScript version for Fluid 2.0 clients is now 5.1.6.
66
+
67
+ ## 2.0.0-internal.6.4.0
68
+
69
+ Dependency updates only.
70
+
71
+ ## 2.0.0-internal.6.3.0
72
+
73
+ Dependency updates only.
74
+
75
+ ## 2.0.0-internal.6.2.0
76
+
77
+ Dependency updates only.
78
+
79
+ ## 2.0.0-internal.6.1.0
80
+
81
+ Dependency updates only.
82
+
83
+ ## 2.0.0-internal.6.0.0
84
+
85
+ ### Major Changes
86
+
87
+ - Upgraded typescript transpilation target to ES2020 [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
88
+
89
+ Upgraded typescript transpilation target to ES2020. This is done in order to decrease the bundle sizes of Fluid Framework packages. This has provided size improvements across the board for ex. Loader, Driver, Runtime etc. Reduced bundle sizes helps to load lesser code in apps and hence also helps to improve the perf.If any app wants to target any older versions of browsers with which this target version is not compatible, then they can use packages like babel to transpile to a older target.
90
+
91
+ ## 2.0.0-internal.5.4.0
92
+
93
+ Dependency updates only.
94
+
95
+ ## 2.0.0-internal.5.3.0
96
+
97
+ Dependency updates only.
98
+
99
+ ## 2.0.0-internal.5.2.0
100
+
101
+ Dependency updates only.
102
+
103
+ ## 2.0.0-internal.5.1.0
104
+
105
+ Dependency updates only.
106
+
107
+ ## 2.0.0-internal.5.0.0
108
+
109
+ Dependency updates only.
110
+
111
+ ## 2.0.0-internal.4.4.0
112
+
113
+ Dependency updates only.
114
+
115
+ ## 2.0.0-internal.4.1.0
116
+
117
+ Dependency updates only.
package/README.md CHANGED
@@ -1,3 +1,199 @@
1
1
  # @fluidframework/counter
2
2
 
3
- Documentation available at https://fluidframework.com/docs/apis/counter/.
3
+ <!-- AUTO-GENERATED-CONTENT:START (README_DEPENDENCY_GUIDELINES_SECTION:includeHeading=TRUE) -->
4
+
5
+ <!-- prettier-ignore-start -->
6
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
7
+
8
+ ## Using Fluid Framework libraries
9
+
10
+ When taking a dependency on a Fluid Framework library, we recommend using a `^` (caret) version range, such as `^1.3.4`.
11
+ While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
12
+ library consumers should always prefer `^`.
13
+
14
+ Note that when depending on a library version of the form `2.0.0-internal.x.y.z`, called the Fluid internal version scheme,
15
+ you must use a `>= <` dependency range (such as `>=2.0.0-internal.x.y.z <2.0.0-internal.w.0.0` where `w` is `x+1`).
16
+ Standard `^` and `~` ranges will not work as expected.
17
+ See the [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
18
+ package for more information including tools to convert between version schemes.
19
+
20
+ <!-- prettier-ignore-end -->
21
+
22
+ <!-- AUTO-GENERATED-CONTENT:END -->
23
+
24
+ ## Introduction
25
+
26
+ The `SharedCounter` distributed data structure (DDS) is used to store an integer counter value that can be modified by multiple clients simultaneously.
27
+ The data structure affords incrementing and decrementing the shared value via its `increment` method. Decrements are done by providing a negative value.
28
+
29
+ The `SharedCounter` is a specialized [Optimistic DDS][].
30
+ It operates on communicated _deltas_ (amounts by which the shared value should be incremented or decremented), rather than direct changes to the shared value.
31
+ In this way, it avoids the pitfalls of DDSes with simpler merge strategies, in which one user's edit may clobber another's (see [below](#why-a-specialized-dds)).
32
+
33
+ Note that the `SharedCounter` only operates on integer values.
34
+
35
+ ### Why a specialized DDS?
36
+
37
+ You may be asking yourself, why not just store the shared integer value directly in another DDS like a [SharedMap][]?
38
+ Why incur the overhead of another runtime type?
39
+
40
+ The key to the answer here is that DDSes with simpler merge strategies (like `SharedMap`) take a somewhat brute-force approach to merging concurrent edits.
41
+ For a semantic data type like a counter, this can result in undesirable behavior.
42
+
43
+ #### SharedMap Example
44
+
45
+ Let's illustrate the issue with an example.
46
+
47
+ Consider a polling widget.
48
+ The widget displays a list of options and allows users to click a checkbox to vote for a given option.
49
+ Next to each option in the list, a live counter is displayed that shows the number of votes for that item.
50
+
51
+ Whenever a user checks an option, all users should see the counter corresponding to that option increment by 1.
52
+
53
+ In this example, the application is storing its vote counts in a [SharedMap][], where the map keys are `strings` representing the IDs of the options, and the values are `numbers` representing the associated vote counts.
54
+
55
+ For simplicity, we will look at a scenario in which 2 users vote for the same option at around the same time.
56
+
57
+ Specifically, **User A** clicks the checkbox for option **Foo**, which currently has **0** votes.
58
+ The application then optimistically updates the vote count for that object by writing the updated counter value of **1** for option **Foo** to its `SharedMap`.
59
+
60
+ The value change operation (op) is then transmitted to the service to be sequenced and eventually sent to other users in the collaborative session.
61
+
62
+ At around the same time, **User B** clicks the checkbox for option **Foo**, which in their view currently has **0** votes.
63
+ Similarly to before, the application optimistically updates the associated counter value to **1**, and transmits its own update op.
64
+
65
+ The service receives the op from **User A** first, and sequences their op updating **Foo** to **1** as **op 0**. **User B**'s op is received second, and is sequenced as **op 1**.
66
+
67
+ Both users then receive acknowledgement of their update, and receive **op 0** and **op 1** to be applied in order.
68
+ Both clients apply **op 0** by setting **Foo** to **1**.
69
+ Then both clients apply **op 1** by setting **Foo** to **1**.
70
+
71
+ But this isn't right.
72
+ Two different users voted for option **Foo**, but the counter now displays **1**.
73
+
74
+ `SharedCounter` solves this problem by expressing its operations in terms of _increments_ and _decrements_ rather than as direct value updates.
75
+
76
+ So for the scenario above, if the system was using `SharedCounter`s to represent the vote counts, **User A** would submit an op _incrementing_ **Foo** by **+1**, rather than updating the value of **Foo** from **0** to **1**.
77
+ At around the same time, **User B** would submit their own **+1** op for **Foo**.
78
+
79
+ Assuming the same sequencing, both users first apply **op 0** and increment their counter for **Foo** by **+1** (from **0** to **1**).
80
+ Next, they both apply **op 1** and increment their counter for **Foo** by **+1** a second time (from **1** to **2**).
81
+
82
+ Now both users see the right vote count for `Foo`!
83
+
84
+ ## Usage
85
+
86
+ The `SharedCounter` object provides a simple API surface for managing a shared integer whose value may be incremented and decremented by collaborators.
87
+
88
+ A new `SharedCounter` value will be initialized with its value set to `0`.
89
+ If you wish to initialize the counter to a different value, you may [modify the value](#incrementing--decrementing-the-value) before attaching the container, or before storing it in another shared object like a `SharedMap`.
90
+
91
+ ## Installation
92
+
93
+ The package containing the `SharedCounter` library is [@fluidframework/shared-counter](https://www.npmjs.com/package/@fluidframework/counter).
94
+
95
+ To get started, run the following from a terminal in your repository:
96
+
97
+ ```bash
98
+ npm install @fluidframework/shared-counter
99
+ ```
100
+
101
+ ### Creation
102
+
103
+ The workflow for creating a `SharedCounter` is effectively the same as many of our other DDSes.
104
+ For an example of how to create one, please see our workflow examples for [SharedMap creation][].
105
+
106
+ ### Incrementing / decrementing the value
107
+
108
+ Once you have created your `SharedCounter`, you can change its value using the [increment][] method.
109
+ This method accepts a positive or negative _integer_ to be applied to the shared value.
110
+
111
+ ```javascript
112
+ sharedCounter.increment(3); // Adds 3 to the current value
113
+ sharedCounter.increment(-5); // Subtracts 5 from the current value
114
+ ```
115
+
116
+ ### `incremented` event
117
+
118
+ The [incremented][] event is sent when a client in the collaborative session changes the counter value via the `increment` method.
119
+
120
+ Signature:
121
+
122
+ ```javascript
123
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void)
124
+ ```
125
+
126
+ By listening to this event, you can receive and apply the changes coming from other collaborators.
127
+ Consider the following code example for configuring a Counter widget:
128
+
129
+ ```javascript
130
+ const sharedCounter = container.initialObjects.sharedCounter;
131
+ let counterValue = sharedCounter.value;
132
+
133
+ const incrementButton = document.createElement("button");
134
+ button.textContent = "Increment";
135
+ const decrementButton = document.createElement("button");
136
+ button.textContent = "Decrement";
137
+
138
+ // Increment / decrement shared counter value when the corresponding button is clicked
139
+ incrementButton.addEventListener("click", () => sharedCounter.increment(1));
140
+ decrementButton.addEventListener("click", () => sharedCounter.increment(-1));
141
+
142
+ const counterValueLabel = document.createElement("label");
143
+ counterValueLabel.textContent = `${counterValue}`;
144
+
145
+ // This function will be called each time the shared counter value is incremented
146
+ // (including increments from this client).
147
+ // Update the local counter value and the corresponding label being displayed in the widget.
148
+ const updateCounterValueLabel = (delta) => {
149
+ counterValue += delta;
150
+ counterValueLabel.textContent = `${counterValue}`;
151
+ };
152
+
153
+ // Register to be notified when the counter is incremented
154
+ sharedCounter.on("incremented", updateCounterValueLabel);
155
+ ```
156
+
157
+ In the code above, whenever a user presses either the Increment or Decrement button, the `sharedCounter.increment` is called with +/- 1.
158
+ This causes the `incremented` event to be sent to all of the clients who have this container open.
159
+
160
+ Since `updateCounterValueLabel` is listening for all `incremented` events, the view will always refresh with the appropriate updated value any time a collaborator increments or decrements the counter value.
161
+
162
+ <!-- AUTO-GENERATED-CONTENT:START (README_API_DOCS_SECTION:includeHeading=TRUE) -->
163
+
164
+ <!-- prettier-ignore-start -->
165
+
166
+ <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
167
+
168
+ ## API Documentation
169
+
170
+ API documentation for **@fluidframework/counter** is available at <https://fluidframework.com/docs/apis/counter>.
171
+
172
+ <!-- prettier-ignore-end -->
173
+
174
+ <!-- AUTO-GENERATED-CONTENT:END -->
175
+
176
+ <!-- AUTO-GENERATED-CONTENT:START (README_TRADEMARK_SECTION:includeHeading=TRUE) -->
177
+
178
+ <!-- prettier-ignore-start -->
179
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
180
+
181
+ ## Trademark
182
+
183
+ This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
184
+
185
+ Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
186
+
187
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
188
+
189
+ <!-- prettier-ignore-end -->
190
+
191
+ <!-- AUTO-GENERATED-CONTENT:END -->
192
+
193
+ <!-- Links -->
194
+
195
+ [increment]: https://fluidframework.com/docs/apis/counter/isharedcounter-interface#increment-methodsignature
196
+ [incremented]: https://fluidframework.com/docs/apis/counter/isharedcounterevents-interface#_call_-callsignature
197
+ [optimistic dds]: https://fluidframework.com/docs/build/dds/#optimistic-data-structures
198
+ [sharedmap]: https://fluidframework.com/docs/data-structures/map
199
+ [sharedmap creation]: https://fluidframework.com/docs/data-structures/map/#creation
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-base-esm.json"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-lint.json"
4
+ }
@@ -1,4 +1,4 @@
1
1
  {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-common-report.json"
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-base.json"
4
4
  }
@@ -0,0 +1,46 @@
1
+ ## API Report File for "@fluidframework/counter"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
8
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
9
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
10
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
11
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
12
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
13
+ import { ISharedObject } from '@fluidframework/shared-object-base';
14
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
15
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
16
+ import { SharedObject } from '@fluidframework/shared-object-base';
17
+
18
+ // @alpha
19
+ export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
20
+ increment(incrementAmount: number): void;
21
+ value: number;
22
+ }
23
+
24
+ // @alpha
25
+ export interface ISharedCounterEvents extends ISharedObjectEvents {
26
+ // @eventProperty
27
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
28
+ }
29
+
30
+ // @alpha
31
+ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
32
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
33
+ // (undocumented)
34
+ protected applyStashedOp(op: unknown): void;
35
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
36
+ static getFactory(): IChannelFactory;
37
+ increment(incrementAmount: number): void;
38
+ // (undocumented)
39
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
40
+ protected onDisconnect(): void;
41
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
42
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
43
+ get value(): number;
44
+ }
45
+
46
+ ```
@@ -0,0 +1,150 @@
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
+ * @alpha
57
+ */
58
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
59
+ /**
60
+ * The counter value.
61
+ *
62
+ * @remarks Must be a whole number.
63
+ */
64
+ value: number;
65
+ /**
66
+ * Increments or decrements the value.
67
+ * Must only increment or decrement by a whole number value.
68
+ *
69
+ * @param incrementAmount - A whole number to increment or decrement by.
70
+ */
71
+ increment(incrementAmount: number): void;
72
+ }
73
+
74
+ /**
75
+ * Events sent by {@link SharedCounter}.
76
+ * @alpha
77
+ */
78
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
79
+ /**
80
+ * This event is raised when the counter is incremented or decremented.
81
+ *
82
+ * @param event - The event name.
83
+ * @param listener - An event listener.
84
+ *
85
+ * @eventProperty
86
+ */
87
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
88
+ }
89
+
90
+ /**
91
+ * {@inheritDoc ISharedCounter}
92
+ * @alpha
93
+ */
94
+ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
95
+ /**
96
+ * Create a new {@link SharedCounter}.
97
+ *
98
+ * @param runtime - The data store runtime to which the new `SharedCounter` will belong.
99
+ * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
100
+ *
101
+ * @returns newly create shared counter (but not attached yet)
102
+ */
103
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
104
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
105
+ /**
106
+ * Get a factory for {@link SharedCounter} to register with the data store.
107
+ *
108
+ * @returns a factory that creates and load SharedCounter
109
+ */
110
+ static getFactory(): IChannelFactory;
111
+ private _value;
112
+ /**
113
+ * {@inheritDoc ISharedCounter.value}
114
+ */
115
+ get value(): number;
116
+ /**
117
+ * {@inheritDoc ISharedCounter.increment}
118
+ */
119
+ increment(incrementAmount: number): void;
120
+ private incrementCore;
121
+ /**
122
+ * Create a summary for the counter.
123
+ *
124
+ * @returns The summary of the current state of the counter.
125
+ */
126
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
127
+ /**
128
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
129
+ */
130
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
131
+ /**
132
+ * Called when the object has disconnected from the delta stream.
133
+ */
134
+ protected onDisconnect(): void;
135
+ /**
136
+ * Process a counter operation (op).
137
+ *
138
+ * @param message - The message to prepare.
139
+ * @param local - Whether or not the message was sent by the local client.
140
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
141
+ * For messages from a remote client, this will be `undefined`.
142
+ */
143
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
144
+ /**
145
+ * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
146
+ */
147
+ protected applyStashedOp(op: unknown): void;
148
+ }
149
+
150
+ export { }
@@ -0,0 +1,25 @@
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
+ /* Excluded from this release type: ISharedCounter */
20
+
21
+ /* Excluded from this release type: ISharedCounterEvents */
22
+
23
+ /* Excluded from this release type: SharedCounter */
24
+
25
+ export { }
@@ -0,0 +1,25 @@
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
+ /* Excluded from this release type: ISharedCounter */
20
+
21
+ /* Excluded from this release type: ISharedCounterEvents */
22
+
23
+ /* Excluded from this release type: SharedCounter */
24
+
25
+ export { }