Constructor
new ItemUpdate()
Used by the client library to provide a value object to each call of the SubscriptionListener#onItemUpdate event.
Methods
forEachChangedField(iterator)
Receives an iterator function and invokes it once per each field
changed with the last server update.
Note that if the Subscription mode of the involved Subscription is
COMMAND, then changed fields are meant as relative to the previous update
for the same key. On such tables if a DELETE command is received, all the
fields, excluding the key field, will be iterated as changed, with null value. All of this
is also true on tables that have the two-level behavior enabled, but in
case of DELETE commands second-level fields will not be iterated.
Note that the iterator is executed before this method returns.
Parameters:
Name | Type | Description |
---|---|---|
iterator |
ItemUpdateChangedFieldCallback |
Function instance that will be called once per each field changed on the last update received from the server. |
forEachField(iterator)
Receives an iterator function and invokes it once per each field
in the Subscription.
Note that the iterator is executed before this method returns.
Parameters:
Name | Type | Description |
---|---|---|
iterator |
ItemUpdateChangedFieldCallback |
Function instance that will be called once per each field in the Subscription. |
getItemName() → {String}
Inquiry method that retrieves the name of the item to which this update
pertains.
The name will be null if the related Subscription was initialized
using an "Item Group".
Returns:
the name of the item to which this update pertains.
- Type
- String
getItemPos() → {Number}
Inquiry method that retrieves the position in the "Item List" or "Item Group" of the item to which this update pertains.
Returns:
the 1-based position of the item to which this update pertains.
- Type
- Number
getValue(fieldNameOrPos) → {String}
Inquiry method that gets the value for a specified field, as received from the Server with the current or previous update.
Parameters:
Name | Type | Description |
---|---|---|
fieldNameOrPos |
String |
The field name or the 1-based position of the field within the "Field List" or "Field Schema". |
Throws:
-
if the specified field is not part of the Subscription.
Returns:
The value of the specified field; it can be null in the following cases:
- a null value has been received from the Server, as null is a possible value for a field;
- no value has been received for the field yet;
- the item is subscribed to with the COMMAND mode and a DELETE command is received (only the fields used to carry key and command informations are valued).
- Type
- String
isSnapshot() → {boolean}
Inquiry method that asks whether the current update belongs to the item snapshot (which carries the current item state at the time of Subscription). Snapshot events are sent only if snapshot information was requested for the items through Subscription#setRequestedSnapshot and precede the real time events. Snapshot informations take different forms in different subscription modes and can be spanned across zero, one or several update events. In particular:
- if the item is subscribed to with the RAW subscription mode, then no snapshot is sent by the Server;
- if the item is subscribed to with the MERGE subscription mode, then the snapshot consists of exactly one event, carrying the current value for all fields;
- if the item is subscribed to with the DISTINCT subscription mode, then the snapshot consists of some of the most recent updates; these updates are as many as specified through Subscription#setRequestedSnapshot, unless fewer are available;
- if the item is subscribed to with the COMMAND subscription mode, then the snapshot consists of an "ADD" event for each key that is currently present.
Returns:
true if the current update event belongs to the item snapshot; false otherwise.
- Type
- boolean
isValueChanged(fieldNameOrPos) → {boolean}
Inquiry method that asks whether the value for a field has changed after the reception of the last update from the Server for an item. If the Subscription mode is COMMAND then the change is meant as relative to the same key.
Parameters:
Name | Type | Description |
---|---|---|
fieldNameOrPos |
String |
The field name or the 1-based position of the field within the field list or field schema. |
Throws:
-
if the specified field is not part of the Subscription.
Returns:
Unless the Subscription mode is COMMAND, the return value is true in the following cases:
- It is the first update for the item;
- the new field value is different than the previous field value received for the item.
- it is the first update for the involved key value (i.e. the event carries an "ADD" command);
- the new field value is different than the previous field value received for the item, relative to the same key value (the event must carry an "UPDATE" command);
- the event carries a "DELETE" command (this applies to all fields other than the field used to carry key information).
- Type
- boolean