Caplin Trader 4.8.0

Class: module:caplin/services/testing/RecordStub

module:caplin/services/testing/RecordStub

Constructor

new module:caplin/services/testing/RecordStub(subject, initialFieldData, generators)

Created by module:caplin/services/testing/MessageServiceStub as a representation of a record that can be subscribed to. Used to send updated field data to subscribers, and to monitor the number of subscriptions made for the record's subject.

This class uses emitr.

Parameters:
Name Type Description
subject String The subject for this record
initialFieldData Object Data fields that will be sent to component when it subscribes. If provided, these will also be editable by user in workbench tool.
generators Array List of data generators.

Members

(static) EVENTS

A map of events that this class may trigger.

Contains the following events:

DATA_CHANGED
Triggered when some of the record's field data has changed.
PARAMETERS
{Map} updatedFields A map of field names to their new values.
STATUS_CHANGED
Triggered when the record's status has changed.
SUBSCRIPTIONS_CHANGED
Triggered when a record stub's number of all subscriptions, or number of paused subscriptions changes.
PARAMETERS
module:caplin/services/testing/RecordStub record The record stub that fired the event.
ERROR
Triggered when the record stub is put into an error state.
PARAMETERS
module:caplin/services/messaging/SubscriptionError type The error type.

Methods

addDataGenerator(generatorToAdd)

Adds a module:caplin/workbench/model/DataGenerator to this record, which will then be used to auto-generate data updates, using the record's initial values as seeds. The update rate can be set using module:caplin/services/testing/RecordStub#setUpdateInterval.
Parameters:
Name Type Description
generatorToAdd module:caplin/workbench/model/DataGenerator The data generator that should be used to generate auto updates for this record.

clearUpdateInterval()

Stops this record from providing automatic updates.

getFieldData() → {Map}

Gets a map of all the record's fields and their values.
Returns:
A map of all field data for this record.
Type
Map

getPausedSubscriptionCount() → {Number}

Returns the number of paused subscriptions there are for this record.
Returns:
The number of paused subscriptions for this record.
Type
Number

getStatus() → {module:caplin/services/messaging/SubscriptionStatus}

Gets the current status of the record.
Returns:
The current status of the record.
Type
module:caplin/services/messaging/SubscriptionStatus

getSubject() → {String}

Gets the subject that maps to this record.
Returns:
The subject of the record.
Type
String

getSubscriptionCount() → {Number}

Returns the number of subscriptions there are for this record. This includes both active and paused subscriptions.
Returns:
the number of subscriptions for this record.
Type
Number

removeDataGenerator(generatorToRemove)

Parameters:
Name Type Description
generatorToRemove module:caplin/workbench/model/DataGenerator The data generator that should no longer be used to generate auto updates for this record.

setErrorType({@link)

Sets the error type of this record, and then informs all listeners of the change.
Parameters:
Name Type Description
{@link module:caplin/services/messaging/SubscriptionError} errorType The type of error that this record is in.

setFieldData(dataUpdates, metaData)

Sets new values for fields on this record, and then informs all subscribers of the change.
Parameters:
Name Type Description
dataUpdates Map A map of new field values.
metaData Map A map of meta data

setStatus(status)

Sets the status of the record {@see module:caplin/services/messaging/SubscriptionStatus}.
Parameters:
Name Type Description
status module:caplin/services/messaging/SubscriptionStatus The new status of this record.

setUpdateInterval(intervalPeriod)

Sets the update rate of generated data for this record {@see module:caplin/services/testing/RecordStub#addDataGenerator}.
Parameters:
Name Type Description
intervalPeriod Number The time in milliseconds between auto-generated data updates for this record.