Code coverage report for lib/MapComponent.js

Statements: 85.14% (63 / 74)      Branches: 55.56% (25 / 45)      Functions: 85.71% (18 / 21)      Lines: 84.62% (44 / 52)      Ignored: none     

All files » lib/ » MapComponent.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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115    3   8   1   5   1   1   1   1   1   1 1 5   5 5       1   1                 7 5 5 5   5   5           7 7   7 7   7 7 2 2 2       7 5 5 5       7         6 6         5         5         2 2                             1     1
"use strict";
 
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
 
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; Eif (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
 
var _inherits = function (subClass, superClass) { Iif (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) subClass.__proto__ = superClass; };
 
var _classCallCheck = function (instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
 
var clone = _interopRequire(require("lodash/lang/clone"));
 
var forEach = _interopRequire(require("lodash/collection/forEach"));
 
var reduce = _interopRequire(require("lodash/collection/reduce"));
 
var Component = require("react").Component;
 
var EVENTS_RE = /on(?:Leaflet)?(.+)/i;
 
var MapComponent = (function (_Component) {
  function MapComponent() {
    _classCallCheck(this, MapComponent);
 
    Eif (_Component != null) {
      _Component.apply(this, arguments);
    }
  }
 
  _inherits(MapComponent, _Component);
 
  _createClass(MapComponent, {
    getLeafletElement: {
      value: function getLeafletElement() {
        console && console.warn && console.warn("`getLeafletElement()` is deprecated, use `leafletElement` instead");
        return this.leafletElement;
      }
    },
    extractLeafletEvents: {
      value: function extractLeafletEvents(props) {
        return reduce(props, function (res, cb, ev) {
          Eif (EVENTS_RE.test(ev)) {
            var key = ev.replace(EVENTS_RE, function (match, p) {
              return p.toLowerCase();
            });
            res[key] = cb;
          }
          return res;
        }, {});
      }
    },
    bindLeafletEvents: {
      value: function bindLeafletEvents() {
        var next = arguments[0] === undefined ? {} : arguments[0];
        var prev = arguments[1] === undefined ? {} : arguments[1];
 
        var el = this.leafletElement;
        Iif (!el) {
          return;
        }var diff = clone(prev);
        forEach(prev, function (cb, ev) {
          Eif (!next[ev] || cb !== next[ev]) {
            delete diff[ev];
            el.off(ev, cb);
          }
        });
 
        forEach(next, function (cb, ev) {
          Eif (!prev[ev] || cb !== prev[ev]) {
            diff[ev] = cb;
            el.on(ev, cb);
          }
        });
 
        return diff;
      }
    },
    fireLeafletEvent: {
      value: function fireLeafletEvent(type, data) {
        var el = this.leafletElement;
        Eif (el) el.fire(type, data);
      }
    },
    componentWillMount: {
      value: function componentWillMount() {
        this._leafletEvents = this.extractLeafletEvents(this.props);
      }
    },
    componentDidMount: {
      value: function componentDidMount() {
        this.bindLeafletEvents(this._leafletEvents);
      }
    },
    componentWillReceiveProps: {
      value: function componentWillReceiveProps(nextProps) {
        var next = this.extractLeafletEvents(nextProps);
        this._leafletEvents = this.bindLeafletEvents(next, this._leafletEvents);
      }
    },
    componentWillUnmount: {
      value: function componentWillUnmount() {
        var el = this.leafletElement;
        if (!el) {
          return;
        }forEach(this._leafletEvents, function (cb, ev) {
          el.off(ev, cb);
        });
      }
    }
  });
 
  return MapComponent;
})(Component);
 
module.exports = MapComponent;