Code coverage report for lib/class/MapElement.js

Statements: 87.67% (64 / 73)      Branches: 59.52% (25 / 42)      Functions: 90.48% (19 / 21)      Lines: 88.24% (45 / 51)      Ignored: none     

All files » lib/class/ » MapElement.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    3   8   1   5   1   1   1   1   1   1 1 5   5 5       1   1     14         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 MapElement = (function (_Component) {
  function MapElement() {
    _classCallCheck(this, MapElement);
 
    Eif (_Component != null) {
      _Component.apply(this, arguments);
    }
  }
 
  _inherits(MapElement, _Component);
 
  _createClass(MapElement, {
    getLeafletElement: {
      value: function getLeafletElement() {
        return this._leafletElement;
      }
    },
    extractEvents: {
      value: function extractEvents(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;
        }, {});
      }
    },
    bindEvents: {
      value: function bindEvents() {
        var next = arguments[0] === undefined ? {} : arguments[0];
        var prev = arguments[1] === undefined ? {} : arguments[1];
 
        var el = this.getLeafletElement();
        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;
      }
    },
    fireEvent: {
      value: function fireEvent(type, data) {
        var el = this.getLeafletElement();
        Eif (el) el.fire(type, data);
      }
    },
    componentWillMount: {
      value: function componentWillMount() {
        this._leafletEvents = this.extractEvents(this.props);
      }
    },
    componentDidMount: {
      value: function componentDidMount() {
        this.bindEvents(this._leafletEvents);
      }
    },
    componentWillReceiveProps: {
      value: function componentWillReceiveProps(nextProps) {
        var next = this.extractEvents(nextProps);
        this._leafletEvents = this.bindEvents(next, this._leafletEvents);
      }
    },
    componentWillUnmount: {
      value: function componentWillUnmount() {
        var el = this.getLeafletElement();
        if (!el) {
          return;
        }forEach(this._leafletEvents, function (cb, ev) {
          el.off(ev, cb);
        });
      }
    }
  });
 
  return MapElement;
})(Component);
 
module.exports = MapElement;