Skip to content

Commit

Permalink
Update documentation to reflect the second parameter of passed in cha…
Browse files Browse the repository at this point in the history
…nge events.
  • Loading branch information
adamsanderson committed Jul 18, 2012
1 parent a4f7e76 commit 54c662c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 6 additions & 3 deletions api.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ <h4 class='fn-signature'>
<a name='IvyAttr.prototype.set' href='#IvyAttr.prototype.set'>IvyAttr.prototype.set(value)</a>
</h4>

<p>Sets the internal value of the attribute.</p>
<p>Sets the internal value of the attribute, and emits a <code>change</code>
event with the new value and the old value as the arguments.</p>
</div>
<div class='fn'>
<h4 class='fn-signature'>
Expand All @@ -89,8 +90,10 @@ <h4 class='fn-signature'>
The most common event is <code>change</code>.
</p>
<pre><code>var a = Ivy.attr(4);
a.on(&#39;change&#39;, function(value){ console.log(&#39;New value is&#39;, value); });
a.set(5); //=&gt; &#39;New value is 5&#39;</code></pre>
a.on(&#39;change&#39;, function(value,oldValue){
console.log(&#39;New value is&#39;, value, &#39;old value was&#39;, oldValue);
});
a.set(5); //=&gt; &#39;New value is 5 old value was 4&#39;</code></pre>
</div>
<div class='fn'>
<h4 class='fn-signature'>
Expand Down
12 changes: 8 additions & 4 deletions ivy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ function IvyAttr(value, parseFn){
};

/**
* Sets the internal value of the attribute.
* Sets the internal value of the attribute, and emits a `change`
* event with the new value and the old value as the arguments.
*/
IvyAttr.prototype.set = function(value){
var oldValue = this.value;

value = this.parseFn ? this.parseFn(value) : value;

if (oldValue === value) return this;
Expand All @@ -56,8 +57,11 @@ IvyAttr.prototype.get = function(){
* The most common event is `change`.
*
* var a = Ivy.attr(4);
* a.on('change', function(value){ console.log('New value is', value); });
* a.set(5); //=> 'New value is 5'
* a.on('change', function(value,oldValue){
* console.log('New value is', value, 'old value was', oldValue);
* });
*
* a.set(5); //=> 'New value is 5 old value was 4'
*
*/
IvyAttr.prototype.on = function(event, fn){
Expand Down
Loading

0 comments on commit 54c662c

Please sign in to comment.