From b3b3fbb97d2df2f06a283453fb5a34e2dcca5e5e Mon Sep 17 00:00:00 2001 From: tristen Date: Tue, 1 May 2018 16:16:05 -0400 Subject: [PATCH] Patch map.fire to format arguments passed to it. Ref #766 --- README.md | 2 +- package.json | 4 ++-- src/setup.js | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 71bca259e..f1c0909e8 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Install dependencies, build the source files and crank up a server via: ``` git clone git@github.com:mapbox/mapbox-gl-draw.git npm install -npm start & open http://localhost:9966/debug/?access_token= +npm start & open http://localhost:9967/debug/?access_token= ``` ### Testing diff --git a/package.json b/package.json index 696837521..c046f922c 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,8 @@ "eslint": "^4.2.0", "eslint-config-mourner": "^2.0.1", "express": "^4.13.4", - "mapbox-gl": "0.41.0", - "mapbox-gl-js-mock": "^0.28.0", + "mapbox-gl": "0.45.0-beta.1", + "mapbox-gl-js-mock": "^1.0.2", "mock-browser": "^0.92.10", "nyc": "^11.0.2", "opener": "^1.4.1", diff --git a/src/setup.js b/src/setup.js index 6cc306685..977795885 100644 --- a/src/setup.js +++ b/src/setup.js @@ -2,6 +2,7 @@ const events = require('./events'); const Store = require('./store'); const ui = require('./ui'); const Constants = require('./constants'); +const xtend = require('xtend'); module.exports = function(ctx) { @@ -35,6 +36,27 @@ module.exports = function(ctx) { ctx.events.addEventListeners(); }, onAdd: function(map) { + + // Monkey patch to resolve breaking change to `fire` introduced by + // mapbox-gl-js. See mapbox/mapbox-gl-draw/issues/766. + const _fire = map.fire; + map.fire = function(type, event) { + + // Circumvent if type is not a string. + if (type !== 'string') return _fire; + + function patched() { + if (_fire.length === 1) { + _fire.apply(this, xtend({}, {type: type }, event)); + } else { + // It's an older version of Mapbox GL JS + _fire.apply(this, type, event); + } + } + + return patched; + }; + ctx.map = map; ctx.events = events(ctx); ctx.ui = ui(ctx);