title: Knockout: Rules for custom binding triggers firing update method
body: <p>Can someone tell me why this works? </p>
  
  <pre><code>&lt;div id="test"&gt;
      &lt;label data-bind="dateText: TheDate"&gt;&lt;/label&gt;
  &lt;/div&gt;
  
  ko.bindingHandlers.dateText = {
          update:         
                  function(el, f_valueaccessor, allbindings, viewmodel, bindingcontext) 
          {
              // Get current value of supplied value
              var val = ko.unwrap(f_valueaccessor());
  
                          console.log('dt is ' + (typeof(val.dt) == 'function' ? '' : 'NOT ') + 'observable');
  
                          var dt = ko.unwrap(val.dt);
  
                          $(el).html(dt ? moment(dt).format('DD/MM/YYYY') : '');
                  }
  };
  
  function Model(data, mapping)
  {
          var _this = this;
  
          if(data)
                  ko.mapping.fromJS(data, mapping, _this);
  
          this.TheDate = this.TheDate || { dt: ko.observable() }
  }
  
  var model = new Model({ TheDate: { dt: null } });
  
  ko.applyBindings(model);
  
  model.TheDate.dt('2001-01-01T01:01:01');
  </code></pre>
  
  <p>Fiddle: <a href="http://jsfiddle.net/qkLzc5u5/2" rel="nofollow">http://jsfiddle.net/qkLzc5u5/2</a></p>
  
  <p>The reason I ask is that I am having problems making this custom binding work in a real application - there, it displays any initial date fine but updates are not reflected in the text - however the <code>IsDated</code> computed does update, so the label is displayed; just blank.</p>
  
  <p>I thought that the problem was that the binding is attached to <code>TheDate</code>, which is not an observable itself; only <code>dt</code> is.</p>
  
  <p>However, the code above will in fact fire the update, so the date <code>01/01/2001</code> is shown, whereas I was expecting nothing to be displayed due to the null initial value.</p>
  
  <p>Now this is actually exactly the behaviour I want, so I don't have a problem with this code - I am hoping to get a bit more of an insight into how the custom bindings know when to fire so I can debug my real world code better.</p>
  
  <p>(Note that the object model for passing dates is fixed by a web service that I cannot change)</p>