Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NumberControl

A Control that obtains a single integer from the user.

Capabilities:

  • Request a value
  • Change a value
  • Validate the value
  • Confirm the value
  • Suggest a value, if the user disconfirms and we know a good alternative to suggest.

Intents that can be handled:

  • GeneralControlIntent: E.g. "yes, update my age"
  • AMAZON_NUMBER_ValueControlIntent: E.g. "no change it to three".
  • AMAZON.YesIntent, AMAZON.NoIntent

APL events that can be handled:

  • touch events indicating number value input.

Hierarchy

Implements

Constructors

constructor

Properties

Readonly id

id: string

state

state: NumberControlState = new NumberControlState()

Methods

canHandle

  • Parameters

    Returns Promise<boolean>

canTakeInitiative

clear

  • clear(): void
  • Clear the state of this control.

    Returns void

commonHandlerWhenValueChanged

  • Parameters

    Returns Promise<void>

evaluateAPLProp

  • Evaluate an APL document/data source prop.

    Parameters

    • act: SystemAct

      act

    • input: ControlInput

      The input object

    • propValue: object | function

      Constant or function producing a map of key:value pairs

    Returns object

    • [key: string]: any

evaluateAPLValidationFailedMessage

  • evaluateAPLValidationFailedMessage(value?: undefined | number): string
  • Parameters

    • Optional value: undefined | number

    Returns string

evaluateBooleanProp

  • evaluateBooleanProp(propValue: boolean | function, input: ControlInput): boolean
  • Evaluate a boolean prop.

    Parameters

    • propValue: boolean | function

      Constant or function producing boolean

    • input: ControlInput

      The input object

    Returns boolean

evaluateFunctionProp

  • evaluateFunctionProp<T>(prop: T | function, input: ControlInput): T

evaluatePromptProp

getSerializableState

  • getSerializableState(): any
  • Gets the Control's state as an object that is serializable.

    Only durable state should be included and the object should be serializable with a straightforward application of JSON.stringify(object).

    Default: {return this.state;}

    Usage:

    • This method must be idempotent (multiple calls must not change the result).
    • The default is sufficient for Controls that use the .state variable and only store simple data.
      • Non-simple data includes functions, and objects with functions, as these will not survive the round trip.
      • Other non-simple data include types with non-enumerable properties.
    • It is safe to pass the actual state object as the framework guarantees to not mutate it.
    • Functions that operate on the Control's state should be defined as member function of the Control type, or as props.

    Framework behavior:

    • During the shutdown phase the state of the control tree is collected by calling this function for each control.
    • The framework serializes the data use a simple application of JSON.stringify.
    • On the subsequent turn the control tree is rebuilt and the state objects are re-attached to each Control via control.setSerializableState(serializedState).

    Returns any

    Serializable object defining the state of the Control

handle

isReady

  • Determines if the Control's value is ready for use by other parts of the skill.

    Note:

    • A basic invariant is isReady === !canTakeInitiative because isReady implies that no further discussion is required and thus there is no need to take the initiative.

    Parameters

    Returns Promise<boolean>

    true if the control has no further questions to ask the user such as elicitation, clarification or confirmation.

reestablishState

  • reestablishState(state: any, controlStateMap: object): void
  • Reestablishes the state of the control.

    Default implementations:

    • Control: reestablishes the state via this.setSerializableState(state).
    • ContainerControl: reestablishes the state and recursively reestablishes state for all children.
    • DynamicContainerControl: reestablishes the state, rebuilds any dynamic child controls, and recursively reestablishes state for all children.

    Parameters

    • state: any
    • controlStateMap: object
      • [index: string]: any

    Returns void

renderAPLComponent

renderAct

setSerializableState

  • setSerializableState(serializedState: any): void
  • Sets the state from a serialized state object.

    Default: {this.state = serializedState;}

    Usage:

    • This method must be idempotent (multiple calls must not change the result).
    • It is safe to use serializedState without copying as the framework guarantees to not mutate it.

    Framework behavior:

    • During the initialization phase the control tree is rebuilt and state objects are re-attached to controls by calling this method for each control.

    Parameters

    • serializedState: any

      Serializable object defining the state of the Control

    Returns void

setValue

  • setValue(value: string | number): void
  • Directly set the value.

    Parameters

    • value: string | number

      Value, either an integer or a string that can be parsed as a integer.

    Returns void

takeInitiative

throwUnhandledActError

  • throwUnhandledActError(act: SystemAct): never

updateInteractionModel

Static mergeWithDefaultProps

  • Merges the user-provided props with the default props.

    Any property defined by the user-provided data overrides the defaults.

    Parameters

    Returns DeepRequired<NumberControlProps>