@fluidframework/counter 1.2.7 → 2.0.0-dev.1.3.0.96595
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/.mocharc.js +12 -0
- package/README.md +159 -1
- package/api-extractor.json +1 -1
- package/dist/counter.d.ts +33 -18
- package/dist/counter.d.ts.map +1 -1
- package/dist/counter.js +34 -19
- package/dist/counter.js.map +1 -1
- package/dist/counterFactory.d.ts +18 -1
- package/dist/counterFactory.d.ts.map +1 -1
- package/dist/counterFactory.js +18 -1
- package/dist/counterFactory.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +9 -4
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/counter.d.ts +33 -18
- package/lib/counter.d.ts.map +1 -1
- package/lib/counter.js +34 -19
- package/lib/counter.js.map +1 -1
- package/lib/counterFactory.d.ts +18 -1
- package/lib/counterFactory.d.ts.map +1 -1
- package/lib/counterFactory.js +18 -1
- package/lib/counterFactory.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +9 -4
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/interfaces.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +16 -16
- package/src/counter.ts +45 -28
- package/src/counterFactory.ts +20 -3
- package/src/index.ts +2 -2
- package/src/interfaces.ts +9 -4
- package/src/packageVersion.ts +1 -1
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/README.md
CHANGED
|
@@ -1,3 +1,161 @@
|
|
|
1
1
|
# @fluidframework/counter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
The `SharedCounter` distributed data structure (DDS) is used to store an integer counter value that can be modified by multiple clients simultaneously.
|
|
6
|
+
The data structure affords incrementing and decrementing the shared value via its `increment` method. Decrements are done by providing a negative value.
|
|
7
|
+
|
|
8
|
+
The `SharedCounter` is a specialized [Optimistic DDS][].
|
|
9
|
+
It operates on communicated _deltas_ (amounts by which the shared value should be incremented or decremented), rather than direct changes to the shared value.
|
|
10
|
+
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)).
|
|
11
|
+
|
|
12
|
+
Note that the `SharedCounter` only operates on integer values.
|
|
13
|
+
|
|
14
|
+
### Why a specialized DDS?
|
|
15
|
+
|
|
16
|
+
You may be asking yourself, why not just store the shared integer value directly in another DDS like a [SharedMap][]?
|
|
17
|
+
Why incur the overhead of another runtime type?
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
For a semantic data type like a counter, this can result in undesirable behavior.
|
|
21
|
+
|
|
22
|
+
#### SharedMap Example
|
|
23
|
+
|
|
24
|
+
Let's illustrate the issue with an example.
|
|
25
|
+
|
|
26
|
+
Consider a polling widget.
|
|
27
|
+
The widget displays a list of options and allows users to click a checkbox to vote for a given option.
|
|
28
|
+
Next to each option in the list, a live counter is displayed that shows the number of votes for that item.
|
|
29
|
+
|
|
30
|
+
Whenever a user checks an option, all users should see the counter corresponding to that option increment by 1.
|
|
31
|
+
|
|
32
|
+
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.
|
|
33
|
+
|
|
34
|
+
For simplicity, we will look at a scenario in which 2 users vote for the same option at around the same time.
|
|
35
|
+
|
|
36
|
+
Specifically, **User A** clicks the checkbox for option **Foo**, which currently has **0** votes.
|
|
37
|
+
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`.
|
|
38
|
+
|
|
39
|
+
The value change operation (op) is then transmitted to the service to be sequenced and eventually sent to other users in the collaborative session.
|
|
40
|
+
|
|
41
|
+
At around the same time, **User B** clicks the checkbox for option **Foo**, which in their view currently has **0** votes.
|
|
42
|
+
Similarly to before, the application optimistically updates the associated counter value to **1**, and transmits its own update op.
|
|
43
|
+
|
|
44
|
+
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**.
|
|
45
|
+
|
|
46
|
+
Both users then receive acknowledgement of their update, and receive **op 0** and **op 1** to be applied in order.
|
|
47
|
+
Both clients apply **op 0** by setting **Foo** to **1**.
|
|
48
|
+
Then both clients apply **op 1** by setting **Foo** to **1**.
|
|
49
|
+
|
|
50
|
+
But this isn't right.
|
|
51
|
+
Two different users voted for option **Foo**, but the counter now displays **1**.
|
|
52
|
+
|
|
53
|
+
`SharedCounter` solves this problem by expressing its operations in terms of *increments* and *decrements* rather than as direct value updates.
|
|
54
|
+
|
|
55
|
+
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**.
|
|
56
|
+
At around the same time, **User B** would submit their own **+1** op for **Foo**.
|
|
57
|
+
|
|
58
|
+
Assuming the same sequencing, both users first apply **op 0** and increment their counter for **Foo** by **+1** (from **0** to **1**).
|
|
59
|
+
Next, they both apply **op 1** and increment their counter for **Foo** by **+1** a second time (from **1** to **2**).
|
|
60
|
+
|
|
61
|
+
Now both users see the right vote count for `Foo`!
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
The `SharedCounter` object provides a simple API surface for managing a shared integer whose value may be incremented and decremented by collaborators.
|
|
66
|
+
|
|
67
|
+
A new `SharedCounter` value will be initialized with its value set to `0`.
|
|
68
|
+
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`.
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
The package containing the `SharedCounter` library is [@fluidframework/shared-counter](https://www.npmjs.com/package/@fluidframework/counter).
|
|
73
|
+
|
|
74
|
+
To get started, run the following from a terminal in your repository:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm install @fluidframework/shared-counter
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Creation
|
|
81
|
+
|
|
82
|
+
The workflow for creating a `SharedCounter` is effectively the same as many of our other DDSes.
|
|
83
|
+
For an example of how to create one, please see our workflow examples for [SharedMap creation][].
|
|
84
|
+
|
|
85
|
+
### Incrementing / decrementing the value
|
|
86
|
+
|
|
87
|
+
Once you have created your `SharedCounter`, you can change its value using the [increment][] method.
|
|
88
|
+
This method accepts a positive or negative *integer* to be applied to the shared value.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
sharedCounter.increment(3); // Adds 3 to the current value
|
|
93
|
+
sharedCounter.increment(-5); // Subtracts 5 from the current value
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### `incremented` event
|
|
97
|
+
|
|
98
|
+
The [incremented][] event is sent when a client in the collaborative session changes the counter value via the `increment` method.
|
|
99
|
+
|
|
100
|
+
Signature:
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
(event: "incremented", listener: (incrementAmount: number, newValue: number) => void)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
By listening to this event, you can receive and apply the changes coming from other collaborators.
|
|
107
|
+
Consider the following code example for configuring a Counter widget:
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
const sharedCounter = container.initialObjects.sharedCounter;
|
|
111
|
+
let counterValue = sharedCounter.value;
|
|
112
|
+
|
|
113
|
+
const incrementButton = document.createElement('button');
|
|
114
|
+
button.textContent = "Increment";
|
|
115
|
+
const decrementButton = document.createElement('button');
|
|
116
|
+
button.textContent = "Decrement";
|
|
117
|
+
|
|
118
|
+
// Increment / decrement shared counter value when the corresponding button is clicked
|
|
119
|
+
incrementButton.addEventListener('click', () => sharedCounter.increment(1));
|
|
120
|
+
decrementButton.addEventListener('click', () => sharedCounter.increment(-1));
|
|
121
|
+
|
|
122
|
+
const counterValueLabel = document.createElement('label');
|
|
123
|
+
counterValueLabel.textContent = `${counterValue}`;
|
|
124
|
+
|
|
125
|
+
// This function will be called each time the shared counter value is incremented
|
|
126
|
+
// (including increments from this client).
|
|
127
|
+
// Update the local counter value and the corresponding label being displayed in the widget.
|
|
128
|
+
const updateCounterValueLabel = (delta) => {
|
|
129
|
+
counterValue += delta;
|
|
130
|
+
counterValueLabel.textContent = `${counterValue}`;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Register to be notified when the counter is incremented
|
|
134
|
+
sharedCounter.on("incremented", updateCounterValueLabel);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
In the code above, whenever a user presses either the Increment or Decrement button, the `sharedCounter.increment` is called with +/- 1.
|
|
138
|
+
This causes the `incremented` event to be sent to all of the clients who have this container open.
|
|
139
|
+
|
|
140
|
+
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.
|
|
141
|
+
|
|
142
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_API_DOCS_SECTION:includeHeading=TRUE) -->
|
|
143
|
+
## API Documentation
|
|
144
|
+
|
|
145
|
+
API documentation for **@fluidframework/counter** is available at <https://fluidframework.com/docs/apis/counter>.
|
|
146
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
147
|
+
|
|
148
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_TRADEMARK_SECTION:includeHeading=TRUE) -->
|
|
149
|
+
## Trademark
|
|
150
|
+
|
|
151
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
152
|
+
Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
|
153
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
154
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
155
|
+
|
|
156
|
+
<!-- Links -->
|
|
157
|
+
[increment]: https://fluidframework.com/docs/apis/counter/isharedcounter-interface#increment-methodsignature
|
|
158
|
+
[incremented]: https://fluidframework.com/docs/apis/counter/isharedcounterevents-interface#_call_-callsignature
|
|
159
|
+
[Optimistic DDS]: https://fluidframework.com/docs/build/dds/#optimistic-data-structures
|
|
160
|
+
[SharedMap]: https://fluidframework.com/docs/data-structures/map
|
|
161
|
+
[SharedMap creation]: https://fluidframework.com/docs/data-structures/map/#creation
|
package/api-extractor.json
CHANGED
package/dist/counter.d.ts
CHANGED
|
@@ -8,48 +8,58 @@ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
|
|
|
8
8
|
import { IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
|
|
9
9
|
import { ISharedCounter, ISharedCounterEvents } from "./interfaces";
|
|
10
10
|
/**
|
|
11
|
-
* A
|
|
12
|
-
*
|
|
11
|
+
* A shared object that holds a number that can be incremented or decremented.
|
|
12
|
+
*
|
|
13
|
+
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
13
14
|
*
|
|
14
|
-
* @
|
|
15
|
-
* ### Creation
|
|
15
|
+
* @example Creating a `SharedCounter`:
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
18
|
+
* with a runtime and string ID:
|
|
18
19
|
*
|
|
19
20
|
* ```typescript
|
|
20
21
|
* const factory = SharedCounter.getFactory();
|
|
21
22
|
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
22
23
|
* ```
|
|
23
24
|
*
|
|
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`:
|
|
25
30
|
*
|
|
26
|
-
* Once created, you can call
|
|
31
|
+
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
32
|
+
* negative number:
|
|
27
33
|
*
|
|
28
34
|
* ```typescript
|
|
29
35
|
* counter.increment(10); // add 10 to the counter value
|
|
30
36
|
* counter.increment(-5); // subtract 5 from the counter value
|
|
31
37
|
* ```
|
|
32
38
|
*
|
|
33
|
-
* To observe changes to the value (including those from remote clients), register for the
|
|
39
|
+
* To observe changes to the value (including those from remote clients), register for the
|
|
40
|
+
* {@link ISharedCounterEvents | incremented} event:
|
|
34
41
|
*
|
|
35
42
|
* ```typescript
|
|
36
43
|
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
37
44
|
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
38
45
|
* });
|
|
39
46
|
* ```
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
40
49
|
*/
|
|
41
50
|
export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
|
|
42
51
|
/**
|
|
43
|
-
* Create a new
|
|
52
|
+
* Create a new {@link SharedCounter}.
|
|
53
|
+
*
|
|
54
|
+
* @param runtime - The data store runtime to which the new `SharedCounter` will belong.
|
|
55
|
+
* @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
|
|
44
56
|
*
|
|
45
|
-
* @param runtime - data store runtime the new shared counter belongs to
|
|
46
|
-
* @param id - optional name of the shared counter
|
|
47
57
|
* @returns newly create shared counter (but not attached yet)
|
|
48
58
|
*/
|
|
49
59
|
static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
|
|
50
60
|
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
|
|
51
61
|
/**
|
|
52
|
-
* Get a factory for SharedCounter to register with the data store.
|
|
62
|
+
* Get a factory for {@link SharedCounter} to register with the data store.
|
|
53
63
|
*
|
|
54
64
|
* @returns a factory that creates and load SharedCounter
|
|
55
65
|
*/
|
|
@@ -65,34 +75,39 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
65
75
|
increment(incrementAmount: number): void;
|
|
66
76
|
private incrementCore;
|
|
67
77
|
/**
|
|
68
|
-
* Create a summary for the counter
|
|
78
|
+
* Create a summary for the counter.
|
|
79
|
+
*
|
|
80
|
+
* @returns The summary of the current state of the counter.
|
|
69
81
|
*
|
|
70
|
-
* @returns the summary of the current state of the counter
|
|
71
82
|
* @internal
|
|
72
83
|
*/
|
|
73
84
|
protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
|
|
74
85
|
/**
|
|
75
86
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
87
|
+
*
|
|
76
88
|
* @internal
|
|
77
89
|
*/
|
|
78
90
|
protected loadCore(storage: IChannelStorageService): Promise<void>;
|
|
79
91
|
/**
|
|
80
92
|
* Called when the object has disconnected from the delta stream.
|
|
93
|
+
*
|
|
81
94
|
* @internal
|
|
82
95
|
*/
|
|
83
96
|
protected onDisconnect(): void;
|
|
84
97
|
/**
|
|
85
|
-
* Process a counter operation
|
|
98
|
+
* Process a counter operation (op).
|
|
86
99
|
*
|
|
87
|
-
* @param message -
|
|
88
|
-
* @param local -
|
|
100
|
+
* @param message - The message to prepare.
|
|
101
|
+
* @param local - Whether or not the message was sent by the local client.
|
|
89
102
|
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
90
|
-
* For messages from a remote client, this will be undefined
|
|
103
|
+
* For messages from a remote client, this will be `undefined`.
|
|
104
|
+
*
|
|
91
105
|
* @internal
|
|
92
106
|
*/
|
|
93
107
|
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
|
|
94
108
|
/**
|
|
95
109
|
* Not implemented.
|
|
110
|
+
*
|
|
96
111
|
* @internal
|
|
97
112
|
*/
|
|
98
113
|
protected applyStashedOp(): void;
|
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;AAEH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EACrB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAA2B,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAE7G,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EACrB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAA2B,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAE7G,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAsBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,aAAc,SAAQ,YAAY,CAAC,oBAAoB,CAAE,YAAW,cAAc;IAC3F;;;;;;;OAOG;WACW,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,aAAa;gBAIrE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,kBAAkB;IAIvF;;;;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;;;;;;OAMG;IACH,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAU5E;;;;OAIG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;;;OAIG;IACH,SAAS,CAAC,YAAY,IAAI,IAAI;IAE9B;;;;;;;;;OASG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;IAezG;;;;OAIG;IACH,SAAS,CAAC,cAAc;CAG3B"}
|
package/dist/counter.js
CHANGED
|
@@ -11,35 +11,44 @@ const shared_object_base_1 = require("@fluidframework/shared-object-base");
|
|
|
11
11
|
const counterFactory_1 = require("./counterFactory");
|
|
12
12
|
const snapshotFileName = "header";
|
|
13
13
|
/**
|
|
14
|
-
* A
|
|
15
|
-
*
|
|
14
|
+
* A shared object that holds a number that can be incremented or decremented.
|
|
15
|
+
*
|
|
16
|
+
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
16
17
|
*
|
|
17
|
-
* @
|
|
18
|
-
* ### Creation
|
|
18
|
+
* @example Creating a `SharedCounter`:
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
21
|
+
* with a runtime and string ID:
|
|
21
22
|
*
|
|
22
23
|
* ```typescript
|
|
23
24
|
* const factory = SharedCounter.getFactory();
|
|
24
25
|
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
25
26
|
* ```
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
+
* The initial value of a new `SharedCounter` is 0.
|
|
29
|
+
* If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
|
|
30
|
+
* attaching the Container, or before inserting it into an existing shared object.
|
|
31
|
+
*
|
|
32
|
+
* @example Using the `SharedCounter`:
|
|
28
33
|
*
|
|
29
|
-
* Once created, you can call
|
|
34
|
+
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
35
|
+
* negative number:
|
|
30
36
|
*
|
|
31
37
|
* ```typescript
|
|
32
38
|
* counter.increment(10); // add 10 to the counter value
|
|
33
39
|
* counter.increment(-5); // subtract 5 from the counter value
|
|
34
40
|
* ```
|
|
35
41
|
*
|
|
36
|
-
* To observe changes to the value (including those from remote clients), register for the
|
|
42
|
+
* To observe changes to the value (including those from remote clients), register for the
|
|
43
|
+
* {@link ISharedCounterEvents | incremented} event:
|
|
37
44
|
*
|
|
38
45
|
* ```typescript
|
|
39
46
|
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
40
47
|
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
41
48
|
* });
|
|
42
49
|
* ```
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
43
52
|
*/
|
|
44
53
|
class SharedCounter extends shared_object_base_1.SharedObject {
|
|
45
54
|
constructor(id, runtime, attributes) {
|
|
@@ -47,17 +56,18 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
47
56
|
this._value = 0;
|
|
48
57
|
}
|
|
49
58
|
/**
|
|
50
|
-
* Create a new
|
|
59
|
+
* Create a new {@link SharedCounter}.
|
|
60
|
+
*
|
|
61
|
+
* @param runtime - The data store runtime to which the new `SharedCounter` will belong.
|
|
62
|
+
* @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
|
|
51
63
|
*
|
|
52
|
-
* @param runtime - data store runtime the new shared counter belongs to
|
|
53
|
-
* @param id - optional name of the shared counter
|
|
54
64
|
* @returns newly create shared counter (but not attached yet)
|
|
55
65
|
*/
|
|
56
66
|
static create(runtime, id) {
|
|
57
67
|
return runtime.createChannel(id, counterFactory_1.CounterFactory.Type);
|
|
58
68
|
}
|
|
59
69
|
/**
|
|
60
|
-
* Get a factory for SharedCounter to register with the data store.
|
|
70
|
+
* Get a factory for {@link SharedCounter} to register with the data store.
|
|
61
71
|
*
|
|
62
72
|
* @returns a factory that creates and load SharedCounter
|
|
63
73
|
*/
|
|
@@ -91,9 +101,10 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
91
101
|
this.emit("incremented", incrementAmount, this._value);
|
|
92
102
|
}
|
|
93
103
|
/**
|
|
94
|
-
* Create a summary for the counter
|
|
104
|
+
* Create a summary for the counter.
|
|
105
|
+
*
|
|
106
|
+
* @returns The summary of the current state of the counter.
|
|
95
107
|
*
|
|
96
|
-
* @returns the summary of the current state of the counter
|
|
97
108
|
* @internal
|
|
98
109
|
*/
|
|
99
110
|
summarizeCore(serializer) {
|
|
@@ -106,6 +117,7 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
106
117
|
}
|
|
107
118
|
/**
|
|
108
119
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
120
|
+
*
|
|
109
121
|
* @internal
|
|
110
122
|
*/
|
|
111
123
|
async loadCore(storage) {
|
|
@@ -114,16 +126,18 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
114
126
|
}
|
|
115
127
|
/**
|
|
116
128
|
* Called when the object has disconnected from the delta stream.
|
|
129
|
+
*
|
|
117
130
|
* @internal
|
|
118
131
|
*/
|
|
119
132
|
onDisconnect() { }
|
|
120
133
|
/**
|
|
121
|
-
* Process a counter operation
|
|
134
|
+
* Process a counter operation (op).
|
|
122
135
|
*
|
|
123
|
-
* @param message -
|
|
124
|
-
* @param local -
|
|
136
|
+
* @param message - The message to prepare.
|
|
137
|
+
* @param local - Whether or not the message was sent by the local client.
|
|
125
138
|
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
126
|
-
* For messages from a remote client, this will be undefined
|
|
139
|
+
* For messages from a remote client, this will be `undefined`.
|
|
140
|
+
*
|
|
127
141
|
* @internal
|
|
128
142
|
*/
|
|
129
143
|
processCore(message, local, localOpMetadata) {
|
|
@@ -140,10 +154,11 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
140
154
|
}
|
|
141
155
|
/**
|
|
142
156
|
* Not implemented.
|
|
157
|
+
*
|
|
143
158
|
* @internal
|
|
144
159
|
*/
|
|
145
160
|
applyStashedOp() {
|
|
146
|
-
throw new Error("
|
|
161
|
+
throw new Error("Not implemented");
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
exports.SharedCounter = SharedCounter;
|
package/dist/counter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+EAA8F;AAO9F,+DAA4D;AAE5D,2EAA6G;AAC7G,qDAAkD;
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+EAA8F;AAO9F,+DAA4D;AAE5D,2EAA6G;AAC7G,qDAAkD;AAqBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,aAAc,SAAQ,iCAAkC;IAajE,YAAY,EAAU,EAAE,OAA+B,EAAE,UAA8B;QACnF,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAY7C,WAAM,GAAW,CAAC,CAAC;IAX3B,CAAC;IAdD;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAC7D,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,+BAAc,CAAC,IAAI,CAAkB,CAAC;IAC3E,CAAC;IAMD;;;;OAIG;IACI,MAAM,CAAC,UAAU;QACpB,OAAO,IAAI,+BAAc,EAAE,CAAC;IAChC,CAAC;IAID;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,eAAuB;QACpC,uGAAuG;QACvG,wGAAwG;QACxG,IAAI,eAAe,GAAG,CAAC,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACvD;QAED,MAAM,EAAE,GAAwB;YAC5B,IAAI,EAAE,WAAW;YACjB,eAAe;SAClB,CAAC;QAEF,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QACpC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;IAEO,aAAa,CAAC,eAAuB;QACzC,IAAI,CAAC,MAAM,IAAI,eAAe,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACO,aAAa,CAAC,UAA4B;QAChD,kCAAkC;QAClC,MAAM,OAAO,GAA2B;YACpC,KAAK,EAAE,IAAI,CAAC,KAAK;SACpB,CAAC;QAEF,wCAAwC;QACxC,OAAO,IAAA,4CAAuB,EAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,QAAQ,CAAC,OAA+B;QACpD,MAAM,OAAO,GAAG,MAAM,IAAA,2BAAY,EAAyB,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAEtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACO,YAAY,KAAW,CAAC;IAElC;;;;;;;;;OASG;IACO,WAAW,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,kCAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA+B,CAAC;YAEnD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACb,KAAK,WAAW;oBACZ,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;oBACvC,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAED;;;;OAIG;IACO,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA/HD,sCA+HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the operation (op) format for incrementing the {@link SharedCounter}.\n */\ninterface IIncrementOperation {\n type: \"increment\";\n incrementAmount: number;\n}\n\n/**\n * @remarks Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n /**\n * The value of the counter.\n */\n value: number;\n}\n\nconst snapshotFileName = \"header\";\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 class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n /**\n * Create a new {@link SharedCounter}.\n *\n * @param runtime - The data store runtime to which the new `SharedCounter` will belong.\n * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.\n *\n * @returns newly create shared counter (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter {\n return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n }\n\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_counter_\");\n }\n\n /**\n * Get a factory for {@link SharedCounter} to register with the data store.\n *\n * @returns a factory that creates and load SharedCounter\n */\n public static getFactory(): IChannelFactory {\n return new CounterFactory();\n }\n\n private _value: number = 0;\n\n /**\n * {@inheritDoc ISharedCounter.value}\n */\n public get value(): number {\n return this._value;\n }\n\n /**\n * {@inheritDoc ISharedCounter.increment}\n */\n public increment(incrementAmount: number): void {\n // Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n // increments are applied affects the result. A more-robust solution would be required to support this.\n if (incrementAmount % 1 !== 0) {\n throw new Error(\"Must increment by a whole number\");\n }\n\n const op: IIncrementOperation = {\n type: \"increment\",\n incrementAmount,\n };\n\n this.incrementCore(incrementAmount);\n this.submitLocalMessage(op);\n }\n\n private incrementCore(incrementAmount: number): void {\n this._value += incrementAmount;\n this.emit(\"incremented\", incrementAmount, this._value);\n }\n\n /**\n * Create a summary for the counter.\n *\n * @returns The summary of the current state of the counter.\n *\n * @internal\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // Get a serializable form of data\n const content: ICounterSnapshotFormat = {\n value: this.value,\n };\n\n // And then construct the summary for it\n return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n *\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n this._value = content.value;\n }\n\n /**\n * Called when the object has disconnected from the delta stream.\n *\n * @internal\n */\n protected onDisconnect(): void { }\n\n /**\n * Process a counter operation (op).\n *\n * @param message - The message to prepare.\n * @param local - Whether or not the message was sent by the local client.\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be `undefined`.\n *\n * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as IIncrementOperation;\n\n switch (op.type) {\n case \"increment\":\n this.incrementCore(op.incrementAmount);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n /**\n * Not implemented.\n *\n * @internal\n */\n protected applyStashedOp() {\n throw new Error(\"Not implemented\");\n }\n}\n"]}
|
package/dist/counterFactory.d.ts
CHANGED
|
@@ -5,17 +5,34 @@
|
|
|
5
5
|
import { IChannelAttributes, IFluidDataStoreRuntime, IChannelServices, IChannelFactory } from "@fluidframework/datastore-definitions";
|
|
6
6
|
import { ISharedCounter } from "./interfaces";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedCounter}.
|
|
9
|
+
*
|
|
10
|
+
* @sealed
|
|
9
11
|
*/
|
|
10
12
|
export declare class CounterFactory implements IChannelFactory {
|
|
13
|
+
/**
|
|
14
|
+
* Static value for {@link CounterFactory."type"}.
|
|
15
|
+
*/
|
|
11
16
|
static readonly Type = "https://graph.microsoft.com/types/counter";
|
|
17
|
+
/**
|
|
18
|
+
* Static value for {@link CounterFactory.attributes}.
|
|
19
|
+
*/
|
|
12
20
|
static readonly Attributes: IChannelAttributes;
|
|
21
|
+
/**
|
|
22
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
|
|
23
|
+
*/
|
|
13
24
|
get type(): string;
|
|
25
|
+
/**
|
|
26
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
|
|
27
|
+
*/
|
|
14
28
|
get attributes(): IChannelAttributes;
|
|
15
29
|
/**
|
|
16
30
|
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
|
|
17
31
|
*/
|
|
18
32
|
load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, attributes: IChannelAttributes): Promise<ISharedCounter>;
|
|
33
|
+
/**
|
|
34
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
35
|
+
*/
|
|
19
36
|
create(document: IFluidDataStoreRuntime, id: string): ISharedCounter;
|
|
20
37
|
}
|
|
21
38
|
//# sourceMappingURL=counterFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counterFactory.d.ts","sourceRoot":"","sources":["../src/counterFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C
|
|
1
|
+
{"version":3,"file":"counterFactory.d.ts","sourceRoot":"","sources":["../src/counterFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C;;;;GAIG;AACH,qBAAa,cAAe,YAAW,eAAe;IAClD;;OAEG;IACH,gBAAuB,IAAI,+CAA+C;IAE1E;;OAEG;IACH,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;OAEG;IACU,IAAI,CACb,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAM5D;;OAEG;IACI,MAAM,CAAC,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,GAAG,cAAc;CAK9E"}
|
package/dist/counterFactory.js
CHANGED
|
@@ -8,12 +8,20 @@ exports.CounterFactory = void 0;
|
|
|
8
8
|
const counter_1 = require("./counter");
|
|
9
9
|
const packageVersion_1 = require("./packageVersion");
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedCounter}.
|
|
12
|
+
*
|
|
13
|
+
* @sealed
|
|
12
14
|
*/
|
|
13
15
|
class CounterFactory {
|
|
16
|
+
/**
|
|
17
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
|
|
18
|
+
*/
|
|
14
19
|
get type() {
|
|
15
20
|
return CounterFactory.Type;
|
|
16
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
|
|
24
|
+
*/
|
|
17
25
|
get attributes() {
|
|
18
26
|
return CounterFactory.Attributes;
|
|
19
27
|
}
|
|
@@ -25,6 +33,9 @@ class CounterFactory {
|
|
|
25
33
|
await counter.load(services);
|
|
26
34
|
return counter;
|
|
27
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
38
|
+
*/
|
|
28
39
|
create(document, id) {
|
|
29
40
|
const counter = new counter_1.SharedCounter(id, document, this.attributes);
|
|
30
41
|
counter.initializeLocal();
|
|
@@ -32,7 +43,13 @@ class CounterFactory {
|
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
45
|
exports.CounterFactory = CounterFactory;
|
|
46
|
+
/**
|
|
47
|
+
* Static value for {@link CounterFactory."type"}.
|
|
48
|
+
*/
|
|
35
49
|
CounterFactory.Type = "https://graph.microsoft.com/types/counter";
|
|
50
|
+
/**
|
|
51
|
+
* Static value for {@link CounterFactory.attributes}.
|
|
52
|
+
*/
|
|
36
53
|
CounterFactory.Attributes = {
|
|
37
54
|
type: CounterFactory.Type,
|
|
38
55
|
snapshotFormatVersion: "0.1",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counterFactory.js","sourceRoot":"","sources":["../src/counterFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,uCAA0C;AAE1C,qDAA8C;AAE9C
|
|
1
|
+
{"version":3,"file":"counterFactory.js","sourceRoot":"","sources":["../src/counterFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,uCAA0C;AAE1C,qDAA8C;AAE9C;;;;GAIG;AACH,MAAa,cAAc;IAevB;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,cAAc,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,cAAc,CAAC,UAAU,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CACb,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAC9B,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;IACnB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,QAAgC,EAAE,EAAU;QACtD,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;IACnB,CAAC;;AAjDL,wCAkDC;AAjDG;;GAEG;AACoB,mBAAI,GAAG,2CAA2C,CAAC;AAE1E;;GAEG;AACoB,yBAAU,GAAuB;IACpD,IAAI,EAAE,cAAc,CAAC,IAAI;IACzB,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,2BAAU;CAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelServices,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { SharedCounter } from \"./counter\";\nimport { 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 /**\n * Static value for {@link CounterFactory.\"type\"}.\n */\n public static readonly Type = \"https://graph.microsoft.com/types/counter\";\n\n /**\n * Static value for {@link CounterFactory.attributes}.\n */\n public static readonly Attributes: IChannelAttributes = {\n type: CounterFactory.Type,\n snapshotFormatVersion: \"0.1\",\n packageVersion: pkgVersion,\n };\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.\"type\"}\n */\n public get type(): string {\n return CounterFactory.Type;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}\n */\n public get attributes(): IChannelAttributes {\n return CounterFactory.Attributes;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n */\n public async load(\n runtime: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<ISharedCounter> {\n const counter = new SharedCounter(id, runtime, attributes);\n await counter.load(services);\n return counter;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n */\n public create(document: IFluidDataStoreRuntime, id: string): ISharedCounter {\n const counter = new SharedCounter(id, document, this.attributes);\n counter.initializeLocal();\n return counter;\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* This
|
|
7
|
-
* which holds a number that can be incremented or decremented.
|
|
6
|
+
* This library contains the {@link SharedCounter} distributed data structure.
|
|
7
|
+
* A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
|
|
8
8
|
*
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
package/dist/index.js
CHANGED
|
@@ -15,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
/**
|
|
18
|
-
* This
|
|
19
|
-
* which holds a number that can be incremented or decremented.
|
|
18
|
+
* This library contains the {@link SharedCounter} distributed data structure.
|
|
19
|
+
* A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
|
|
20
20
|
*
|
|
21
21
|
* @packageDocumentation
|
|
22
22
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH;;;;;GAKG;AAEH,4CAA0B;AAC1B,+CAA6B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH;;;;;GAKG;AAEH,4CAA0B;AAC1B,+CAA6B","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 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 * from \"./counter\";\nexport * from \"./interfaces\";\n"]}
|