Attribute.js.html revision 4fcbec6145d16637205990699912fb90f6a3807c
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>attribute <span class="subtitle">3.00PR1</span></h3>
<p>
> Attribute.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> <label for="showprivate">Show Private</label></span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre> <span class="c">/**</span>
<span class="c"> * Managed Attribute Provider</span>
<span class="c"> * @module attribute</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">O</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Object</span><span class="o">,</span>
<span class="nx">DOT</span> <span class="o">=</span> <span class="s2">"."</span><span class="o">,</span>
<span class="nx">CHANGE</span> <span class="o">=</span> <span class="s2">"Change"</span><span class="o">,</span>
<span class="nx">GET</span> <span class="o">=</span> <span class="s2">"get"</span><span class="o">,</span>
<span class="nx">SET</span> <span class="o">=</span> <span class="s2">"set"</span><span class="o">,</span>
<span class="nx">VALUE</span> <span class="o">=</span> <span class="s2">"value"</span><span class="o">,</span>
<span class="nx">CLONE</span> <span class="o">=</span> <span class="s2">"clone"</span><span class="o">,</span>
<span class="nx">READ_ONLY</span> <span class="o">=</span> <span class="s2">"readOnly"</span><span class="o">,</span>
<span class="nx">WRITE_ONCE</span> <span class="o">=</span> <span class="s2">"writeOnce"</span><span class="o">,</span>
<span class="nx">VALIDATOR</span> <span class="o">=</span> <span class="s2">"validator"</span><span class="o">,</span>
<span class="nx">CLONE_ENUM</span><span class="o">;</span>
<span class="c">/**</span>
<span class="c"> * <p></span>
<span class="c"> * Attribute provides managed attribute support. </span>
<span class="c"> * </p></span>
<span class="c"> * <p></span>
<span class="c"> * The class is designed to be augmented onto a host class, </span>
<span class="c"> * initial configuration support and attribute change events.</span>
<span class="c"> * </p></span>
<span class="c"> * <p>Attributes added to the host can:</p></span>
<span class="c"> * <ul></span>
<span class="c"> * <li>Be defined as read-only.</li></span>
<span class="c"> * <li>Be defined as write-once.</li></span>
<span class="c"> * <li>Be defined with a set function, used to manipulate</span>
<span class="c"> * values passed to Attribute's set method, before they are stored.</li></span>
<span class="c"> * <li>Be defined with a validator function, to validate values before they are stored.</li></span>
<span class="c"> * <li>Be defined with a get function, which can be used to manipulate stored values,</span>
<span class="c"> * before they are returned by Attribute's get method.</li></span>
<span class="c"> * <li>Specify if and how they should be cloned on 'get' (see Attribute.CLONE for supported clone modes).</li></span>
<span class="c"> * </ul></span>
<span class="c"> *</span>
<span class="c"> * <em>See the addAtt method, for details about how to add attributes with</span>
<span class="c"> * a specific configuration</em></span>
<span class="c"> *</span>
<span class="c"> * @class Attribute</span>
<span class="c"> */</span>
<span class="k">function</span> <span class="nx">Attribute</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">Target</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="o">{</span><span class="nx">emitFacade</span><span class="o">:</span><span class="kc">true</span><span class="o">});</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span> <span class="o">||</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">State</span><span class="o">();</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'att constructor called'</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">/**</span>
<span class="c"> * @property CLONE</span>
<span class="c"> * @static</span>
<span class="c"> * @final</span>
<span class="c"> * @type Object</span>
<span class="c"> * <p></span>
<span class="c"> * Constants for clone formats supported by Attribute.</span>
<span class="c"> * </p></span>
<span class="c"> * <p></span>
<span class="c"> * By default attribute values returned by the get method</span>
<span class="c"> * are not cloned. However setting the attribute's "clone"</span>
<span class="c"> * property to:</span>
<span class="c"> * </p></span>
<span class="c"> * <dl></span>
<span class="c"> * <dd>Will result in a deep cloned value being returned</span>
<span class="c"> * objects.</span>
<span class="c"> * </dd></span>
<span class="c"> * <dd>Will result in a shallow cloned value being returned</span>
<span class="c"> * </dd></span>
<span class="c"> * <dd>Will result in a deep cloned value being returned</span>
<span class="c"> * when using the get method. Additionally users will</span>
<span class="c"> * not be able to set sub values of the attribute </span>
<span class="c"> * However the value of the attribute can be changed, making</span>
<span class="c"> * it different from a READONLY attribute.</span>
<span class="c"> * </dd></span>
<span class="c"> * <dd></span>
<span class="c"> * The value will not be cloned, resulting in a reference</span>
<span class="c"> * to the stored value being passed back, if the value is an object.</span>
<span class="c"> * This is the default behavior.</span>
<span class="c"> * </dd></span>
<span class="c"> * </dl></span>
<span class="c"> */</span>
<span class="nx">Attribute</span><span class="o">.</span><span class="nx">CLONE</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">NONE</span> <span class="o">:</span> <span class="m">0</span><span class="o">,</span>
<span class="nx">DEEP</span> <span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="nx">SHALLOW</span> <span class="o">:</span> <span class="m">2</span><span class="o">,</span>
<span class="nx">IMMUTABLE</span><span class="o">:</span> <span class="m">3</span>
<span class="o">};</span>
<span class="nx">CLONE_ENUM</span> <span class="o">=</span> <span class="nx">Attribute</span><span class="o">.</span><span class="nx">CLONE</span><span class="o">;</span>
<span class="nx">Attribute</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * <p></span>
<span class="c"> * Adds an attribute, with the provided configuration to the host object. Intended</span>
<span class="c"> * to be used by the host object to setup it's set of available attributes.</span>
<span class="c"> * </p></span>
<span class="c"> * <p></span>
<span class="c"> * The config argument object literal supports the following optional properties:</span>
<span class="c"> * </p></span>
<span class="c"> * <dl></span>
<span class="c"> * <dt>value {Any}</dt></span>
<span class="c"> * <dd>The initial value to set on the attribute</dd></span>
<span class="c"> * <dt>readOnly {Boolean}</dt></span>
<span class="c"> * <dd>Whether or not the attribute is read only. Attributes having readOnly set to true</span>
<span class="c"> * cannot be set by invoking the set method.</dd></span>
<span class="c"> * <dt>writeOnce {Boolean}</dt></span>
<span class="c"> * <dd>Whether or not the attribute is "write once". Attributes having writeOnce set to true, </span>
<span class="c"> * can only have their values set once, be it through the default configuration, </span>
<span class="c"> * constructor configuration arguments, or by invoking set.</dd></span>
<span class="c"> * <dt>set {Function}</dt></span>
<span class="c"> * <dd>The setter function to be invoked (within the context of the host object) before </span>
<span class="c"> * the attribute is stored by a call to the set method. The value returned by the </span>
<span class="c"> * set function will be the finally stored value.</dd></span>
<span class="c"> * <dt>get {Function}</dt></span>
<span class="c"> * <dd>The getter function to be invoked (within the context of the host object) before</span>
<span class="c"> * the stored values is returned to a user invoking the get method for the attribute.</span>
<span class="c"> * The value returned by the get function is the final value which will be returned to the </span>
<span class="c"> * user when they invoke get.</dd></span>
<span class="c"> * <dt>validator {Function}</dt></span>
<span class="c"> * <dd>The validator function which is invoked prior to setting the stored value. Returning</span>
<span class="c"> * false from the validator function will prevent the value from being stored</dd></span>
<span class="c"> * <dt>clone {int}</dt></span>
<span class="c"> * <dd>If and how the value returned by a call to the get method, should be de-referenced from</span>
<span class="c"> * the stored value. By default values are not cloned, and hence a call to get will return</span>
<span class="c"> * a reference to the stored value. See Attribute.CLONE for more details about the clone </span>
<span class="c"> * options available</dd></span>
<span class="c"> * </dl></span>
<span class="c"> *</span>
<span class="c"> * @method addAtt</span>
<span class="c"> * </span>
<span class="c"> * @param {String} name The attribute key</span>
<span class="c"> * @param {Object} config (optional) An object literal specifying the configuration for the attribute.</span>
<span class="c"> * <strong>NOTE:</strong> The config object is modified when adding an attribute, </span>
<span class="c"> * so if you need to protect the original values, you will need to merge or clone the object.</span>
<span class="c"> * </span>
<span class="c"> */</span>
<span class="nx">addAtt</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">config</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'adding attribute: '</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">value</span><span class="o">,</span> <span class="nx">hasValue</span> <span class="o">=</span> <span class="o">(</span><span class="nx">VALUE</span> <span class="k">in</span> <span class="nx">config</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">config</span><span class="o">[</span><span class="nx">READ_ONLY</span><span class="o">]</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">hasValue</span><span class="o">)</span> <span class="o">{</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'readOnly attribute: '</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">', added without an initial value. Value will be set on intial call to set'</span><span class="o">,</span> <span class="s1">'warn'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);}</span>
<span class="k">if</span><span class="o">(</span><span class="nx">hasValue</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">value</span> <span class="o">=</span> <span class="nx">config</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span>
<span class="nx">delete</span> <span class="nx">config</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">config</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">hasValue</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">value</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Removes an attribute.</span>
<span class="c"> *</span>
<span class="c"> * @method removeAtt</span>
<span class="c"> * @param {String} name The attribute key</span>
<span class="c"> */</span>
<span class="nx">removeAtt</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">remove</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the current value of the attribute. If the attribute</span>
<span class="c"> * has been configured with a 'get' handler, this method will delegate</span>
<span class="c"> * to the 'get' handler to obtain the value of the attribute.</span>
<span class="c"> * The 'get' handler will be passed the current value of the attribute </span>
<span class="c"> * as the only argument.</span>
<span class="c"> *</span>
<span class="c"> * @method get</span>
<span class="c"> *</span>
<span class="c"> * @param {String} key The attribute whose value will be returned. If</span>
<span class="c"> * the value of the attribute is an Object, dot notation can be used to</span>
<span class="c"> * obtain the value of a property of the object (e.g. <code>get("x.y.z")</code>)</span>
<span class="c"> */</span>
<span class="nx">get</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">,</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">getFn</span><span class="o">,</span>
<span class="nx">clone</span><span class="o">,</span>
<span class="nx">val</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">name</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="nx">DOT</span><span class="o">)</span> <span class="o">!==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">name</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="nx">DOT</span><span class="o">);</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="o">}</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">VALUE</span><span class="o">);</span>
<span class="nx">getFn</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">GET</span><span class="o">);</span>
<span class="nx">clone</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">CLONE</span><span class="o">);</span>
<span class="nx">val</span> <span class="o">=</span> <span class="o">(</span><span class="nx">clone</span><span class="o">)</span> <span class="o">?</span> <span class="k">this</span><span class="o">.</span><span class="nx">_cloneAttVal</span><span class="o">(</span><span class="nx">val</span><span class="o">,</span> <span class="nx">clone</span><span class="o">)</span> <span class="o">:</span> <span class="nx">val</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="o">(</span><span class="nx">getFn</span><span class="o">)</span> <span class="o">?</span> <span class="nx">getFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">:</span> <span class="nx">val</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="o">(</span><span class="nx">path</span><span class="o">)</span> <span class="o">?</span> <span class="k">this</span><span class="o">.</span><span class="nx">_getSubAttVal</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">:</span> <span class="nx">val</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Sets the value of an attribute.</span>
<span class="c"> *</span>
<span class="c"> * @method set</span>
<span class="c"> * @chainable</span>
<span class="c"> * </span>
<span class="c"> * @param {String} name The name of the attribute. Note, if the </span>
<span class="c"> * value of the attribute is an Object, dot notation can be used</span>
<span class="c"> * to set the value of a property within the object </span>
<span class="c"> * (e.g. <code>set("x.y.z", 5)</code>), if the attribute has not</span>
<span class="c"> * </span>
<span class="c"> * @param {Any} value The value to apply to the attribute</span>
<span class="c"> * </span>
<span class="c"> * @param {Object} opts Optional event data. This object will be mixed into</span>
<span class="c"> * the event facade passed as the first argument to subscribers </span>
<span class="c"> * of attribute change events</span>
<span class="c"> */</span>
<span class="nx">set</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">,</span>
<span class="nx">data</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">data</span><span class="o">,</span>
<span class="nx">strPath</span><span class="o">,</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">currVal</span><span class="o">,</span>
<span class="nx">initialSet</span> <span class="o">=</span> <span class="o">(!</span><span class="nx">data</span><span class="o">.</span><span class="nx">value</span> <span class="o">||</span> <span class="o">!(</span><span class="nx">name</span> <span class="k">in</span> <span class="nx">data</span><span class="o">.</span><span class="nx">value</span><span class="o">));</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">name</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="nx">DOT</span><span class="o">)</span> <span class="o">!==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">strPath</span> <span class="o">=</span> <span class="nx">name</span><span class="o">;</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">name</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="nx">DOT</span><span class="o">);</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">path</span> <span class="o">&&</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">CLONE</span><span class="o">)</span> <span class="o">===</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">IMMUTABLE</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'set '</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">' failed; Attribute is IMMUTABLE. Setting a sub value is not permitted'</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">initialSet</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">WRITE_ONCE</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'set '</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">' failed; Attribute is writeOnce'</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">READ_ONLY</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'set '</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">' failed; Attribute is readOnly'</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'Set called with unconfigured attribute. Adding a new attribute: '</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="o">}</span>
<span class="nx">currVal</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">path</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_setSubAttVal</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">clone</span><span class="o">(</span><span class="nx">currVal</span><span class="o">),</span> <span class="nx">val</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">val</span> <span class="o">===</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// Path not valid, don't set anything.</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'set '</span> <span class="o">+</span> <span class="nx">strPath</span> <span class="o">+</span> <span class="s1">'failed; attribute sub path is invalid'</span><span class="o">,</span> <span class="s1">'error'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_fireAttChange</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">currVal</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">name</span><span class="o">,</span> <span class="nx">strPath</span><span class="o">,</span> <span class="nx">opts</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Alias for the <a href="Event.Target.html#method_subscribe">Event.Target subscribe method</a>.</span>
<span class="c"> * @method on</span>
<span class="c"> */</span>
<span class="nx">on</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">subscribe</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Default handler implementation for set events</span>
<span class="c"> *</span>
<span class="c"> * @private</span>
<span class="c"> * @method _defAttSet</span>
<span class="c"> */</span>
<span class="nx">_defAttSet</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">,</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">e</span><span class="o">.</span><span class="nx">attrName</span><span class="o">,</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">e</span><span class="o">.</span><span class="nx">newVal</span><span class="o">,</span>
<span class="nx">retVal</span><span class="o">,</span>
<span class="nx">valFn</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">VALIDATOR</span><span class="o">),</span>
<span class="nx">setFn</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">SET</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">setFn</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">retVal</span> <span class="o">=</span> <span class="nx">setFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">val</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">retVal</span> <span class="o">!==</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'attribute: '</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">' modified by setter'</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'attribute'</span><span class="o">);</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">retVal</span><span class="o">;</span> <span class="c">// setter can change value</span>
<span class="c"></span> <span class="o">}</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">valFn</span> <span class="o">||</span> <span class="nx">valFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">val</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">conf</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="o">{</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">val</span> <span class="o">});</span>
<span class="nx">e</span><span class="o">.</span><span class="nx">newVal</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">VALUE</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="c">// Prevent "after" listeners from being </span>
<span class="c"></span> <span class="c">// invoked since nothing changed.</span>
<span class="c"></span> <span class="nx">e</span><span class="o">.</span><span class="nx">stopImmediatePropagation</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Retrieves the sub value at the provided path,</span>
<span class="c"> * from the value object provided.</span>
<span class="c"> *</span>
<span class="c"> * @method _getSubAttVal</span>
<span class="c"> * @private</span>
<span class="c"> *</span>
<span class="c"> * @param {Array} path A path array, specifying the object traversal path</span>
<span class="c"> * from which to obtain the sub value.</span>
<span class="c"> * @param {Object} val The object from which to extract the property value</span>
<span class="c"> * @return {Any} The value stored in the path or undefined if not found.</span>
<span class="c"> */</span>
<span class="nx">_getSubAttVal</span><span class="o">:</span> <span class="k">function</span> <span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">pl</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span>
<span class="nx">i</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">pl</span> <span class="o">></span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">val</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="o">&&</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">pl</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">val</span><span class="o">[</span><span class="nx">path</span><span class="o">[</span><span class="nx">i</span><span class="o">]];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Sets the sub value at the provided path on the value object.</span>
<span class="c"> * Returns the modified value object, or undefined if the path is invalid.</span>
<span class="c"> *</span>
<span class="c"> * @method _setSubAttVal</span>
<span class="c"> * @private</span>
<span class="c"> * </span>
<span class="c"> * @param {Array} path A path array, specifying the object traversal path</span>
<span class="c"> * at which to set the sub value.</span>
<span class="c"> * @param {Object} val The object on which to set the sub value.</span>
<span class="c"> * @param {Any} subval The sub value to set.</span>
<span class="c"> * @return {Object} The modified object, with the new sub value set, or </span>
<span class="c"> * undefined, if the path was invalid.</span>
<span class="c"> */</span>
<span class="nx">_setSubAttVal</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">subval</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">leafIdx</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">,</span>
<span class="nx">i</span><span class="o">,</span>
<span class="nx">o</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">leafIdx</span> <span class="o">>=</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span> <span class="o">=</span> <span class="nx">val</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">o</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="o">&&</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">leafIdx</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span> <span class="o">=</span> <span class="nx">o</span><span class="o">[</span><span class="nx">path</span><span class="o">[</span><span class="nx">i</span><span class="o">]];</span>
<span class="o">}</span>
<span class="c">// Not preventing new properties from being added</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">o</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="c">/* && o[path[i]] !== undefined */</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span><span class="o">[</span><span class="nx">path</span><span class="o">[</span><span class="nx">i</span><span class="o">]]</span> <span class="o">=</span> <span class="nx">subval</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="kc">undefined</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Sets multiple attribute values.</span>
<span class="c"> * </span>
<span class="c"> * @method setAtts</span>
<span class="c"> */</span>
<span class="nx">setAtts</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">att</span> <span class="k">in</span> <span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span> <span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">atts</span><span class="o">,</span> <span class="nx">att</span><span class="o">)</span> <span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">atts</span><span class="o">[</span><span class="nx">att</span><span class="o">]);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Gets multiple attribute values.</span>
<span class="c"> *</span>
<span class="c"> * @method getAtts</span>
<span class="c"> */</span>
<span class="nx">getAtts</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">o</span> <span class="o">=</span> <span class="o">{};</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">clone</span><span class="o">(</span><span class="nx">atts</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">VALUE</span><span class="o">),</span> <span class="k">function</span><span class="o">(</span><span class="nx">val</span><span class="o">,</span> <span class="nx">att</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span><span class="o">[</span><span class="nx">att</span><span class="o">]</span> <span class="o">=</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">});</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">o</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Configures attributes, and sets initial values</span>
<span class="c"> *</span>
<span class="c"> * @method _initAtts</span>
<span class="c"> * @protected</span>
<span class="c"> * </span>
<span class="c"> * @param {Object} cfg Attribute configuration object literal</span>
<span class="c"> */</span>
<span class="nx">_initAtts</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">cfg</span><span class="o">,</span> <span class="nx">initValues</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">cfg</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">att</span><span class="o">,</span>
<span class="nx">attCfg</span><span class="o">,</span>
<span class="nx">values</span><span class="o">,</span>
<span class="nx">value</span><span class="o">,</span>
<span class="nx">atts</span> <span class="o">=</span> <span class="nx">cfg</span><span class="o">;</span>
<span class="nx">values</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_splitAttVals</span><span class="o">(</span><span class="nx">initValues</span><span class="o">);</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">att</span> <span class="k">in</span> <span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">atts</span><span class="o">,</span> <span class="nx">att</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">attCfg</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="nx">atts</span><span class="o">[</span><span class="nx">att</span><span class="o">]);</span>
<span class="nx">value</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_initAttVal</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">attCfg</span><span class="o">,</span> <span class="nx">values</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">value</span> <span class="o">!==</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">attCfg</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">value</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">addAtt</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">attCfg</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Utility to split out regular attribute values</span>
<span class="c"> * from complex attribute values, so that complex</span>
<span class="c"> * attributes can be keyed by top level attribute name.</span>
<span class="c"> *</span>
<span class="c"> * @method _splitAttrValues</span>
<span class="c"> *</span>
<span class="c"> * @return {Object} Object literal with 2 properties - "simple" and "complex",</span>
<span class="c"> * containing simple and complex attribute values respectively keyed </span>
<span class="c"> * by attribute the top level attribute name.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_splitAttVals</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">valueHash</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">vals</span> <span class="o">=</span> <span class="o">{},</span>
<span class="nx">subvals</span> <span class="o">=</span> <span class="o">{},</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">attr</span><span class="o">,</span>
<span class="nx">v</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">k</span> <span class="k">in</span> <span class="nx">valueHash</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">valueHash</span><span class="o">,</span> <span class="nx">k</span><span class="o">))</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">k</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="nx">DOT</span><span class="o">)</span> <span class="o">!==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">k</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="nx">DOT</span><span class="o">);</span>
<span class="nx">attr</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="nx">v</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">attr</span><span class="o">]</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">attr</span><span class="o">]</span> <span class="o">||</span> <span class="o">[];</span>
<span class="nx">v</span><span class="o">[</span><span class="nx">v</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">:</span> <span class="nx">path</span><span class="o">,</span>
<span class="nx">value</span><span class="o">:</span> <span class="nx">valueHash</span><span class="o">[</span><span class="nx">k</span><span class="o">]</span>
<span class="o">};</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">vals</span><span class="o">[</span><span class="nx">k</span><span class="o">]</span> <span class="o">=</span> <span class="nx">valueHash</span><span class="o">[</span><span class="nx">k</span><span class="o">];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="o">{</span> <span class="nx">simple</span><span class="o">:</span><span class="nx">vals</span><span class="o">,</span> <span class="nx">complex</span><span class="o">:</span><span class="nx">subvals</span> <span class="o">};</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the initial value of the given attribute from</span>
<span class="c"> * either the default configuration provided, or the </span>
<span class="c"> * over-ridden value if it exists in the initValues </span>
<span class="c"> * hash provided.</span>
<span class="c"> *</span>
<span class="c"> * @param {String} att Attribute name</span>
<span class="c"> * @param {Object} cfg Default attribute configuration</span>
<span class="c"> * object literal</span>
<span class="c"> * @param {Object} initVales Initial attribute values, provided </span>
<span class="c"> * for the instance</span>
<span class="c"> *</span>
<span class="c"> * @return {Any} Initial value of the attribute.</span>
<span class="c"> *</span>
<span class="c"> * @method _initAttVal</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_initAttVal</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">cfg</span><span class="o">,</span> <span class="nx">initValues</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">hasVal</span> <span class="o">=</span> <span class="o">(</span><span class="nx">VALUE</span> <span class="k">in</span> <span class="nx">cfg</span><span class="o">),</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">cfg</span><span class="o">.</span><span class="nx">value</span><span class="o">,</span>
<span class="nx">simple</span><span class="o">,</span>
<span class="nx">complex</span><span class="o">,</span>
<span class="nx">i</span><span class="o">,</span>
<span class="nx">l</span><span class="o">,</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">subval</span><span class="o">,</span>
<span class="nx">subvals</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">cfg</span><span class="o">[</span><span class="nx">READ_ONLY</span><span class="o">]</span> <span class="o">&&</span> <span class="nx">initValues</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// Simple Attributes</span>
<span class="c"></span> <span class="nx">simple</span> <span class="o">=</span> <span class="nx">initValues</span><span class="o">.</span><span class="nx">simple</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">simple</span> <span class="o">&&</span> <span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">simple</span><span class="o">,</span> <span class="nx">att</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">hasVal</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">simple</span><span class="o">[</span><span class="nx">att</span><span class="o">];</span>
<span class="o">}</span>
<span class="c">// Complex Attributes</span>
<span class="c"></span> <span class="nx">complex</span> <span class="o">=</span> <span class="nx">initValues</span><span class="o">.</span><span class="nx">complex</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">complex</span> <span class="o">&&</span> <span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">complex</span><span class="o">,</span> <span class="nx">att</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">hasVal</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="nx">subvals</span> <span class="o">=</span> <span class="nx">complex</span><span class="o">[</span><span class="nx">att</span><span class="o">];</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">l</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">l</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">path</span><span class="o">;</span>
<span class="nx">subval</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">value</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_setSubAttVal</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">subval</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Clone utility method, which will </span>
<span class="c"> * clone the provided value using YUI's </span>
<span class="c"> * merge, or clone utilities based</span>
<span class="c"> * on the clone type provided.</span>
<span class="c"> * </span>
<span class="c"> * @method _cloneAttVal</span>
<span class="c"> * @private </span>
<span class="c"> * @param {Any} val Value to clone</span>
<span class="c"> * @param {int} type Clone type to use, See the CLONE property</span>
<span class="c"> */</span>
<span class="nx">_cloneAttVal</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">val</span><span class="o">,</span> <span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">switch</span><span class="o">(</span><span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">case</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">SHALLOW</span><span class="o">:</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="nx">val</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="nx">case</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">DEEP</span><span class="o">:</span>
<span class="nx">case</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">IMMUTABLE</span><span class="o">:</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">clone</span><span class="o">(</span><span class="nx">val</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Utility method to help setup the event payload and </span>
<span class="c"> * fire the attribute change event.</span>
<span class="c"> * </span>
<span class="c"> * @method _fireAttChange</span>
<span class="c"> * @private</span>
<span class="c"> * @param {String} type The event name</span>
<span class="c"> * @param {Any} currVal The current value of the attribute</span>
<span class="c"> * @param {Any} newVal The new value of the attribute</span>
<span class="c"> * @param {String} attrName The name of the attribute</span>
<span class="c"> * @param {String} strFullPath The full path of the property being changed, </span>
<span class="c"> * if this is a sub-attribute value being change</span>
<span class="c"> * @param {Function} defaultFn The default handler for the change event</span>
<span class="c"> * @param {Object} opts Any additional event data to mix into the attribute change event's event facade.</span>
<span class="c"> */</span>
<span class="nx">_fireAttChange</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">currVal</span><span class="o">,</span> <span class="nx">newVal</span><span class="o">,</span> <span class="nx">attrName</span><span class="o">,</span> <span class="nx">strFullPath</span><span class="o">,</span> <span class="nx">defaultFn</span><span class="o">,</span> <span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">type</span> <span class="o">=</span> <span class="nx">type</span> <span class="o">+</span> <span class="nx">CHANGE</span><span class="o">;</span>
<span class="c"></span> <span class="k">this</span><span class="o">.</span><span class="nx">publish</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="o">{</span><span class="nx">queuable</span><span class="o">:</span><span class="kc">false</span><span class="o">,</span> <span class="nx">defaultFn</span><span class="o">:</span><span class="k">this</span><span class="o">.</span><span class="nx">_defAttSet</span><span class="o">});</span>
<span class="k">var</span> <span class="nx">eData</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">type</span><span class="o">:</span> <span class="nx">type</span><span class="o">,</span>
<span class="nx">prevVal</span><span class="o">:</span> <span class="nx">currVal</span><span class="o">,</span>
<span class="nx">newVal</span><span class="o">:</span> <span class="nx">newVal</span><span class="o">,</span>
<span class="nx">attrName</span><span class="o">:</span> <span class="nx">attrName</span><span class="o">,</span>
<span class="nx">subAttrName</span><span class="o">:</span> <span class="nx">strFullPath</span>
<span class="o">};</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">eData</span><span class="o">,</span> <span class="nx">opts</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">eData</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">Attribute</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">Target</span><span class="o">,</span> <span class="kc">false</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="m">1</span><span class="o">);</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Attribute</span> <span class="o">=</span> <span class="nx">Attribute</span><span class="o">;</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>