# all files / lib/components/Layer/ Layer.js

52.27% Statements 23/44
21.05% Branches 4/19
33.33% Functions 3/9
53.66% Lines 22/41

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    1×
    1×
    1×
    1×

    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

     "use strict";
    var __extends = (this && this.__extends) || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
    var React = require('react');
    var ReactDOM = require('react-dom');
    var LayerHost_1 = require('./LayerHost');
    require('./Layer.scss');
    var LAYER_HOST_ELEMENT_ID = 'ms-layer-host';
    var _instance = 0;
    var _layerHost;
    var Layer = (function (_super) {
        __extends(Layer, _super);
        function Layer(props) {
            _super.call(this, props);
            this._layer = {
                id: String(_instance++),
                children: props.children
            };
        }
        Layer.prototype.render = function () {
            var isInLayer = this.context.isInLayer;
            return isInLayer ? this.props.children : null;
        };
        Layer.prototype.componentWillMount = function () {
            if (!_layerHost) {
                var hostElement = document.createElement('div');
                hostElement.setAttribute('id', LAYER_HOST_ELEMENT_ID);
                document.body.appendChild(hostElement);
                var layerHost = ReactDOM.render((React.createElement(LayerHost_1.LayerHost, null)), hostElement);
                _layerHost = layerHost;
            }
        };
        Layer.prototype.componentDidMount = function () {
            if (!this.context.isInLayer) {
                _layerHost.addLayer(this._layer, this.props.onLayerMounted);
            }
            else {
                if (this.props.onLayerMounted) {
                    this.props.onLayerMounted();
                }
            }
        };
        Layer.prototype.componentWillReceiveProps = function (props) {
            if (!this.context.isInLayer) {
                this._layer.children = props.children;
                _layerHost.updateLayer(this._layer);
            }
        };
        Layer.prototype.componentWillUnmount = function () {
            if (!this.context.isInLayer) {
                _layerHost.removeLayer(this._layer);
            }
        };
        Layer.contextTypes = {
            isInLayer: React.PropTypes.bool
        };
        return Layer;
    }(React.Component));
    exports.Layer = Layer;

    //# sourceMappingURL=Layer.js.map