# Code coverage report for lib/template/vnode/element/componentHydrator.js

## Statements: 100% (16 / 16) Branches: 100% (2 / 2) Functions: 100% (3 / 3) Lines: 100% (15 / 15) Ignored: none

All files » lib/template/vnode/element/ » componentHydrator.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    541

    1
    93
    93
    93
    93
    93

    1

    93

    51

    51

    51

    51

    51

    51

     var protoclass        = require("protoclass"),
    utils                 = require("../../../utils"),
    AttributesBinding     = require("./attributesBinding"),
    _extend               = require("../../../utils/extend");

    /**
     */

    function ComponentHydrator(name, attributes, childTemplate, section, componentClass) {
      this.name           = name;
      this.attributes     = attributes;
      this.childTemplate  = childTemplate;
      this.section        = section;
      this.componentClass = componentClass;
    }

    /**
     */

    module.exports = protoclass(ComponentHydrator, {

      /**
       */

      initialize: function() {
        this.sectionMarker = this.section.createMarker();
      },

      /**
       */

      hydrate: function(view) {
        this.childTemplate.accessor = view.accessor;

        var clonedSection = this.sectionMarker.getSection(view.rootNode);

        // TODO - bind script attrs to these attrs
        var attributes = _extend({}, this.attributes);

        var component = new this.componentClass({
          name          : this.name,
          section       : clonedSection,
          attributes    : attributes,
          view          : view,
          childTemplate : this.childTemplate
        });

        view.bindings.push(new AttributesBinding(attributes, this.attributes, component, view));

        // is it bindable?
        if (component.bind) view.bindings.push(component);
      }
    });