Skip to content

Commit

Permalink
Patch map.fire to format arguments passed to it.
Browse files Browse the repository at this point in the history
Ref #766
  • Loading branch information
tristen committed May 1, 2018
1 parent 85f39bf commit b3b3fbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Install dependencies, build the source files and crank up a server via:
```
git clone [email protected]:mapbox/mapbox-gl-draw.git
npm install
npm start & open http://localhost:9966/debug/?access_token=<token>
npm start & open http://localhost:9967/debug/?access_token=<token>
```

### Testing
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b3b3fbb

Please sign in to comment.