Skip to main content

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
counterNamestringName 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
documentIdstringID of a document to subscribe to.
counterNamestringName 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
documentIdstringID 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

NameTypeDescription
TypeCounterChangeTypesCounter change type enum
NamestringCounter name
ValuelongCounter value after the change
DocumentIdstringCounter document identifier
ChangeVectorstringCounter's ChangeVector

CounterChangeTypes

NameValue
None0
Put1
Delete2
Increment4

Remarks

To get more method overloads, especially ones supporting delegates, please add the System.Reactive.Core package to your project.