Skip to content

Commit

Permalink
Rename to suppressAPIEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
underoot committed Dec 3, 2024
1 parent d13d485 commit 41d4b1e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ All of the following options are optional.
- `modes`, Object: over ride the default modes with your own. `MapboxDraw.modes` can be used to see the default values. More information on custom modes [can be found here](https://github.com/mapbox/mapbox-gl-draw/blob/main/docs/MODES.md).
- `defaultMode`, String (default: `'simple_select'`): the mode (from `modes`) that user will first land in.
- `userProperties`, boolean (default: `false`): properties of a feature will also be available for styling and prefixed with `user_`, e.g., `['==', 'user_custom_label', 'Example']`
- `silent`, boolean (default: `true`): Whether or not to emit events when calling Draw API methods. If `false`, events will be emitted.
- `suppressAPIEvents`, boolean (default: `true`): Whether or not to emit events when calling Draw API methods. If `false`, events will be emitted.

## Modes

Expand Down
2 changes: 1 addition & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function(ctx, api) {
api.modes = Constants.modes;

// API doesn't emit events by default
const silent = ctx.options.silent !== undefined ? !!ctx.options.silent : true;
const silent = ctx.options.suppressAPIEvents !== undefined ? !!ctx.options.suppressAPIEvents : true;

api.getFeatureIdsAt = function(point) {
const features = featuresAt.click({ point }, null, ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const defaultOptions = {
modes,
controls: {},
userProperties: false,
silent: true
suppressAPIEvents: true
};

const showControls = {
Expand Down
4 changes: 2 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Store.prototype.setDirty = function() {
Store.prototype.featureCreated = function(featureId, options = {}) {
this._changedFeatureIds.add(featureId);

const silent = options.silent != null ? options.silent : this.ctx.options.silent;
const silent = options.silent != null ? options.silent : this.ctx.options.suppressAPIEvents;
if (silent !== true) {
const feature = this.get(featureId);
this.ctx.events.fire(Constants.events.CREATE, {
Expand All @@ -106,7 +106,7 @@ Store.prototype.featureCreated = function(featureId, options = {}) {
Store.prototype.featureChanged = function(featureId, options = {}) {
this._changedFeatureIds.add(featureId);

const silent = options.silent != null ? options.silent : this.ctx.options.silent;
const silent = options.silent != null ? options.silent : this.ctx.options.suppressAPIEvents;
if (silent !== true) {
this.ctx.events.fire(Constants.events.UPDATE, {
action: options.action ? options.action : Constants.updateActions.CHANGE_COORDINATES,
Expand Down
4 changes: 2 additions & 2 deletions test/interaction_events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,8 @@ test('ensure API fire right events', async (t) => {
const map = createMap({container});
const fireSpy = spy(map, 'fire');

// Explicitly set silent to false to ensure events are fired
const Draw = new MapboxDraw({ silent: false });
// Explicitly set `suppressAPIEvents` to false to ensure events are fired
const Draw = new MapboxDraw({ suppressAPIEvents: false });

map.addControl(Draw);
await map.on('load');
Expand Down
12 changes: 6 additions & 6 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('Options test', async (t) => {
combine_features: true,
uncombine_features: true
},
silent: true
suppressAPIEvents: true
};
assert.deepEqual(defaultOptions, Draw.options);
assert.deepEqual(styleWithSourcesFixture, Draw.options.styles);
Expand All @@ -60,7 +60,7 @@ test('Options test', async (t) => {
combine_features: true,
uncombine_features: true
},
silent: true
suppressAPIEvents: true
};

assert.deepEqual(defaultOptions, Draw.options);
Expand All @@ -87,7 +87,7 @@ test('Options test', async (t) => {
combine_features: false,
uncombine_features: false
},
silent: true
suppressAPIEvents: true
};
assert.deepEqual(defaultOptions, Draw.options);
});
Expand All @@ -113,7 +113,7 @@ test('Options test', async (t) => {
combine_features: false,
uncombine_features: false
},
silent: true
suppressAPIEvents: true
};

assert.deepEqual(defaultOptions, Draw.options);
Expand All @@ -140,7 +140,7 @@ test('Options test', async (t) => {
combine_features: true,
uncombine_features: true
},
silent: true
suppressAPIEvents: true
};

assert.deepEqual(defaultOptions, Draw.options);
Expand All @@ -167,7 +167,7 @@ test('Options test', async (t) => {
combine_features: true,
uncombine_features: true
},
silent: true
suppressAPIEvents: true
};
assert.deepEqual(defaultOptions, Draw.options);
assert.deepEqual(styleWithSourcesFixture, Draw.options.styles);
Expand Down
2 changes: 1 addition & 1 deletion test/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import createMap from './utils/create_map.js';
function createStore() {
const ctx = {
options: {
silent: true
suppressAPIEvents: true
},
map: createMap(),
events: {
Expand Down

0 comments on commit 41d4b1e

Please sign in to comment.