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

50% Statements 18/36
36.36% Branches 4/11
27.27% Functions 3/11
51.52% Lines 17/33
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                                                                                 
"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 Fabric_1 = require('../../Fabric');
var LayerHost = (function (_super) {
    __extends(LayerHost, _super);
    function LayerHost(props) {
        _super.call(this, props);
        this._layers = [];
        this.state = {
            layers: this._layers
        };
    }
    LayerHost.prototype.getChildContext = function () {
        return {
            isInLayer: true
        };
    };
    LayerHost.prototype.render = function () {
        var layers = this.state.layers.map(function (layer, index) {
            return (React.createElement("div", {className: 'ms-LayerHost-layer', key: layer.id}, layer.children));
        });
        return (React.createElement(Fabric_1.Fabric, {className: 'ms-LayerHost'}, layers));
    };
    LayerHost.prototype.addLayer = function (layerToAdd, onComplete) {
        this._layers.push(layerToAdd);
        this.setState({
            layers: this._layers
        }, function () {
            if (onComplete) {
                onComplete();
            }
        });
    };
    LayerHost.prototype.updateLayer = function (layerToUpdate) {
        this.forceUpdate();
    };
    LayerHost.prototype.removeLayer = function (layerToRemove) {
        var index = this._layers.indexOf(layerToRemove);
        if (index > -1) {
            this._layers.splice(index, 1);
            this.forceUpdate();
        }
    };
    LayerHost.childContextTypes = {
        isInLayer: React.PropTypes.bool
    };
    return LayerHost;
}(React.Component));
exports.LayerHost = LayerHost;
 
//# sourceMappingURL=LayerHost.js.map