Permalink
Browse files

Merge pull request #54 from g6scheme/1.5.2

1.5.2
  • Loading branch information...
2 parents 70e9b33 + 2338528 commit 1d68645494687d9d6bdfe8f7347cebdeffeb5ab2 @addyosmani committed Aug 22, 2012
Showing with 9 additions and 7 deletions.
  1. +9 −7 book/index.html
View
@@ -4876,7 +4876,7 @@ <h2 id="detailmvp">MVP</h2>
<p>At the end of the day, the underlying concerns we may have with MVC will likely hold true for MVP given that the differences between them are mainly semantic. As long as we are cleanly separating concerns into models, views and controllers (or presenters) we should be achieving most of the same benefits regardless of the variation we opt for.</p>
<h3>MVC, MVP and Backbone.js</h3>
-<p>There are very few, if any architectural JavaScript frameworks that claim to implement the MVC or MVC patterns in their classical form as many JavaScript developers don't view MVC and MVP as being mutually exclusive (we are actually more likely to see MVP strictly implemented when looking at web frameworks such as ASP.net or GWT). This is because it's possible to have additional presenter/view logic in our application and yet still consider it a flavor of MVC.</p>
+<p>There are very few, if any architectural JavaScript frameworks that claim to implement the MVC or MVP patterns in their classical form as many JavaScript developers don't view MVC and MVP as being mutually exclusive (we are actually more likely to see MVP strictly implemented when looking at web frameworks such as ASP.net or GWT). This is because it's possible to have additional presenter/view logic in our application and yet still consider it a flavor of MVC.</p>
<p>Backbone contributor <a href="http://ireneros.com/">Irene Ros</a> (of Boston-based Bocoup) subscribes to this way of thinking as when she separates views out into their own distinct components, she needs something to actually assemble them for her. This could either be a controller route (such as a <code>Backbone.Router</code>, covered later in the book) or a callback in response to data being fetched.</p>
<p>That said, some developers do however feel that Backbone.js better fits the description of MVP than it does MVC. Their view is that:</p>
<ul>
@@ -4971,15 +4971,17 @@ <h2 id="detailmvvm">MVVM</h2>
<p>ViewModel:</p>
<pre class="brush: js">
var aViewModel = {
- contactName: ko.observable( "John" );
+ contactName: ko.observable("John")
};
+ko.applyBindings(aViewModel);
</pre>
<p>View:</p>
-<pre class="brush: js">&lt;input id="source" data-bind="value: contactName, valueUpdate: "keyup" /&gt;&lt;/p&gt;
-
-&lt;div data-bind="visible: contactName().length &gt; 10"&gt;
- You have a really long name!
-&lt;/div&gt;
+<pre class="brush: js">
+ &lt;p&gt;&lt;input id=&quot;source&quot; data-bind=&quot;value: contactName, valueUpdate: &#x27;keyup&#x27;&quot; /&gt;&lt;/p&gt;
+ &lt;div data-bind=&quot;visible: contactName().length &gt; 10&quot;&gt;
+ You have a really long name!
+ &lt;/div&gt;
+ &lt;p&gt;Contact name: &lt;strong data-bind=&quot;text: contactName&quot;&gt;&lt;/strong&gt;&lt;/p&gt;
</pre>
<p>Our input text-box (source) obtains it's initial value from <code>contactName</code>, automatically updating this value whenever contactName changes. As the data binding is two-way, typing into the text-box will update <code>contactName</code> accordingly so the values are always in sync.</p>
<p>Although implementation specific to KnockoutJS, the <code>&lt;div&gt;</code> containing the "You have a really long name!" text also contains simple validation (once again in the form of data bindings). If the input exceeds 10 characters, it will display, otherwise it will remain hidden.</p>

0 comments on commit 1d68645

Please sign in to comment.