Support Menu

Class Model

Class Model

A model is a key-value store that triggers various JavaScript events when any value associated to one of its key changes.
This class is meant to be extended, one of the most important extension being the QueryStateModel class.
Components set values in this key-value store and listen to triggered events in order to update themselves accordingly.

Index

Methods

debugInfo

  • debugInfo(): any

disable

  • disable(): void
  • Disable the component. Normally this means that the component will not execute handlers for the framework events (query events, for example). Component are enabled by default on creation.

    Returns void

enable

  • enable(): void
  • Enable the component. Normally this means that the component will execute handlers for the framework events (query events, for example). Components are enabled by default on creation.

    Returns void

get

  • get(attribute?: string): any
  • Gets the value of a single specific attribute.
    If no attribute is specified, the method instead returns an object containing all registered attribute key-values.

    Parameters

    • Optional attribute: string

      the specific attribute whose value should be returned.

    Returns any

getAttributes

  • getAttributes(): object
  • Gets an object containing all active registered attribute key-values.
    An attribute is considered active when its value is not in its default state.

    Returns object

    • [key: string]: any

getDefault

  • getDefault(attribute?: string): any
  • Gets the default value of a single specific attribute.
    If no attribute is specified, the method instead returns an object containing all registered attribute key-default values.

    Parameters

    • Optional attribute: string

      the specific attribute whose default value should be returned.

    Returns any

getEventName

  • getEventName(event: string): string
  • Gets a string displaying the event namespace followed by the specific event name. The returned string is formatted thus:
    [eventNameSpace]:[eventName]

    example

    getEventName("reset"); could return "state:reset".

    Parameters

    • event: string

      the event name.

    Returns string

registerNewAttribute

  • registerNewAttribute(attribute: string, defaultValue: any): void
  • Registers a new attribute key-value.

    Parameters

    • attribute: string

      the name of the new attribute to register.

    • defaultValue: any

      the newly registered attribute default value.

    Returns void

reset

  • reset(): void
  • Resets each registered attribute to its default value.
    Note: this method calls the setMultiple method without specifying any options.
    After the setMultiple call has returned, this method triggers the reset event.

    Returns void

set

  • set(attribute: string, value: any, options?: IModelSetOptions): void
  • Sets the value of a single specific attribute.
    Note: this method calls the setMultiple method.

    Parameters

    • attribute: string

      the specific attribute whose value is to be set.

    • value: any

      the value to set the attribute to.

    • Optional options: IModelSetOptions

      the options (see setMultiple).

    Returns void

setDefault

  • setDefault(attribute: string): void
  • Sets a single specific attribute to its default value.
    Note: this method calls the setMultiple method without specifying any option.

    Parameters

    • attribute: string

      the specific attribute whose value is to be set to its default value.

    Returns void

setMultiple

  • setMultiple(toSet: object, options?: IModelSetOptions): void
  • Sets the values of one or many attributes.
    This method may trigger the following events (in order):
    preprocess
    changeOne
    change
    all

    Parameters

    • toSet: object

      the key-value list of attributes with their new intended values.

      • [key: string]: any
    • Optional options: IModelSetOptions

      if the customAttribute option is set to true, the method will not validate whether an attribute is registered or not.
      If the validateType option is set to true, the method will ensure that each value type is correct.
      If the silent option is set to true, then the changeOne, change and all events will not be triggered.

    Returns void

setNewDefault

  • setNewDefault(attribute: string, value: any, options?: IModelSetOptions): void
  • Sets a new default value to a single specific attribute.
    Note: specifying a new attribute default value does not set the attribute to that value. This can be done using the setDefault method.

    Parameters

    • attribute: string

      the specific attribute whose default value is to be changed.

    • value: any

      the new intended default value.

    • Optional options: IModelSetOptions

      if the customAttribute option is set to true, the method will not validate whether the attribute is registered or not.

    Returns void

Properties

attributes

attributes: object

The attributes contained in this model.
Normally, you should not set attributes directly on this property, as this would prevent required events from being triggered.

Type declaration

  • [key: string]: any

disabled

disabled: boolean

A disabled component will not participate in the query, or listen to ComponentEvents.

type

{boolean}

logger

logger: Logger

Allows component to log in the dev console.

Static ID

ID: string

The static ID that each component need to be identified.
For example, SearchButton -> static ID : SearchButton -> className : CoveoSearchButton

Object literals

Static eventTypes

eventTypes: object

The event types that can be triggered:
preprocess: triggered before a value is set on an attribute. This allows the value to be modified before it is set.
changeOne: triggered when a single value changes.
change: triggered when one or many values change.
reset: triggered when all attributes are reset to their default values.
all: triggered after the change event.

type

{{preprocess: string, changeOne: string, change: string, reset: string, all: string}}

Hierarchy