Skip to content

Commit bb3fb10

Browse files
committed
add check for button 'name':
- throw error when name is not passed in - throw error when name is not unique - check for button 'name' is Modebar.hasButton method
1 parent da787d7 commit bb3fb10

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/components/modebar/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,20 @@ proto.updateButtons = function(buttons) {
7575

7676
this.buttons = buttons;
7777
this.buttonElements = [];
78+
this.buttonsNames = [];
7879

7980
this.buttons.forEach(function(buttonGroup) {
8081
var group = _this.createGroup();
8182

8283
buttonGroup.forEach(function(buttonConfig) {
84+
var buttonName = buttonConfig.name;
85+
if(!buttonName) {
86+
throw new Error('must provide button \'name\' in button config');
8387
}
88+
if(_this.buttonsNames.indexOf(buttonName) !== -1) {
89+
throw new Error('button name \'', + buttonName + '\' is taken');
90+
}
91+
_this.buttonsNames.push(buttonName);
8492

8593
var button = _this.createButton(buttonConfig);
8694
_this.buttonElements.push(button);
@@ -192,11 +200,10 @@ proto.updateActiveButton = function(buttonClicked) {
192200
});
193201
};
194202

195-
196203
/**
197204
* Check if modebar is configured as button configuration argument
198205
*
199-
* @Param {object} buttons 2d array of grouped button names
206+
* @Param {object} buttons 2d array of grouped button config objects
200207
* @Return {boolean}
201208
*/
202209
proto.hasButtons = function (buttons) {
@@ -209,7 +216,7 @@ proto.hasButtons = function (buttons) {
209216
for (var i = 0; i < buttons.length; ++i) {
210217
if (buttons[i].length !== currentButtons[i].length) return false;
211218
for (var j = 0; j < buttons[i].length; j++) {
212-
if (buttons[i][j] !== currentButtons[i][j]) return false;
219+
if (buttons[i][j].name !== currentButtons[i][j].name) return false;
213220
}
214221
}
215222

0 commit comments

Comments
 (0)