Changes API: How to Subscribe to Counter Changes
Following methods allow you to subscribe to counter changes:
ForCounter
Counter changes can be observed using ForCounter
method. This will subscribe changes from all counters with a given name, no matter in what document counter was changed.
Syntax
IChangesObservable<CounterChange> ForCounter(string counterName);
Parameters | ||
---|---|---|
counterName | string | Name of a counter to subscribe to. |
Return Value | |
---|---|
IChangesObservable<CounterChange> | Observable that allows to add subscriptions to counter notifications. |
Example
IDisposable subscription = store
.Changes()
.ForCounter("Likes")
.Subscribe(
change =>
{
switch (change.Type)
{
case CounterChangeTypes.Increment:
// do something
break;
}
});
ForCounterOfDocument
Specific counter changes of a given document can be observed using ForCounterOfDocument
method.
Syntax
IChangesObservable<CounterChange> ForCounterOfDocument(string documentId, string counterName);
Parameters | ||
---|---|---|
documentId | string | ID of a document to subscribe to. |
counterName | string | Name of a counter to subscribe to. |
Return Value | |
---|---|
IChangesObservable<CounterChange> | Observable that allows to add subscriptions to counter notifications. |
Example
IDisposable subscription = store
.Changes()
.ForCounterOfDocument("companies/1-A", "Likes")
.Subscribe(
change =>
{
switch (change.Type)
{
case CounterChangeTypes.Increment:
// do something
break;
}
});
ForCountersOfDocument
Counter changes of a specified document can be observed using ForCountersOfDocument
method.
Syntax
IChangesObservable<CounterChange> ForCountersOfDocument(string documentId);
Parameters | ||
---|---|---|
documentId | string | ID of a document to subscribe to. |
Return Value | |
---|---|
IChangesObservable<CounterChange> | Observable that allows to add subscriptions to counter notifications. |
Example
IDisposable subscription = store
.Changes()
.ForCountersOfDocument("companies/1-A")
.Subscribe(
change =>
{
switch (change.Type)
{
case CounterChangeTypes.Increment:
// do something
break;
}
});
ForAllCounters
Changes for all counters can be observed using ForAllCounters
method.
Syntax
IChangesObservable<CounterChange> ForAllCounters();
Return Value | |
---|---|
IChangesObservable<CounterChange> | Observable that allows to add subscriptions to counter notifications. |
Example
IDisposable subscription = store
.Changes()
.ForAllCounters()
.Subscribe(
change =>
{
switch (change.Type)
{
case CounterChangeTypes.Increment:
// do something
break;
}
});
CounterChange
Name | Type | Description |
---|---|---|
Type | CounterChangeTypes | Counter change type enum |
Name | string | Counter name |
Value | long | Counter value after the change |
DocumentId | string | Counter document identifier |
ChangeVector | string | Counter's ChangeVector |
CounterChangeTypes
Name | Value |
---|---|
None | 0 |
Put | 1 |
Delete | 2 |
Increment | 4 |
Remarks
To get more method overloads, especially ones supporting delegates, please add the
System.Reactive.Core package to your project.