# 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
- disable
- enable
- get
- getAttributes
- getDefault
- getEventName
- registerNewAttribute
- reset
- set
- setDefault
- setMultiple
- setNewDefault

### Properties

- attributes
- disabled
- logger
- ID

### Object literals

- eventTypes

## Methods

### debugInfo

- debugInfo(): any

- Inherited from BaseComponent.debugInfo

  - Defined in ui/Base/BaseComponent.ts :41

  Return the debug info about this component.

  #### Returns any

### disable

- disable(): void

- Inherited from BaseComponent.disable

  - Defined in ui/Base/BaseComponent.ts :52

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

  #### Returns void

### enable

- enable(): void

- Inherited from BaseComponent.enable

  - Defined in ui/Base/BaseComponent.ts :61

  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

- - Defined in models/Model.ts :185

  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

- - Defined in models/Model.ts :96

  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

- - Defined in models/Model.ts :200

  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

- - Defined in models/Model.ts :238

  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

- - Defined in models/Model.ts :225

  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

- - Defined in models/Model.ts :213

  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

- - Defined in models/Model.ts :85

  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

- - Defined in models/Model.ts :174

  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

- - Defined in models/Model.ts :124

  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

- - Defined in models/Model.ts :161

  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: IStringMap<any>

- Defined in models/Model.ts :45

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.

### disabled

disabled: boolean

Inherited from BaseComponent.disabled

- Defined in ui/Base/BaseComponent.ts :23

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

type

  {boolean}

### logger

logger: Logger

Inherited from BaseComponent.logger

- Defined in ui/Base/BaseComponent.ts :18

Allows component to log in the dev console.

### Static ID

ID: string

Inherited from BaseComponent.ID

- Defined in ui/Base/BaseComponent.ts :28

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

## Object literals

### Static eventTypes

eventTypes: object

- Defined in models/Model.ts :58

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

- BaseComponent