editorial

This commit is contained in:
Leo Horie 2014-05-27 08:51:34 -04:00
parent d9243f4998
commit 0550079bfc
19 changed files with 93 additions and 91 deletions

View file

@ -94,7 +94,7 @@ var doSomething = function() { /*...*/ }
m.request({method: &quot;GET&quot;, url: &quot;/user&quot;}).then(users).then(doSomething)</code></pre>
<p>While both basic assignment syntax and thennable syntax can be used to the same effect, typically it&#39;s recommended that you use the assignment syntax whenever possible, as it&#39;s easier to read.</p>
<p>The thennable mechanism is intended to be used in 3 ways:</p>
<p>The thennable mechanism is intended to be used in three ways:</p>
<ul>
<li>in the model layer: to process web service data in transformative ways (e.g. filtering a list based on a parameter that the web service doesn&#39;t support)</li>
<li>in the controller layer: to bind redirection code upon a condition</li>
@ -152,7 +152,7 @@ var controller = function() {
<li>in the controller, to redirect after a model service resolves.</li>
<li>in the controller, to bind error messages</li>
</ul>
<p>In the example below, we take advantage of queuing to debug the ajax response data prior to doing further processing on the user list</p>
<p>In the example below, we take advantage of queuing to debug the AJAX response data prior to doing further processing on the user list</p>
<pre><code class="lang-javascript">var users = m.request({method: &quot;GET&quot;, url: &quot;/user&quot;})
.then(console.log);
.then(function(users) {
@ -165,7 +165,7 @@ var controller = function() {
//i.e. users() //[{name: &quot;John&quot;}, {name: &quot;Mary&quot;}, {name: &quot;Jane&quot;}]</code></pre>
<hr>
<h3 id="casting-the-response-data-to-a-class">Casting the Response Data to a Class</h3>
<p>It&#39;s possible to auto-cast a JSON response to a class. This is useful when we want to control access to certain properties in an object, as opposed to exposing all the fields in POJOs (plain old javascript objects) for arbitrary processing.</p>
<p>It&#39;s possible to auto-cast a JSON response to a class. This is useful when we want to control access to certain properties in an object, as opposed to exposing all the fields in POJOs (plain old Javascript objects) for arbitrary processing.</p>
<p>In the example below, <code>User.list</code> returns a list of <code>User</code> instances.</p>
<pre><code class="lang-javascript">var User = function(data) {
this.name = m.prop(data.name);