text: 
  const ModeHandler = function(mode, DrawContext) {
  
    const handlers = {
      drag: [],
      click: [],
      mousemove: [],
      mousedown: [],
      mouseup: [],
      mouseout: [],
      keydown: [],
      keyup: [],
      touchstart: [],
      touchmove: [],
      touchend: [],
      tap: []
    };
  
    const ctx = {
      on: function(event, selector, fn) {
        if (handlers[event] === undefined) {
          throw new Error(`Invalid event type: ${event}`);
        }
        handlers[event].push({
          selector: selector,
          fn: fn
        });
      },
      render: function(id) {
        DrawContext.store.featureChanged(id);
      }
    };
  
    const delegate = function (eventName, event) {
      const handles = handlers[eventName];
      let iHandle = handles.length;
      while (iHandle--) {
        const handle = handles[iHandle];
        if (handle.selector(event)) {
          handle.fn.call(ctx, event);
          DrawContext.store.render();
          DrawContext.ui.updateMapClasses();
  
          // ensure an event is only handled once
          // we do this to let modes have multiple overlapping selectors
          // and relay on order of oppertations to filter
          break;
        }
      }
    };
  
    mode.start.call(ctx);
  
    return {
      render: mode.render,
      stop: function() {
        if (mode.stop) mode.stop();
      },
      trash: function() {
        if (mode.trash) {
          mode.trash();
          DrawContext.store.render();
        }
      },
      removePoint: function(index) {
        if (mode.removePoint) {
          mode.removePoint(index);
          DrawContext.store.render();
        }
      },
      combineFeatures: function() {
        if (mode.combineFeatures) {
          mode.combineFeatures();
        }
      },
      uncombineFeatures: function() {
        if (mode.uncombineFeatures) {
          mode.uncombineFeatures();
        }
      },
      drag: function(event) {
        delegate('drag', event);
      },
      click: function(event) {
        delegate('click', event);
      },
      mousemove: function(event) {
        delegate('mousemove', event);
      },
      mousedown: function(event) {
        delegate('mousedown', event);
      },
      mouseup: function(event) {
        delegate('mouseup', event);
      },
      mouseout: function(event) {
        delegate('mouseout', event);
      },
      keydown: function(event) {
        delegate('keydown', event);
      },
      keyup: function(event) {
        delegate('keyup', event);
      },
      touchstart: function(event) {
        delegate('touchstart', event);
      },
      touchmove: function(event) {
        delegate('touchmove', event);
      },
      touchend: function(event) {
        delegate('touchend', event);
      },
      tap: function(event) {
        delegate('tap', event);
      }
    };
  };
  
  module.exports = ModeHandler;
  