Skip to content

Commit

Permalink
Allow multiple addSourceType calls with same name
Browse files Browse the repository at this point in the history
Since `addSourceType` adds the source type to a static map, it was
yielding an error if two map instances tried to add the same source
type.

This changes `addSourceType(name, SourceType)` to simply do nothing if
there is already a source type named `name`.
  • Loading branch information
Anand Thakker committed Aug 11, 2016
1 parent 9318aaf commit f9d3ea6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ Style.prototype = util.inherit(Evented, {

addSourceType: function (name, SourceType, callback) {
if (Source.getType(name)) {
return callback(new Error('A source type called "' + name + '" already exists.'));
return callback(null, null);
}

Source.setType(name, SourceType);
Expand Down
6 changes: 4 additions & 2 deletions test/js/style/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,12 @@ test('Style#addSourceType', function (t) {
style.addSourceType('bar', SourceType, function (err) { t.error(err); });
});

t.test('refuses to add new type over existing name', function (t) {
t.test('does not overwrite existing source type, but returns gracefully', function (t) {
var style = new Style(createStyleJSON());
var existing = _types['existing'];
style.addSourceType('existing', function () {}, function (err) {
t.ok(err);
t.error(err);
t.equal(_types['existing'], existing);
t.end();
});
});
Expand Down

0 comments on commit f9d3ea6

Please sign in to comment.