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
Maintains the local, normalized CustomEvent queue
Maintains the local collection of configuration property objects as
they were initially applied.
This object is used when resetting a property.
Object reference to the owner of this Config Object
Boolean flag that specifies whether a queue is currently
being executed
Constant representing the boolean type string
Constant representing the CustomEvent type for the config changed event.
Methods
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
- Returns:
void
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.
- Returns:
void
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
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
void
destroy
(
)
Sets all properties to null, unsubscribes all listeners from each
property's change event and all listeners from the configChangedEvent.
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
- Returns:
void
void
fireQueue
(
)
Fires the normalized list of queued property change events
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
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
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
- Returns:
void
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
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.
void
refireEvent
(
key
)
Fires the event for a property using the property's current value.
- Parameters:
-
key <String>
The name of the property
- Returns:
void
void
refresh
(
)
Refires the events for all configuration properties using their
current values.
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
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.
Boolean
subscribeToConfigEvent
(
key
,
handler
,
obj
,
override
)
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)
-
override <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.
String
toString
(
)
Returns a string representation of the Config object
- Returns:
String
- The Config object in string format.
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.
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
(
)
Custom Event, notifying subscribers when Config properties are set
(setProperty is called without the silent flag