dist/tko.binding.if.js
function bindingContext(dataItemOrAccessor, parentContext, dataItemAlias, extendCallback, settings) {

      var self = this,
          isFunc = typeof(dataItemOrAccessor) == "function" && !isObservable(dataItemOrAccessor),
          nodes,
          subscribable;

      // The binding context object includes static properties for the current, parent, and root view models.
      // If a view model is actually stored in an observable, the corresponding binding context object, and
      // any child contexts, must be updated when the view model is changed.
      function updateContext() {
          // Most of the time, the context will directly get a view model object, but if a function is given,
          // we call the function to retrieve the view model. If the function accesses any observables or returns
          // an observable, the dependency is tracked, and those observables can later cause the binding
          // context to be updated.
          var dataItemOrObservable = isFunc ? dataItemOrAccessor() : dataItemOrAccessor,
              dataItem = unwrap(dataItemOrObservable);

          if (parentContext) {
              // When a "parent" context is given, register a dependency on the parent context. Thus whenever the
              // parent context is updated, this context will also be updated.
              if (parentContext._subscribable)
                  parentContext._subscribable();

              // Copy $root and any custom properties from the parent context
              extend(self, parentContext);

              // Because the above copy overwrites our own properties, we need to reset them.
              self._subscribable = subscribable;
          } else {
              self.$parents = [];
              self.$root = dataItem;

              // Export 'ko' in the binding context so it will be available in bindings and templates
              // even if 'ko' isn't exported as a global, such as when using an AMD loader.
              // See https://github.com/SteveSanderson/knockout/issues/490
              self.ko = options.knockoutInstance;
          }
          self.$rawData = dataItemOrObservable;
          self.$data = dataItem;
          if (dataItemAlias)
              self[dataItemAlias] = dataItem;

          // The extendCallback function is provided when creating a child context or extending a context.
          // It handles the specific actions needed to finish setting up the binding context. Actions in this
          // function could also add dependencies to this binding context.
          if (extendCallback)
              extendCallback(self, parentContext, dataItem);

          return self.$data;
      }

      function disposeWhen() {
          return nodes && !anyDomNodeIsAttachedToDocument(nodes);
      }

      if (settings && settings.exportDependencies) {
          // The "exportDependencies" option means that the calling code will track any dependencies and re-create
          // the binding context when they change.
          updateContext();
          return;
      }

      subscribable = computed(updateContext, null, { disposeWhen: disposeWhen, disposeWhenNodeIsRemoved: true });

      // At this point, the binding context has been initialized, and the "subscribable" computed observable is
      // subscribed to any observables that were accessed in the process. If there is nothing to track, the
      // computed will be inactive, and we can safely throw it away. If it's active, the computed is stored in
      // the context object.
      if (subscribable.isActive()) {
          self._subscribable = subscribable;

          // Always notify because even if the model ($data) hasn't changed, other context properties might have changed
          subscribable.equalityComparer = null;

          // We need to be able to dispose of this computed observable when it's no longer needed. This would be
          // easy if we had a single node to watch, but binding contexts can be used by many different nodes, and
          // we cannot assume that those nodes have any relation to each other. So instead we track any node that
          // the context is attached to, and dispose the computed when all of those nodes have been cleaned.

          // Add properties to *subscribable* instead of *self* because any properties added to *self* may be overwritten on updates
          nodes = [];
          subscribable._addNode = function(node) {
              nodes.push(node);
              addDisposeCallback(node, function(node) {
                  arrayRemoveItem(nodes, node);
                  if (!nodes.length) {
                      subscribable.dispose();
                      self._subscribable = subscribable = undefined;
                  }
              });
          };
      }
  }
function bindingContext(dataItemOrAccessor, parentContext, dataItemAlias, extendCallback, settings) {

      var self = this,
          isFunc = typeof(dataItemOrAccessor) == "function" && !isObservable(dataItemOrAccessor),
          nodes,
          subscribable;

      // The binding context object includes static properties for the current, parent, and root view models.
      // If a view model is actually stored in an observable, the corresponding binding context object, and
      // any child contexts, must be updated when the view model is changed.
      function updateContext() {
          // Most of the time, the context will directly get a view model object, but if a function is given,
          // we call the function to retrieve the view model. If the function accesses any observables or returns
          // an observable, the dependency is tracked, and those observables can later cause the binding
          // context to be updated.
          var dataItemOrObservable = isFunc ? dataItemOrAccessor() : dataItemOrAccessor,
              dataItem = unwrap(dataItemOrObservable);

          if (parentContext) {
              // When a "parent" context is given, register a dependency on the parent context. Thus whenever the
              // parent context is updated, this context will also be updated.
              if (parentContext._subscribable)
                  parentContext._subscribable();

              // Copy $root and any custom properties from the parent context
              extend(self, parentContext);

              // Because the above copy overwrites our own properties, we need to reset them.
              self._subscribable = subscribable;
          } else {
              self.$parents = [];
              self.$root = dataItem;

              // Export 'ko' in the binding context so it will be available in bindings and templates
              // even if 'ko' isn't exported as a global, such as when using an AMD loader.
              // See https://github.com/SteveSanderson/knockout/issues/490
              self.ko = options.knockoutInstance;
          }
          self.$rawData = dataItemOrObservable;
          self.$data = dataItem;
          if (dataItemAlias)
              self[dataItemAlias] = dataItem;

          // The extendCallback function is provided when creating a child context or extending a context.
          // It handles the specific actions needed to finish setting up the binding context. Actions in this
          // function could also add dependencies to this binding context.
          if (extendCallback)
              extendCallback(self, parentContext, dataItem);

          return self.$data;
      }

      function disposeWhen() {
          return nodes && !anyDomNodeIsAttachedToDocument(nodes);
      }

      if (settings && settings.exportDependencies) {
          // The "exportDependencies" option means that the calling code will track any dependencies and re-create
          // the binding context when they change.
          updateContext();
          return;
      }

      subscribable = computed(updateContext, null, { disposeWhen: disposeWhen, disposeWhenNodeIsRemoved: true });

      // At this point, the binding context has been initialized, and the "subscribable" computed observable is
      // subscribed to any observables that were accessed in the process. If there is nothing to track, the
      // computed will be inactive, and we can safely throw it away. If it's active, the computed is stored in
      // the context object.
      if (subscribable.isActive()) {
          self._subscribable = subscribable;

          // Always notify because even if the model ($data) hasn't changed, other context properties might have changed
          subscribable.equalityComparer = null;

          // We need to be able to dispose of this computed observable when it's no longer needed. This would be
          // easy if we had a single node to watch, but binding contexts can be used by many different nodes, and
          // we cannot assume that those nodes have any relation to each other. So instead we track any node that
          // the context is attached to, and dispose the computed when all of those nodes have been cleaned.

          // Add properties to *subscribable* instead of *self* because any properties added to *self* may be overwritten on updates
          nodes = [];
          subscribable._addNode = function(node) {
              nodes.push(node);
              addDisposeCallback(node, function(node) {
                  arrayRemoveItem(nodes, node);
                  if (!nodes.length) {
                      subscribable.dispose();
                      self._subscribable = subscribable = undefined;
                  }
              });
          };
      }
  }
function bindingContext ( dataItemOrAccessor , parentContext , dataItemAlias , extendCallback , settings ) { var self = this , isFunc = typeof ( dataItemOrAccessor ) == "function" && ! isObservable ( dataItemOrAccessor ) , nodes , subscribable ; // The binding context object includes static properties for the current, parent, and root view models. // If a view model is actually stored in an observable, the corresponding binding context object, and // any child contexts, must be updated when the view model is changed. function updateContext ( ) { // Most of the time, the context will directly get a view model object, but if a function is given, // we call the function to retrieve the view model. If the function accesses any observables or returns // an observable, the dependency is tracked, and those observables can later cause the binding // context to be updated. var dataItemOrObservable = isFunc ? dataItemOrAccessor ( ) : dataItemOrAccessor , dataItem = unwrap ( dataItemOrObservable ) ; if ( parentContext ) { // When a "parent" context is given, register a dependency on the parent context. Thus whenever the // parent context is updated, this context will also be updated. if ( parentContext . _subscribable ) parentContext . _subscribable ( ) ; // Copy $root and any custom properties from the parent context extend ( self , parentContext ) ; // Because the above copy overwrites our own properties, we need to reset them. self . _subscribable = subscribable ; } else { self . $parents = [ ] ; self . $root = dataItem ; // Export 'ko' in the binding context so it will be available in bindings and templates // even if 'ko' isn't exported as a global, such as when using an AMD loader. // See https://github.com/SteveSanderson/knockout/issues/490 self . ko = options . knockoutInstance ; } self . $rawData = dataItemOrObservable ; self . $data = dataItem ; if ( dataItemAlias ) self [ dataItemAlias ] = dataItem ; // The extendCallback function is provided when creating a child context or extending a context. // It handles the specific actions needed to finish setting up the binding context. Actions in this // function could also add dependencies to this binding context. if ( extendCallback ) extendCallback ( self , parentContext , dataItem ) ; return self . $data ; } function disposeWhen ( ) { return nodes && ! anyDomNodeIsAttachedToDocument ( nodes ) ; } if ( settings && settings . exportDependencies ) { // The "exportDependencies" option means that the calling code will track any dependencies and re-create // the binding context when they change. updateContext ( ) ; return ; } subscribable = computed ( updateContext , null , { disposeWhen : disposeWhen , disposeWhenNodeIsRemoved : true } ) ; // At this point, the binding context has been initialized, and the "subscribable" computed observable is // subscribed to any observables that were accessed in the process. If there is nothing to track, the // computed will be inactive, and we can safely throw it away. If it's active, the computed is stored in // the context object. if ( subscribable . isActive ( ) ) { self . _subscribable = subscribable ; // Always notify because even if the model ($data) hasn't changed, other context properties might have changed subscribable . equalityComparer = null ; // We need to be able to dispose of this computed observable when it's no longer needed. This would be // easy if we had a single node to watch, but binding contexts can be used by many different nodes, and // we cannot assume that those nodes have any relation to each other. So instead we track any node that // the context is attached to, and dispose the computed when all of those nodes have been cleaned. // Add properties to *subscribable* instead of *self* because any properties added to *self* may be overwritten on updates nodes = [ ] ; subscribable . _addNode = function ( node ) { nodes . push ( node ) ; addDisposeCallback ( node , function ( node ) { arrayRemoveItem ( nodes , node ) ; if ( ! nodes . length ) { subscribable . dispose ( ) ; self . _subscribable = subscribable = undefined ; } } ) ; } ; } }
The bindingContext constructor is only called directly to create the root context. For child contexts, use bindingContext.createChildContext or bindingContext.extend.
The bindingContext constructor is only called directly to create the root context . For child contexts use bindingContext . createChildContext or bindingContext . extend .