# Yahoo! UI Library

### Container 2.8.2r1

Yahoo! UI Library > container > YAHOO.util.Config
Search:
Filters Show Private Show Protected Show Deprecated

## Class YAHOO.util.Config

Config is a utility used within an Object to allow the implementer to maintain a list of local configuration properties and listen for changes to those properties dynamically using CustomEvent. The initial values are also maintained so that the configuration can be reset at any given point to its initial state.

### Constructor

YAHOO.util.Config `( owner )`

Parameters:
  `owner <Object>` The owner Object to which this Config Object belongs

### Properties

#### config - `private Object`

Maintains the local collection of configuration property objects and their specified values

#### eventQueue - `private Object`

Maintains the local, normalized CustomEvent queue

#### initialConfig - `private Object`

Maintains the local collection of configuration property objects as they were initially applied. This object is used when resetting a property.

#### owner - `Object`

Object reference to the owner of this Config Object

#### queueInProgress - `Boolean`

Boolean flag that specifies whether a queue is currently being executed

#### YAHOO.util.Config.BOOLEAN_TYPE - `private static final object`

Constant representing the boolean type string

#### YAHOO.util.Config.CONFIG_CHANGED_EVENT - `private static final object`

Constant representing the CustomEvent type for the config changed event.

### Methods

#### addProperty

`void addProperty ( key , propertyObject )`
Adds a property to the Config Object's private config hash.

Parameters:
  `key <String>` The configuration property's name
  `propertyObject <Object>` The Object containing all of this property's arguments

#### applyConfig

`void applyConfig ( userConfig , init )`
Applies a key-value Object literal to the configuration, replacing any existing values, and queueing the property events. Although the values will be set, fireQueue() must be called for their associated events to execute.

Parameters:
  `userConfig <Object>` The configuration Object literal
  `init <Boolean>` When set to true, the initialConfig will be set to the userConfig passed in, so that calling a reset will reset the properties to the passed values.

#### checkBoolean

`Boolean checkBoolean ( val )`
Validates that the value passed in is a Boolean.

Parameters:
  `val <Object>` The value to validate

Returns: `Boolean`
  true, if the value is valid

#### checkNumber

`Boolean checkNumber ( val )`
Validates that the value passed in is a number.

Parameters:
  `val <Object>` The value to validate

Returns: `Boolean`
  true, if the value is valid

#### destroy

`void destroy ( )`
Sets all properties to null, unsubscribes all listeners from each property's change event and all listeners from the configChangedEvent.

#### fireEvent

`private void fireEvent ( key , Object )`
Fires a configuration property event using the specified value.

Parameters:
  `key <String>` The configuration property's name
  `Object <value>` The value of the correct type for the property

#### fireQueue

`void fireQueue ( )`
Fires the normalized list of queued property change events

#### getConfig

`Object getConfig ( )`
Returns a key-value configuration map of the values currently set in the Config Object.

Returns: `Object`
  The current config, represented in a key-value map

#### getProperty

`Object getProperty ( key )`
Returns the value of specified property.

Parameters:
  `key <String>` The name of the property

Returns: `Object`
  The value of the specified property

#### init

`void init ( owner )`
Initializes the configuration Object and all of its local members.

Parameters:
  `owner <Object>` The owner Object to which this Config Object belongs

#### outputEventQueue

`String outputEventQueue ( )`
Returns a string representation of the Config object's current CustomEvent queue

Returns: `String`
  The string list of CustomEvents currently queued for execution

#### queueProperty

`Boolean queueProperty ( key , value )`
Sets the value of a property and queues its event to execute. If the event is already scheduled to execute, it is moved from its current position to the end of the queue.

Parameters:
  `key <String>` The name of the property
  `value <String>` The value to set the property to

Returns: `Boolean`
  true, if the set was successful, false if it failed.

#### refireEvent

`void refireEvent ( key )`
Fires the event for a property using the property's current value.

Parameters:
  `key <String>` The name of the property

#### refresh

`void refresh ( )`
Refires the events for all configuration properties using their current values.

#### resetProperty

`Boolean resetProperty ( key )`
Resets the specified property's value to its initial value.

Parameters:
  `key <String>` The name of the property

Returns: `Boolean`
  True is the property was reset, false if not

#### setProperty

`Boolean setProperty ( key , value , silent )`
Sets the value of a property. If the silent property is passed as true, the property's event will not be fired.

Parameters:
  `key <String>` The name of the property
  `value <String>` The value to set the property to
  `silent <Boolean>` Whether the value should be set silently, without firing the property event.

Returns: `Boolean`
  True, if the set was successful, false if it failed.

#### subscribeToConfigEvent

`Boolean subscribeToConfigEvent ( key , handler , obj , overrideContext )`
Subscribes an external handler to the change event for any given property.

Parameters:
  `key <String>` The property name
  `handler <Function>` The handler function to use subscribe to the property's event
  `obj <Object>` The Object to use for scoping the event handler (see CustomEvent documentation)
  `overrideContext <Boolean>` Optional. If true, will override "this" within the handler to map to the scope Object passed into the method.

Returns: `Boolean`
  True, if the subscription was successful, otherwise false.

#### toString

`String toString ( )`
Returns a string representation of the Config object

Returns: `String`
  The Config object in string format.

#### unsubscribeFromConfigEvent

`Boolean unsubscribeFromConfigEvent ( key , handler , obj )`
Unsubscribes an external handler from the change event for any given property.

Parameters:
  `key <String>` The property name
  `handler <Function>` The handler function to use subscribe to the property's event
  `obj <Object>` The Object to use for scoping the event handler (see CustomEvent documentation)

Returns: `Boolean`
  True, if the unsubscription was successful, otherwise false.

#### YAHOO.util.Config.alreadySubscribed

`static Boolean YAHOO.util.Config.alreadySubscribed ( evt , fn , obj )`
Checks to determine if a particular function/Object pair are already subscribed to the specified CustomEvent

Parameters:
  `evt <YAHOO.util.CustomEvent>` The CustomEvent for which to check the subscriptions
  `fn <Function>` The function to look for in the subscribers list
  `obj <Object>` The execution scope Object for the subscription

Returns: `Boolean`
  true, if the function/Object pair is already subscribed to the CustomEvent passed in

### Events

#### configChangedEvent

`configChangedEvent ( )`
Custom Event, notifying subscribers when Config properties are set (setProperty is called without the silent flag

Copyright © 2010 Yahoo! Inc. All rights reserved.