Interface AttributeValuesEnumeratorInterface

The AttributeValuesEnumeratorInterface is used to query available values of a string attribute (AttributeInfoInterface).

The AttributeValuesEnumeratorInterface is created from a connected DataSessionInterface by the use of the DataSessionInterface.createAttributeValuesEnumerator function.

/** 
* Sample to illustrate the use of an AttributeValuesEnumeratorInterface.
* The AttributeValuesEnumeratorInterface is used to query available values of a string attribute.
*/
import {
AttributesDictionaryInterface, AttributeInfoInterface, AttributeType, DataSessionInterface,
AttributeValuesEnumeratorInterface, AttributeValuesEnumeratorInterfaceSignal,
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;

// the attribute name to query
const lAttributeNameToQuery : string = 'CompletionStatus';
// MAKE SURE the attributes "CompletionStatus" is relevant
const lAttributeDictionary : AttributesDictionaryInterface = lDataSession.getAttributesDictionary();
const lAttributeInfo : AttributeInfoInterface | undefined = lAttributeDictionary.getAttributeInfo(lAttributeNameToQuery);
// make sure the attribute is a string one
console.assert((lAttributeInfo !== undefined) && (lAttributeInfo.getAttributeType() === AttributeType.ATTR_STRING));
// the expected values
const lAvailableValues : Array<string> = [];
// using an attribute value enumerator to query available values
const lAttributeValueEnumerator : AttributeValuesEnumeratorInterface = lDataSession.createAttributeValuesEnumerator();

// we may have queried only values that strictly begin with a fixed pattern
// but here we want to query all values => use an empty string
// WARNING : the enumeration is case sensitive !!!
const lAttributeInitResult : boolean = lAttributeValueEnumerator.initEnumeration(lAttributeNameToQuery, '');
// make sure the enumeration has started
console.assert(lAttributeInitResult);

// make sure we are ready to get the result
lAttributeValueEnumerator.addEventListener(AttributeValuesEnumeratorInterfaceSignal.AttributesEnumerationReady, () : void => {
// make sure everything went well
if(lAttributeValueEnumerator.getLastError() !== undefined)
{
console.log('Enumeration request failed');
return;
}
// retrieve the enumeration result
const lValues : Array<string> = lAttributeValueEnumerator.getEnumerationResult();
// push the result to our array
lAvailableValues.push(...lValues);
// and if further values can be queries, go on !
if(lAttributeValueEnumerator.hasOtherValues())
{
lAttributeValueEnumerator.nextValues();
}
else
{
// we have done it !
// display the available values
console.log(lAvailableValues);
// perhaps here some GUI code ?
}
});

// and start the enumeration !
lAttributeValueEnumerator.nextValues();

or asynchronously :
/** 
* Sample to illustrate the asynchronous use of an AttributeValuesEnumeratorInterface.
* The AttributeValuesEnumeratorInterface is used to query available values of a string attribute.
*/
import {
AttributesDictionaryInterface, AttributeInfoInterface, AttributeType, DataSessionInterface,
AttributeValuesEnumeratorInterface, AsyncAttributeEnumerationResult,
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;

// the attribute name to query
const lAttributeNameToQuery : string = 'CompletionStatus';
// MAKE SURE the attributes "CompletionStatus" is relevant
const lAttributeDictionary : AttributesDictionaryInterface = lDataSession.getAttributesDictionary();
const lAttributeInfo : AttributeInfoInterface | undefined = lAttributeDictionary.getAttributeInfo(lAttributeNameToQuery);
// make sure the attribute is a string one
console.assert((lAttributeInfo !== undefined) && (lAttributeInfo.getAttributeType() === AttributeType.ATTR_STRING));
// the expected values
const lAvailableValues : Array<string> = [];
// using an attribute value enumerator to query available values
const lAttributeValueEnumerator : AttributeValuesEnumeratorInterface = lDataSession.createAttributeValuesEnumerator();

// we may have queried only values that strictly begin with a fixed pattern
// but here we want to query all values => use an empty string
// WARNING : the enumeration is case sensitive !!!
const lAttributeInitResult : boolean = lAttributeValueEnumerator.initEnumeration(lAttributeNameToQuery, '');
// make sure the enumeration has started
console.assert(lAttributeInitResult);

const fetchValues = async () : Promise<void> => {
// loop till no other values are available
let lHasAvailableValues : boolean = true;
let lRequestResult : AsyncAttributeEnumerationResult;
while (lHasAvailableValues)
{
lRequestResult = await lAttributeValueEnumerator.asyncNextValues();
// make sure we are ready to get the result
// make sure everything went well
if(lRequestResult.error !== undefined || lRequestResult.value === undefined)
{
console.log('Enumeration request failed');
return;
}
// retrieve the enumeration result
const lValues : Array<string> = lRequestResult.value;
// push the result to our array
lAvailableValues.push(...lValues);
// and if further values can be queries, go on !
lHasAvailableValues = lAttributeValueEnumerator.hasOtherValues();
}
// we have done it !
// display the available values
console.log(lAvailableValues);
// perhaps here some GUI code ?
};
fetchValues();

The AttributeValuesEnumeratorInterface must be used to fully handle FilterAttributeInterface.
Metadata

interface AttributeValuesEnumeratorInterface {
    addEventListener(pType, pListener, pObject): string;
    addEventListener(pType, pListener): string;
    areSignalsBlocked(): boolean;
    asyncNextValues(): Promise<AsyncAttributeEnumerationResult>;
    blockSignals(pBlock): void;
    cancel(): boolean;
    dispose(): void;
    getAttributeName(): string;
    getAttributesValueEnumeratorId(): string;
    getEnumerationRequest(): string;
    getEnumerationResult(): string[];
    getInfiniteObjectType(): InfiniteObjectType;
    getLastError(): InfiniteError;
    getLastRequestId(): string;
    hasEventListener(pType, pListener): boolean;
    hasEventListenerById(pId): boolean;
    hasOtherValues(): boolean;
    initEnumeration(pAttributeName, pStartsWith): boolean;
    isCancelled(): boolean;
    isDisposed(): boolean;
    isRunning(): boolean;
    nextValues(): boolean;
    removeAllEventListeners(): boolean;
    removeEventListener(pType, pListener, pObject): boolean;
    removeEventListener(pType, pListener): boolean;
    removeEventListenerById(pId): boolean;
}

Hierarchy (view full)

Methods

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal. It is possible to add an object that will be included in the callback to avoid creating too many closures. Calling twice addEventListener with the same parameters results in the second call to be ignored, only unique pairs callback / object are allowed, in order to avoid calling multiple times the same thing.

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.
    • pObject: Object
      in
      The optional object the callback will be called with when the given event fires.

    Returns string

    The id of the inserted callback (actually an UUID).

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal.

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.

    Returns string

    The id of the inserted callback (actually an UUID).

  • Tells if signals sent by the object are blocked or not.

    If signals are blocked, no signal will be emitted nor buffered, such signal will be lost.

    Returns boolean

    true if signals are blocked.

  • Asynchronously asks for a attribute values enumeration.

    This call may be used to implement a value completer.

    A signal AttributeValuesEnumeratorInterfaceSignal.AttributesEnumerationReady will be sent shortly after telling the AttributeValuesEnumeratorInterface is ready. Then call getEnumerationResult to get the actual results of the call.

    No more than 5 AttributeValuesEnumeratorInterface requests can run simultaneously, but only one request can be run at a time for a given AttributeValuesEnumeratorInterface. If you want to run multiple attribute values requests simultaneously, then create multiple AttributeValuesEnumeratorInterfaces.

    Returns a promise.

    If a request is already running on this AttributeValuesEnumeratorInterface, if initEnumeration failed, if no other values are available (hasOtherValues returns false), or if too many enumeration requests are running simultaneously, the result will be an error.

    Returns Promise<AsyncAttributeEnumerationResult>

    A promise. The promise is resolved with the reason (success, cancelled, disposed, bad input). In case of success, the promise contains the requested Array.

  • Blocks / Unblocks all signals sent by the object.

    If signals are blocked, no signal will be emitted nor buffered, such signal will be lost.

    Parameters

    • pBlock: boolean
      in
      If set to true, all further signals will be silently discarded.

    Returns void

  • Cancels a running enumeration request (nextValues).

    If the AttributeValuesEnumeratorInterface is running, the current request will be cancelled. If the AttributeValuesEnumeratorInterface is not running, returns false.

    Returns boolean

    true if the running request was cancelled.

  • Gets the name of the attribute that was set by initEnumeration.

    getAttributeName is empty by default, which is invalid.

    Returns string

    The attribute name that was set by initEnumeration.

  • Gets the id of the AttributeValuesEnumeratorInterface.

    Returns string

    The id of the AttributeValuesEnumeratorInterface.

  • Gets the request start value of the attribute that was set by initEnumeration.

    All attribute values that begins exactly with this value will be retrieved (no fuzzy search). In order to search for all available values, the enumeration request must be set with an empty string.

    getEnumerationRequest is empty by default.

    Returns string

    The request start value that was set by initEnumeration.

  • Gets the list of all values from the last call to the nextValues function.

    An array of string is returned if the AttributeValuesEnumeratorInterface has finished computing. Use addEventListener on the event AttributeValuesEnumeratorInterfaceSignal.AttributesEnumerationReady to know when the AttributeValuesEnumeratorInterface is ready.

    The hasOtherValues tells if more values are available, then you may call nextValues.

    DO NOT modify this data in place, this results in undefined behavior.

    Returns string[]

    const
    The list of available values, or undefined if the AttributeValuesEnumeratorInterface is fetching or if the AttributeValuesEnumeratorInterface is in error or cancelled.
  • Gets the last error returned by the attribute values retrieval procedure.

    Returns undefined if no error occurred.

    Returns InfiniteError

    The last error.

  • Each call to nextValues is assigned a request id.

    This call tels the id of the last call to nextValues.

    Returns string

    The id of the last call to nextValues.

  • Tells if the EventDispatcher has such a callback registered for the given event type.

    Parameters

    • pType: string
      in
      The type of the event to test.
    • pListener: tListenerCallback
      in
      The listener function that gets tested.

    Returns boolean

    true if such a listener is installed for the given type of event.

  • Tells if the EventDispatcher has such a callback registered for the given callback id.

    Parameters

    • pId: string
      in
      The id of the callback to test.

    Returns boolean

    true if such a listener is installed for the given callback id.

  • Asks for an attribute values enumeration.

    This call cancels any running request on the given AttributeValuesEnumeratorInterface, and sets up a new enumeration. No value is available right now, but nextValues can be called after a successful setup.

    If a previous call is cancelled, then a AttributeValuesEnumeratorInterfaceSignal.AttributesEnumerationReady signal is fired during the call with the id of the previous call.

    pAttributeName must refer to a valid string attribute. All values that strictly begins with pStartsWith will be exposed with the call to nextValues.

    Warning The meaning of pStartsWith may change in future versions of the api. At the moment, the enumeration is case sensitive, and NO regular expression is allowed.

    Parameters

    • pAttributeName: string
      in
      The attribute name to query values for.
    • pStartsWith: string
      in
      Values starting by this string will be queried for (case sensitive).

    Returns boolean

    true if the call succeeded.

  • Tells if the AttributeValuesEnumeratorInterface has been cancelled.

    This is generally the case after calling cancel when the AttributeValuesEnumeratorInterface is retrieving data.

    Returns boolean

    true if the AttributeValuesEnumeratorInterface is cancelled.

  • Tells if a values attribute retrieval procedure is running.

    This is the case after calling nextValues.

    Returns boolean

    true if a values attribute retrieval procedure request is running.

  • Asks for a attribute values enumeration.

    This call may be used to implement a value completer.

    A signal AttributeValuesEnumeratorInterfaceSignal.AttributesEnumerationReady will be sent shortly after telling the AttributeValuesEnumeratorInterface is ready. Then call getEnumerationResult to get the actual results of the call.

    No more than 5 AttributeValuesEnumeratorInterface requests can run simultaneously, but only one request can be run at a time for a given AttributeValuesEnumeratorInterface. If you want to run multiple attribute values requests simultaneously, then create multiple AttributeValuesEnumeratorInterfaces.

    Returns false if a request is already running on this AttributeValuesEnumeratorInterface, if initEnumeration failed, if no other values are available (hasOtherValues returns false), or if too many enumeration requests are running simultaneously.

    Returns boolean

    true if the call succeeded, and then a AttributeValuesEnumeratorInterfaceSignal.AttributesEnumerationReady will be fired shortly after.

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    • pObject: Object

      The listener object that was used when addEventListener was called.

    Returns boolean

    true if the callback was removed else false.

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    Returns boolean

    true if the callback was removed else false.

  • Removes a listener by its id.

    If no such listener is found, then the function returns false and does nothing. You must use the return value of addEventListener to actually remove the listener.

    Parameters

    • pId: string
      in
      The id returned by the call to addEventListener that you want to remove.

    Returns boolean

    true if the callback was removed else false.