org.apache.royale.binding.DataBindingBase.prototype.setupWatchers = function()

in asdoc/org/apache/royale/binding/DataBindingBase.js [223:289]


org.apache.royale.binding.DataBindingBase.prototype.setupWatchers = function(gb, index, watchers, parentWatcher) {
  var /** @type {boolean} */ foundWatcher = false;
  var /** @type {number} */ n = (watchers.length) >> 0;
  for (var /** @type {number} */ i = 0; i < n; i++) {
    var /** @type {Object} */ watcher = watchers[i];
    var /** @type {boolean} */ isValidWatcher = false;
    if (typeof((watcher.bindings)) == "number") {
      isValidWatcher = (watcher.bindings == index);
    } else {
      isValidWatcher = (watcher.bindings.indexOf(index) != -1);
    }
    if (isValidWatcher) {
      var /** @type {boolean} */ hasWatcherChildren = this.org_apache_royale_binding_DataBindingBase_watcherChildrenRelevantToIndex(watcher.children, index);
      var /** @type {string} */ type = watcher.type;
      var /** @type {Object} */ parentObj = this._strand;
      var /** @type {boolean} */ processWatcher = false;
      var /** @type {org.apache.royale.binding.PropertyWatcher} */ pw;
      switch (type) {
        case "static":
          parentObj = watcher.parentObj;
          gb.staticRoot = parentObj;
          gb.isStatic = true;
          break;
        case "property":
          var /** @type {Function} */ getterFunction = watcher.getterFunction;
          if (typeof((gb.source)) === "function" && !hasWatcherChildren) {
            getterFunction =  /** @type {Function} */ (gb.source);
          }
          pw = new org.apache.royale.binding.PropertyWatcher(this._strand, watcher.propertyName, watcher.eventNames, getterFunction);
          processWatcher = true;
          break;
        case 'function':
          pw = new org.apache.royale.binding.PropertyWatcher(this._strand, watcher.propertyName, watcher.eventNames, null);
          pw.funcProps = {};
          pw.funcProps.functionName = watcher.functionName;
          pw.funcProps.paramFunction = watcher.paramFunction;
          processWatcher = true;
          break;
      }
      if (processWatcher) {
        foundWatcher = true;
        watcher.watcher = pw;
        if (parentWatcher) {
          pw.parentChanged(parentWatcher.value);
        } else {
          pw.parentChanged(parentObj);
        }
        if (parentWatcher) {
          parentWatcher.addChild(pw);
        }
        if (!hasWatcherChildren || this.org_apache_royale_binding_DataBindingBase_watcherChildIsXML(watcher)) {
          pw.addBinding(gb);
        }
      }
      if (hasWatcherChildren) {
        this.setupWatchers(gb, index, watcher.children.watchers, watcher.watcher);
      }
    }
  }
  if (!foundWatcher) {
    if (parentWatcher) {
      gb.valueChanged(parentWatcher.value, true);
    } else {
      gb.valueChanged(null, true);
    }
  }
};