~benji/juju-gui/bug-1200412

« back to all changes in this revision

Viewing changes to app/views/databinding.js

  • Committer: Benji York
  • Date: 2013-07-12 18:21:37 UTC
  • mfrom: (822.1.2 juju-gui)
  • Revision ID: benji.york@canonical.com-20130712182137-2xyt9je6pbr3gxxr
merge from trunk (fixing conflicts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
     * a model and its viewlet(s).
112
112
     *
113
113
     * @class BindingEngine
 
114
     * @param {Object} options taking:
 
115
     *          interval: ms window to restrict multiple DOM udpates.250ms
 
116
     *          default.
114
117
     */
115
 
    function BindingEngine() {
 
118
    function BindingEngine(options) {
 
119
      this.options = options || {};
 
120
      this.interval = this.options.interval !== undefined ?
 
121
          this.options.interval : 250;
116
122
      this._viewlets = {};  // {viewlet.name: viewlet}
117
123
      this._bindings = {};  // {modelName: binding Object}
118
124
      this._fieldHandlers = DEFAULT_FIELD_HANDLERS;
247
253
        }, this);
248
254
        this._setupHeirarchicalBindings();
249
255
        this._setupDependencies();
250
 
        this._updateDOM();
 
256
        this._modelChangeHandler();
251
257
      } else {
252
258
        // Model list
253
259
        // TODO: If this is a lazy model list then the models contained are
322
328
            if (source.dependents === undefined) {
323
329
              source.dependents = [];
324
330
            }
325
 
            source.dependents.push(binding.name);
 
331
            if (source.dependents.indexOf(binding.name) === -1) {
 
332
              source.dependents.push(binding.name);
 
333
            }
326
334
          });
327
335
        }
328
336
      });
444
452
      which bindings to change based on the change event.
445
453
      This is called automatically by the framework.
446
454
 
 
455
      This introduces threshold of 250ms without trigger before
 
456
      an actual update will occur.
 
457
 
447
458
      @method _modelChangeHandler
448
459
      @param {Event} evt Y.Model change event.
449
460
     */
450
461
    BindingEngine.prototype._modelChangeHandler = function(evt) {
451
 
      var keys = Y.Object.keys(evt.changed);
452
 
      this._updateDOM(deltaFromChange.call(this, keys));
 
462
      var keys = evt && Y.Object.keys(evt.changed);
 
463
      var delta = keys && deltaFromChange.call(this, keys);
 
464
 
 
465
      if (this._updateTimeout) {
 
466
        this._updateTimeout.cancel();
 
467
        this._updateTimeout = null;
 
468
      }
 
469
      if (this.interval) {
 
470
        this._updateTimeout = Y.later(
 
471
            this.interval,
 
472
            this,
 
473
            this._updateDOM,
 
474
            [delta]);
 
475
      } else {
 
476
        this._updateDOM(delta);
 
477
      }
453
478
    };
454
479
 
455
480
    /**
572
597
}, '0.1.0', {
573
598
  requires: ['juju-view-utils',
574
599
             'juju-models',
 
600
             'yui-later',
575
601
             'observe',
576
602
             'node']
577
603
});