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

## Statements: 100% (15 / 15) Branches: 100% (2 / 2) Functions: 100% (3 / 3) Lines: 100% (14 / 14) 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
    411

    1
    94
    94
    94

    94
    94

    1

    94

    53

    53

    53

    53

    53

     var protoclass        = require("protoclass"),
    utils                 = require("../../../utils"),
    createDocumentSection = require("document-section"),
    BindableObject        = require("bindable-object"),
    AttributesBinding     = require("./attributesBinding");

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

      // TODO - section shouldn't be here. marker should be.
      this.section        = section;
      this.componentClass = componentClass;
    }

    module.exports = protoclass(ComponentHydrator, {
      initialize: function () {
        this.sectionMarker = this.section.createMarker();
      },
      hydrate: function (view) {
        var clonedSection = this.sectionMarker.getSection(view.rootNode);

        // TODO - bind script attrs to these attrs
        var attributes = new BindableObject(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);
      }
    });