Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Re-generated for v0.4.0

  • Loading branch information...
commit ad6b0ad0ed3f3ff15de7bd8e26b7b3a7c591b3b6 1 parent e128b62
dhruvaray authored
Showing with 22 additions and 19 deletions.
  1. +2 −2 backbone-associations-min.js
  2. +20 −17 docs/backbone-associations.html
4 backbone-associations-min.js
View
@@ -6,5 +6,5 @@ this.attributes[e])&&!h._proxyCallback){h._proxyCallback=function(){return this.
return d},hasChanged:function(d){var a,c,b;if(!this.visitedHC){this.visitedHC=true;a=m.hasChanged.apply(this,arguments);if(!a&&this.relations)for(b=0;b<this.relations.length;++b){c=this.relations[b];if(c=this.attributes[c.key]){if(c instanceof l){c=c.filter(function(a){return a.hasChanged()===true});f.size(c)>0&&(a=true)}else a=c.hasChanged&&c.hasChanged();if(a)break}}delete this.visitedHC}return!!a},changedAttributes:function(d){var a,c,b,e;if(!this.visited){this.visited=true;a=m.changedAttributes.apply(this,
arguments);if(this.relations)for(e=0;e<this.relations.length;++e){c=this.relations[e];if(b=this.attributes[c.key])if(b instanceof l){b=f.filter(b.map(function(a){return a.changedAttributes()}),function(a){return!!a});f.size(b)>0&&(a[c.key]=b)}else b instanceof o&&b.hasChanged()&&(a[c.key]=b.toJSON())}delete this.visited}return!a?false:a},previousAttributes:function(){var d,a,c,b;if(!this.visited){this.visited=true;d=m.previousAttributes.apply(this,arguments);this.relations&&f.each(this.relations,
function(e){a=this.attributes[e.key];b=(c=d[e.key])?c.toJSON():void 0;c&&c==a?a instanceof o?d[e.key]=a.previousAttributes():a instanceof l&&(d[e.key]=a.map(function(a){return a.previousAttributes()})):c&&(d[e.key]=b)},this);delete this.visited}return d},previous:function(d){return this.previousAttributes()[d]},toJSON:function(d){var a,c;if(!this.visited){this.visited=true;a=m.toJSON.apply(this,arguments);this.relations&&f.each(this.relations,function(b){var e=this.attributes[b.key];if(e){c=e.toJSON(d);
-a[b.key]=f.isArray(c)?f.compact(c):c}},this);delete this.visited}return a},clone:function(){return new this.constructor(this.toJSON())},getAttr:function(d,a){var c=this,b=r(d),e,j;if(!(f.size(b)<1)){a||(a=function(a,b){return a instanceof l&&f.isNumber(b)?a.at(b):a.attributes[b]});for(j=0;j<b.length;j++){e=b[j];if(!c)break;c=a.call(this,c,e,b)}return c}}});var r=function(d,a,c){if(f.isString(d)){a||(a=function(a){return a.match(/^\d+$/)?parseInt(a,10):a});return f.map(d.match(/[^\.\[\]]+/g)||[""],
-a,c)}return d||[""]}})();
+a[b.key]=f.isArray(c)?f.compact(c):c}},this);delete this.visited}return a},clone:function(){return new this.constructor(this.toJSON())},getAttr:function(d,a){var c=this,b=r(d),e,j;if(!(f.size(b)<1)){a||(a=function(a,b){return a instanceof l&&f.isNumber(b)?a.at(b):a.attributes[b]});for(j=0;j<b.length;j++){e=b[j];if(!c)break;c=a.call(this,c,e,b)}return c}}});var t=/^\d+$/,u=/[^\.\[\]]+/g,r=function(d,a,c){if(f.isString(d)){a||(a=function(a){return a.match(t)?parseInt(a,10):a});return f.map(d.match(u)||
+[""],a,c)}return d||[""]}})();
37 docs/backbone-associations.html
View
@@ -20,10 +20,10 @@
<span class="nx">BackboneCollection</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Collection</span><span class="p">;</span>
<span class="nx">ModelProto</span> <span class="o">=</span> <span class="nx">BackboneModel</span><span class="p">.</span><span class="nx">prototype</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Built-in Backbone <code>events</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">defaultEvents</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;change&quot;</span><span class="p">,</span> <span class="s2">&quot;add&quot;</span><span class="p">,</span> <span class="s2">&quot;remove&quot;</span><span class="p">,</span> <span class="s2">&quot;reset&quot;</span><span class="p">,</span> <span class="s2">&quot;destroy&quot;</span><span class="p">,</span>
<span class="s2">&quot;sync&quot;</span><span class="p">,</span> <span class="s2">&quot;error&quot;</span><span class="p">,</span> <span class="s2">&quot;sort&quot;</span><span class="p">,</span> <span class="s2">&quot;request&quot;</span><span class="p">];</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h2>Backbone.AssociatedModel</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Add <code>Many</code> and <code>One</code> relations to Backbone Object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Many</span> <span class="o">=</span> <span class="s2">&quot;Many&quot;</span><span class="p">;</span>
- <span class="nx">Backbone</span><span class="p">.</span><span class="nx">One</span> <span class="o">=</span> <span class="s2">&quot;One&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Define <code>AssociatedModel</code> (Extends Backbone.Model).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">AssociatedModel</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">AssociatedModel</span> <span class="o">=</span> <span class="nx">BackboneModel</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Define relations with Associated Model.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">relations</span><span class="o">:</span> <span class="kc">undefined</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Define <code>Model</code> property which can keep track of already fired <code>events</code>,
-and prevent redundant event to be triggered in case of circular model graph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_proxyCalls</span><span class="o">:</span> <span class="kc">undefined</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Get the value of an attribute.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">get</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">attr</span><span class="p">){</span>
+ <span class="nx">Backbone</span><span class="p">.</span><span class="nx">One</span> <span class="o">=</span> <span class="s2">&quot;One&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Define <code>AssociatedModel</code> (Extends Backbone.Model).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">AssociatedModel</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">AssociatedModel</span> <span class="o">=</span> <span class="nx">BackboneModel</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Define relations with Associated Model.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">relations</span><span class="o">:</span><span class="kc">undefined</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Define <code>Model</code> property which can keep track of already fired <code>events</code>,
+and prevent redundant event to be triggered in case of circular model graph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_proxyCalls</span><span class="o">:</span><span class="kc">undefined</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Get the value of an attribute.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">get</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">getAttr</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Set a hash of model attributes on the Backbone Model.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">set</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Set a hash of model attributes on the Backbone Model.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">set</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">attributes</span><span class="p">,</span> <span class="nx">attr</span><span class="p">,</span> <span class="nx">modelMap</span><span class="p">,</span> <span class="nx">modelId</span><span class="p">,</span> <span class="nx">obj</span><span class="p">,</span> <span class="nx">result</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Duplicate backbone's behavior to allow separate key/value parameters,
instead of a single 'attributes' object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">isObject</span><span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="o">||</span> <span class="nx">key</span> <span class="o">==</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">attributes</span> <span class="o">=</span> <span class="nx">key</span><span class="p">;</span>
@@ -40,7 +40,7 @@
<span class="nx">modelMap</span> <span class="o">||</span> <span class="p">(</span><span class="nx">modelMap</span> <span class="o">=</span> <span class="p">{});</span>
<span class="k">if</span> <span class="p">((</span><span class="o">!</span><span class="nx">parentModel</span> <span class="o">&amp;&amp;</span> <span class="nx">_</span><span class="p">.</span><span class="nx">size</span><span class="p">(</span><span class="nx">initials</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="o">||</span> <span class="nx">parentModel</span> <span class="k">instanceof</span> <span class="nx">BackboneCollection</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="nx">parentModel</span> <span class="k">instanceof</span> <span class="nx">AssociatedModel</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="nx">root</span> <span class="o">=</span> <span class="nx">parentModel</span><span class="p">);</span>
- <span class="nx">obj</span> <span class="o">=</span> <span class="nx">modelMap</span><span class="p">[</span><span class="nx">root</span><span class="p">.</span><span class="nx">cid</span><span class="p">]</span> <span class="o">||</span> <span class="p">(</span><span class="nx">modelMap</span><span class="p">[</span><span class="nx">root</span><span class="p">.</span><span class="nx">cid</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;model&#39;</span><span class="o">:</span> <span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;data&#39;</span><span class="o">:</span> <span class="p">{}});</span>
+ <span class="nx">obj</span> <span class="o">=</span> <span class="nx">modelMap</span><span class="p">[</span><span class="nx">root</span><span class="p">.</span><span class="nx">cid</span><span class="p">]</span> <span class="o">||</span> <span class="p">(</span><span class="nx">modelMap</span><span class="p">[</span><span class="nx">root</span><span class="p">.</span><span class="nx">cid</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;model&#39;</span><span class="o">:</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;data&#39;</span><span class="o">:</span><span class="p">{}});</span>
<span class="nx">obj</span><span class="p">.</span><span class="nx">data</span><span class="p">[</span><span class="nx">last</span><span class="p">]</span> <span class="o">=</span> <span class="nx">attributes</span><span class="p">[</span><span class="nx">attr</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">modelMap</span><span class="p">)</span> <span class="p">{</span>
@@ -55,7 +55,7 @@
<span class="p">},</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Set a hash of model attributes on the object,
fire Backbone <code>event</code> with options.
It maintains relations between models during the set operation.
-It also bubbles up child events to the parent.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">setAttr</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">attributes</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+It also bubbles up child events to the parent.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">setAttr</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">attributes</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">processedRelations</span><span class="p">,</span> <span class="nx">tbp</span><span class="p">,</span> <span class="nx">attr</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Extract attributes and options.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">||</span> <span class="p">(</span><span class="nx">options</span> <span class="o">=</span> <span class="p">{});</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">unset</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="nx">attr</span> <span class="k">in</span> <span class="nx">attributes</span><span class="p">)</span> <span class="nx">attributes</span><span class="p">[</span><span class="nx">attr</span><span class="p">]</span> <span class="o">=</span> <span class="k">void</span> <span class="mi">0</span><span class="p">;</span>
@@ -107,7 +107,7 @@
<span class="p">}</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Set all <code>attributes</code> to <code>tbp</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">tbp</span> <span class="o">=</span> <span class="nx">attributes</span><span class="p">;</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Return results for <code>BackboneModel.set</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">ModelProto</span><span class="p">.</span><span class="nx">set</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">tbp</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Bubble-up event to <code>parent</code> Model</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_bubbleEvent</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">relationKey</span><span class="p">,</span> <span class="nx">eventArguments</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Bubble-up event to <code>parent</code> Model</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_bubbleEvent</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">relationKey</span><span class="p">,</span> <span class="nx">eventArguments</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">eventArguments</span><span class="p">,</span>
<span class="nx">opt</span> <span class="o">=</span> <span class="nx">args</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">),</span>
<span class="nx">eventType</span> <span class="o">=</span> <span class="nx">opt</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
@@ -144,7 +144,7 @@
<span class="k">delete</span> <span class="nx">_proxyCalls</span><span class="p">[</span><span class="nx">eventPath</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">return</span> <span class="k">this</span><span class="p">;</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">&#182;</a> </div> <p>Returns New <code>collection</code> of type <code>relation.relatedModel</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_createCollection</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">&#182;</a> </div> <p>Returns New <code>collection</code> of type <code>relation.relatedModel</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_createCollection</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">collection</span><span class="p">,</span> <span class="nx">relatedModel</span> <span class="o">=</span> <span class="nx">type</span><span class="p">;</span>
<span class="nx">_</span><span class="p">.</span><span class="nx">isString</span><span class="p">(</span><span class="nx">relatedModel</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="nx">relatedModel</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="nx">relatedModel</span><span class="p">));</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-39">&#182;</a> </div> <p>Creates new <code>Backbone.Collection</code> and defines model class.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">relatedModel</span> <span class="o">&amp;&amp;</span> <span class="nx">relatedModel</span><span class="p">.</span><span class="nx">prototype</span> <span class="k">instanceof</span> <span class="nx">AssociatedModel</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">collection</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">BackboneCollection</span><span class="p">();</span>
@@ -153,7 +153,7 @@
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;type must inherit from Backbone.AssociatedModel&#39;</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">collection</span><span class="p">;</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Has the model changed. Traverse the object hierarchy to compute dirtyness.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">hasChanged</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Has the model changed. Traverse the object hierarchy to compute dirtyness.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">hasChanged</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">isDirty</span><span class="p">,</span> <span class="nx">relation</span><span class="p">,</span> <span class="nx">attrValue</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">dirtyObjects</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>To prevent cycles, check if this node is visited.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">visitedHC</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">visitedHC</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">isDirty</span> <span class="o">=</span> <span class="nx">ModelProto</span><span class="p">.</span><span class="nx">hasChanged</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
@@ -178,7 +178,7 @@
<span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">visitedHC</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="o">!!</span><span class="nx">isDirty</span><span class="p">;</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-43">&#182;</a> </div> <p>Returns a hash of the changed attributes.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">changedAttributes</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">diff</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-43">&#182;</a> </div> <p>Returns a hash of the changed attributes.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">changedAttributes</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">diff</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">delta</span><span class="p">,</span> <span class="nx">relation</span><span class="p">,</span> <span class="nx">attrValue</span><span class="p">,</span> <span class="nx">changedCollection</span><span class="p">,</span> <span class="nx">i</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-44">&#182;</a> </div> <p>To prevent cycles, check if this node is visited.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">visited</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">visited</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">delta</span> <span class="o">=</span> <span class="nx">ModelProto</span><span class="p">.</span><span class="nx">changedAttributes</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
@@ -205,7 +205,7 @@
<span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">visited</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="o">!</span><span class="nx">delta</span> <span class="o">?</span> <span class="kc">false</span> <span class="o">:</span> <span class="nx">delta</span><span class="p">;</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-45">&#182;</a> </div> <p>Returns the hash of the previous attributes of the graph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">previousAttributes</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-45">&#182;</a> </div> <p>Returns the hash of the previous attributes of the graph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">previousAttributes</span><span class="o">:</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">pa</span><span class="p">,</span> <span class="nx">attrValue</span><span class="p">,</span> <span class="nx">pattrValue</span><span class="p">,</span> <span class="nx">pattrJSON</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-46">&#182;</a> </div> <p>To prevent cycles, check if this node is visited.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">visited</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">visited</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">pa</span> <span class="o">=</span> <span class="nx">ModelProto</span><span class="p">.</span><span class="nx">previousAttributes</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
@@ -231,9 +231,9 @@
<span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">visited</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">pa</span><span class="p">;</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-47">&#182;</a> </div> <p>Return the previous value of the passed in attribute.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">previous</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-47">&#182;</a> </div> <p>Return the previous value of the passed in attribute.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">previous</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">previousAttributes</span><span class="p">()[</span><span class="nx">attr</span><span class="p">];</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-48">&#182;</a> </div> <p>The JSON representation of the model.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">toJSON</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-48">&#182;</a> </div> <p>The JSON representation of the model.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">toJSON</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">json</span><span class="p">,</span> <span class="nx">aJson</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">visited</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">visited</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-49"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-49">&#182;</a> </div> <p>Get json representation from <code>BackboneModel.toJSON</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">json</span> <span class="o">=</span> <span class="nx">ModelProto</span><span class="p">.</span><span class="nx">toJSON</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-50">&#182;</a> </div> <p>If <code>this.relations</code> is defined, iterate through each <code>relation</code>
@@ -249,9 +249,9 @@
<span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">visited</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">json</span><span class="p">;</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-51">&#182;</a> </div> <p>Create a new model with identical attributes to this one.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">clone</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-51">&#182;</a> </div> <p>Create a new model with identical attributes to this one.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">clone</span><span class="o">:</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="k">this</span><span class="p">.</span><span class="nx">constructor</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">toJSON</span><span class="p">());</span>
- <span class="p">},</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-52">&#182;</a> </div> <p>Get <code>reduced</code> result using passed <code>path</code> array or string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">getAttr</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">path</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-52">&#182;</a> </div> <p>Get <code>reduced</code> result using passed <code>path</code> array or string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">getAttr</span><span class="o">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">path</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">result</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">attrs</span> <span class="o">=</span> <span class="nx">getPathArray</span><span class="p">(</span><span class="nx">path</span><span class="p">),</span>
<span class="nx">key</span><span class="p">,</span>
@@ -267,12 +267,15 @@
<span class="p">}</span>
<span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
<span class="p">}</span>
- <span class="p">});</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-53">&#182;</a> </div> <p>Get Path <code>attrs</code> as Array</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">getPathArray</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">path</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">});</span>
+
+ <span class="kd">var</span> <span class="nx">_index</span> <span class="o">=</span> <span class="sr">/^\d+$/</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">_pathTokenizer</span> <span class="o">=</span> <span class="sr">/[^\.\[\]]+/g</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-53">&#182;</a> </div> <p>Get Path <code>attrs</code> as Array</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">getPathArray</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">path</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">isString</span><span class="p">(</span><span class="nx">path</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">iterator</span> <span class="o">||</span> <span class="p">(</span><span class="nx">iterator</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">return</span> <span class="nx">value</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/^\d+$/</span><span class="p">)</span> <span class="o">?</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <span class="o">:</span> <span class="nx">value</span><span class="p">;</span>
+ <span class="k">return</span> <span class="nx">value</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">_index</span><span class="p">)</span> <span class="o">?</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <span class="o">:</span> <span class="nx">value</span><span class="p">;</span>
<span class="p">});</span>
- <span class="k">return</span> <span class="nx">_</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/[^\.\[\]]+/g</span><span class="p">)</span> <span class="o">||</span> <span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">],</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">_</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">_pathTokenizer</span><span class="p">)</span> <span class="o">||</span> <span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">],</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">path</span> <span class="o">||</span> <span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">];</span>
<span class="p">}</span>
Please sign in to comment.
Something went wrong with that request. Please try again.