<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Just the Useful Stuff</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/just_the_useful_stuff/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/just_the_useful_stuff/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 04:09:31 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>To observe or not to observe? That is the question…</title>
      <link>https://docs.microsoft.com/archive/blogs/just_the_useful_stuff/to-observe-or-not-to-observe-that-is-the-question</link>
      <pubDate>Fri, 03 May 2013 14:32:03 GMT</pubDate>
      <dc:creator><![CDATA[William Forney]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/just_the_useful_stuff/2013/05/03/to-observe-or-not-to-observe-that-is-the-question/</guid>
      <description><![CDATA[Lately I’ve been doing a lot of work using KnockoutJS and Durandal. I’ve noticed that many...]]></description>
      <content:encoded><![CDATA[<p>Lately I’ve been doing a lot of work using <a title="Knockout" href="https://knockoutjs.com/" rel="nofollow" target="_blank">KnockoutJS</a> and <a title="Durandal" href="https://durandaljs.com/" rel="nofollow" target="_blank">Durandal</a>. I’ve noticed that many developers fall into a pattern of using observables everywhere in these kinds of applications so I thought it might be good to point out when that is appropriate and when it is not.</p>  <p>There are lots of nifty uses for observables in these types of applications, but one needs to remember that there is a cost to using them. So I am going to make a quick cheat sheet below explaining when to use an observable and when not to.</p>  <p><strong>DO</strong> use observables when:</p>  <ul>   <li>you are going to two-way bind the value to the user interface</li>    <li>want to watch when the value changes and act based on it</li>    <li>need to extend it for validation purposes</li> </ul>  <p><strong>DO NOT</strong> use observables when:</p>  <ul>   <li>you are only one-time binding the value</li>    <li>you do not need to subscribe to changes in the value</li> </ul>  <p>I have seen people using observables all the time which slows your pages down and causes more memory consumption. The general rule of thumb is only use observables in the types of scenarios above. Normal variables are fine for other cases.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/11/metablogapi/0358.image_351B8112.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-11-metablogapi/0358.image_5F00_351B8112.png"><img title="magnifier" style="margin: 0px 0px 10px; border: 0px currentcolor; display: inline;" border="0" alt="magnifier" align="left" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/11/metablogapi/8371.image_thumb_1BB37DD8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-11-metablogapi/8371.image_5F00_thumb_5F00_1BB37DD8.png" width="240" height="240" /></a>Also, while reviewing lots of others’ code I have noticed a habit of people calling the observable within their <a title="Knockout" href="https://knockoutjs.com/" rel="nofollow" target="_blank">KnockoutJS</a> templates. This causes the output to lose its observable nature and effectively converts it to a one-time binding. Like so:</p>  <p><strong>WRONG: <strike>&lt;div data-bind=”visible: someVarIsTrue()”&gt;</strike></strong></p>  <p><strong>RIGHT: &lt;div data-bind=”visible: someVarIsTrue”&gt;</strong></p>  <p><strong>WRONG: <strike>&lt;div data-bind=”visible: someProperty.subObject()”&gt;</strike></strong></p>  <p>Generally any time you have a set of parenthesis within your binding you are doing it wrong. If you need to do that you should probably look at using computed properties or adding custom bindings for these scenarios.</p>  <p>Hopefully this helps clear up some of the confusion around using observable variables with <a title="Knockout" href="https://knockoutjs.com/" rel="nofollow" target="_blank">KnockoutJS</a> and other frameworks. Please feel free to point out anything I missed and I will update the post. Enjoy!</p>  <div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c891a95c-49c5-4824-85a4-5ed710ea6a40" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;">Technorati Tags: <a href="https://technorati.com/tags/KnockoutJS" rel="tag">KnockoutJS</a>,<a href="https://technorati.com/tags/Knockout" rel="tag">Knockout</a>,<a href="https://technorati.com/tags/Durandal" rel="tag">Durandal</a></div>]]></content:encoded>
    </item>
    <item>
      <title>A Quick Comparison Between jsViews and Knockout</title>
      <link>https://docs.microsoft.com/archive/blogs/just_the_useful_stuff/a-quick-comparison-between-jsviews-and-knockout</link>
      <pubDate>Tue, 04 Dec 2012 12:56:57 GMT</pubDate>
      <dc:creator><![CDATA[William Forney]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/just_the_useful_stuff/2012/12/04/a-quick-comparison-between-jsviews-and-knockout/</guid>
      <description><![CDATA[Both jsViews and Knockout are JavaScript libraries for implementing an MVVM pattern on the client...]]></description>
      <content:encoded><![CDATA[<p>Both <a title="jsViews" href="https://github.com/BorisMoore/jsviews" rel="nofollow" target="_blank">jsViews</a> and <a title="Knockout" href="https://knockoutjs.com/" rel="nofollow" target="_blank">Knockout</a> are JavaScript libraries for implementing an MVVM pattern on the client side using the <a title="jQuery templates plugin" href="https://github.com/jquery/jquery-tmpl" rel="nofollow" target="_blank">jQuery templates plugin</a> or the later version of same, <a title="jsRender" href="https://github.com/BorisMoore/jsrender" rel="nofollow" target="_blank">jsRender</a>.</p>  <p>When trying to choose which of these libraries to use for some projects I made a quick list of the pros and cons of each and thought it might be useful to others when they are doing the same.</p>  <p>So without further delay, here is my list for <a title="Knockout" href="https://knockoutjs.com/" rel="nofollow" target="_blank">Knockout</a> so far:</p> <strong></strong>  <table cellspacing="0" cellpadding="10" width="500" border="1"><tbody>     <tr>       <td valign="top" width="250"><strong>           <h3><strong>Pros</strong></h3>         </strong></td>        <td valign="top" width="248"><strong>           <h3><strong>Cons</strong></h3>         </strong></td>     </tr>      <tr>       <td valign="top" width="250">Declarative binding for events is easier for some within the templates themselves rather than using selectors and code behind</td>        <td valign="top" width="248">Requires you to use          <br />ko.observable(data) calls to convert your view model data into something usable by the binding engine</td>     </tr>      <tr>       <td valign="top" width="250">Has excellent documentation and examples</td>        <td valign="top" width="248">Requires you to call your view model properties as functions when you access them. If you forget, it breaks the binding and silently fails (at least in the version I was using). This is bad when you assign values and forget to add the parenthesis because you wipe out the observable binding information.</td>     </tr>      <tr>       <td valign="top" width="250">Binding common elements is quite easy and the syntax is simple.</td>        <td valign="top" width="248">Purists will note that declarative event binding within the templates violates separation of concerns</td>     </tr>   </tbody></table>  <p>And for <a title="jsViews" href="https://github.com/BorisMoore/jsviews" rel="nofollow" target="_blank">jsViews</a>:</p>  <table cellspacing="0" cellpadding="10" width="500" border="1"><tbody>     <tr>       <td valign="top" width="249"><strong>           <h3><strong>Pros</strong></h3>         </strong></td>        <td valign="top" width="249"><strong>           <h3><strong>Cons</strong></h3>         </strong></td>     </tr>      <tr>       <td valign="top" width="249">Uses raw data view models without need of conversion or wrapping</td>        <td valign="top" width="249">Requires explicit “observable” update calls for data changes in code (binding still works without issue… I’d equate this to <a title="Knockout" href="https://knockoutjs.com/" rel="nofollow" target="_blank">Knockout</a> requiring parenthesis on all the view model properties because it makes them functions)</td>     </tr>      <tr>       <td valign="top" width="249">Is very lightweight and fast</td>        <td valign="top" width="249">There is little in the way of documentation and there are few samples aside from <a title="jsViews" href="https://github.com/BorisMoore/jsviews" rel="nofollow" target="_blank">Boris’ GitHub repository</a></td>     </tr>      <tr>       <td valign="top" width="249">Uses <a title="jsRender" href="https://github.com/BorisMoore/jsrender" rel="nofollow" target="_blank">jsRender</a> out of the box without modification</td>        <td valign="top" width="249">Has no event binding capability (some, including me like using <a title="jQuery" href="https://jquery.com/" rel="nofollow" target="_blank">jQuery</a>.on() instead of <a title="Knockout" href="https://knockoutjs.com/" rel="nofollow" target="_blank">Knockout</a> syntax for this so this could be a Pro to some)</td>     </tr>   </tbody></table>  <p>No matter which of these you choose to use, they both have the MVVM pattern covered if used properly. At present it seems to be a choice based on personal preference. I welcome any comments or suggestions for additions to my lists.</p>]]></content:encoded>
    </item>
  </channel>
</rss>