Skip to content

Commit 9526152

Browse files
committed
Patch map.fire to format arguments passed to it.
1 parent 85f39bf commit 9526152

File tree

5 files changed

+2074
-159
lines changed

5 files changed

+2074
-159
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Install dependencies, build the source files and crank up a server via:
8484
```
8585
git clone [email protected]:mapbox/mapbox-gl-draw.git
8686
npm install
87-
npm start & open http://localhost:9966/debug/?access_token=<token>
87+
npm start & open http://localhost:9967/debug/?access_token=<token>
8888
```
8989

9090
### Testing

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
"style": "dist/mapbox-gl-draw.css",
1010
"browserify": {
1111
"transform": [
12+
"envify",
1213
"babelify"
1314
]
1415
},
1516
"scripts": {
1617
"docs": "npm run docs-modes-life-cycle && npm run docs-modes-get-and-set",
1718
"docs-modes-get-and-set": "documentation readme --readme-file ./docs/MODES.md -s \"Setters and Getters\" src/modes/mode_interface_accessors.js --shallow",
1819
"docs-modes-life-cycle": "documentation readme --readme-file ./docs/MODES.md -s \"Life Cycle Functions\" src/modes/mode_interface.js --shallow",
19-
"test": "npm run lint && npm run tape",
20+
"test": "NODE_ENV=test npm run lint && npm run tape",
2021
"lint": "eslint --no-eslintrc -c .eslintrc index.js src test",
2122
"tape": "tape -r ./test/mock-browser.js -r babel-register test/*.test.js",
2223
"coverage": "NODE_ENV=test nyc --reporter html npm run tape && opener coverage/index.html",
@@ -57,18 +58,18 @@
5758
"eslint-config-mourner": "^2.0.1",
5859
"express": "^4.13.4",
5960
"mapbox-gl": "0.41.0",
60-
"mapbox-gl-js-mock": "^0.28.0",
61+
"mapbox-gl-js-mock": "0.28.0",
6162
"mock-browser": "^0.92.10",
6263
"nyc": "^11.0.2",
6364
"opener": "^1.4.1",
64-
"sinon": "^5.0.0",
65-
"synthetic-dom-events": "^0.3.0",
65+
"sinon": "5.0.0",
66+
"synthetic-dom-events": "0.3.0",
6667
"tape": "^4.0.0",
6768
"uglify-js": "^3.0.22",
6869
"unassertify": "^2.0.3"
6970
},
7071
"peerDependencies": {
71-
"mapbox-gl": ">=0.27.0 <=0.41.0"
72+
"mapbox-gl": ">=0.27.0 <=0.45.0"
7273
},
7374
"dependencies": {
7475
"@mapbox/geojson-area": "^0.2.1",

src/setup.js

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const events = require('./events');
22
const Store = require('./store');
33
const ui = require('./ui');
44
const Constants = require('./constants');
5+
const xtend = require('xtend');
56

67
module.exports = function(ctx) {
78

@@ -35,6 +36,21 @@ module.exports = function(ctx) {
3536
ctx.events.addEventListeners();
3637
},
3738
onAdd: function(map) {
39+
if (process.env.NODE_ENV !== 'test') {
40+
// Monkey patch to resolve breaking change to `fire` introduced by
41+
// mapbox-gl-js. See mapbox/mapbox-gl-draw/issues/766.
42+
const _fire = map.fire;
43+
map.fire = function(type, event) {
44+
let args = arguments;
45+
46+
if (_fire.length === 1 && arguments.length !== 1) {
47+
args = [xtend({}, { type: type }, event)];
48+
}
49+
50+
return _fire.apply(map, args);
51+
};
52+
}
53+
3854
ctx.map = map;
3955
ctx.events = events(ctx);
4056
ctx.ui = ui(ctx);

src/store.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Store.prototype.restoreMapConfig = function() {
325325
/**
326326
* Returns the initial state of an interaction setting.
327327
* @param {string} interaction
328-
* @return {boolean} `true` if the interaction is enabled, `false` if not.
328+
* @return {boolean} `true` if the interaction is enabled, `false` if not.
329329
* Defaults to `true`. (Todo: include defaults.)
330330
*/
331331
Store.prototype.getInitialConfigValue = function(interaction) {

0 commit comments

Comments
 (0)