Fix id types (#743)

* Set ids to be numbers

* Split out _setLoading into start/stop methods

* Build
This commit is contained in:
Josh Johnson 2019-11-08 09:19:18 +00:00 committed by GitHub
parent 7dcc155b8f
commit d04031e02f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 117 additions and 151 deletions

60
package-lock.json generated
View file

@ -1944,7 +1944,7 @@
},
"browserify-aes": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz",
"resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz",
"integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==",
"dev": true,
"requires": {
@ -1981,7 +1981,7 @@
},
"browserify-rsa": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
"resolved": "http://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
"integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=",
"dev": true,
"requires": {
@ -2026,7 +2026,7 @@
},
"buffer": {
"version": "4.9.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
"resolved": "http://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
"integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
"dev": true,
"requires": {
@ -2213,7 +2213,7 @@
},
"camelcase-keys": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
"resolved": "http://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
"integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=",
"dev": true,
"requires": {
@ -2807,7 +2807,7 @@
},
"create-hash": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
"dev": true,
"requires": {
@ -2820,7 +2820,7 @@
},
"create-hmac": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
"resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
"integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
"dev": true,
"requires": {
@ -3350,7 +3350,7 @@
},
"diffie-hellman": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
"resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
"integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==",
"dev": true,
"requires": {
@ -3420,7 +3420,7 @@
},
"duplexer": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
"resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
"integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
"dev": true
},
@ -4092,7 +4092,7 @@
"dependencies": {
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true
}
@ -5873,7 +5873,7 @@
},
"get-stream": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
"resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
"integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=",
"dev": true
},
@ -6038,7 +6038,7 @@
},
"got": {
"version": "6.7.1",
"resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz",
"resolved": "http://registry.npmjs.org/got/-/got-6.7.1.tgz",
"integrity": "sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=",
"dev": true,
"requires": {
@ -6903,7 +6903,7 @@
},
"is-obj": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
"resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
"dev": true
},
@ -7866,7 +7866,7 @@
},
"load-json-file": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
"dev": true,
"requires": {
@ -7887,7 +7887,7 @@
},
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true
}
@ -8145,7 +8145,7 @@
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
"dev": true
},
@ -8186,7 +8186,7 @@
},
"meow": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
"resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
"integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=",
"dev": true,
"requires": {
@ -8214,7 +8214,7 @@
},
"load-json-file": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
"dev": true,
"requires": {
@ -8256,7 +8256,7 @@
},
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true
},
@ -8454,7 +8454,7 @@
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": {
@ -8724,7 +8724,7 @@
"dependencies": {
"semver": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"resolved": "http://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=",
"dev": true
}
@ -9603,7 +9603,7 @@
},
"onetime": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
"resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
"dev": true
},
@ -9653,7 +9653,7 @@
},
"ora": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/ora/-/ora-0.2.3.tgz",
"resolved": "http://registry.npmjs.org/ora/-/ora-0.2.3.tgz",
"integrity": "sha1-N1J9Igrc1Tw5tzVx11QVbV22V6Q=",
"dev": true,
"requires": {
@ -9704,7 +9704,7 @@
},
"os-locale": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
"resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
"integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
"dev": true,
"requires": {
@ -9940,7 +9940,7 @@
"dependencies": {
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true
}
@ -11770,7 +11770,7 @@
},
"safe-regex": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"dev": true,
"requires": {
@ -12134,7 +12134,7 @@
},
"sha.js": {
"version": "2.4.11",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
"dev": true,
"requires": {
@ -12215,7 +12215,7 @@
},
"slice-ansi": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz",
"resolved": "http://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz",
"integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU=",
"dev": true
},
@ -12635,7 +12635,7 @@
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
@ -12650,7 +12650,7 @@
},
"strip-eof": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
"resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
"dev": true
},
@ -12983,7 +12983,7 @@
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
"dev": true
},

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/assets/images/mstile-150x150.png"/>
<TileColor>#ffffff</TileColor>
</tile>
</msapplication>
</browserconfig>
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/assets/images/mstile-150x150.png"/>
<TileColor>#ffffff</TileColor>
</tile>
</msapplication>
</browserconfig>

View file

@ -1372,8 +1372,8 @@ var getAdjacentEl = function getAdjacentEl(startEl, selector, direction) {
return sibling;
};
/**
* @param {HTMLElement} element
* @param {HTMLElement} parent
* @param {Element} element
* @param {Element} parent
* @param {-1 | 1} direction
* @returns {boolean}
*/
@ -1412,7 +1412,7 @@ var sanitise = function sanitise(value) {
return value.replace(/&/g, '&amp;').replace(/>/g, '&rt;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
};
/**
* @returns {function}
* @returns {() => (str: string) => Element}
*/
var strToEl = function () {
@ -1622,14 +1622,14 @@ function () {
}
/**
* Get group by group id
* @param {string} id Group ID
* @param {number} id Group ID
* @returns {Group | undefined} Group data
*/
;
_proto.getGroupById = function getGroupById(id) {
return this.groups.find(function (group) {
return group.id === parseInt(id, 10);
return group.id === id;
});
};
@ -2411,7 +2411,7 @@ function () {
this.element.scrollTop = 0;
}
/**
* @param {HTMLElement} element
* @param {Element} element
* @param {1 | -1} direction
*/
;
@ -3886,13 +3886,13 @@ function () {
this.containerOuter.removeLoadingState();
this._setLoading(true);
this._startLoading();
choicesArrayOrFetcher.forEach(function (groupOrChoice) {
if (groupOrChoice.choices) {
_this11._addGroup({
id: parseInt(groupOrChoice.id, 10) || null,
group: groupOrChoice,
id: groupOrChoice.id || null,
valueKey: value,
labelKey: label
});
@ -3908,7 +3908,7 @@ function () {
}
});
this._setLoading(false);
this._stopLoading();
return this;
};
@ -4339,8 +4339,12 @@ function () {
}
};
_proto._setLoading = function _setLoading(isLoading) {
this._store.dispatch(setIsLoading(isLoading));
_proto._startLoading = function _startLoading() {
this._store.dispatch(setIsLoading(true));
};
_proto._stopLoading = function _stopLoading() {
this._store.dispatch(setIsLoading(false));
};
_proto._handleLoadingState = function _handleLoadingState(setLoading) {
@ -4513,39 +4517,21 @@ function () {
documentElement.removeEventListener('keydown', this._onKeyDown, true);
documentElement.removeEventListener('touchend', this._onTouchEnd, true);
documentElement.removeEventListener('mousedown', this._onMouseDown, true);
documentElement.removeEventListener('keyup', this._onKeyUp, {
passive: true
});
documentElement.removeEventListener('click', this._onClick, {
passive: true
});
documentElement.removeEventListener('touchmove', this._onTouchMove, {
passive: true
});
documentElement.removeEventListener('mouseover', this._onMouseOver, {
passive: true
});
documentElement.removeEventListener('keyup', this._onKeyUp);
documentElement.removeEventListener('click', this._onClick);
documentElement.removeEventListener('touchmove', this._onTouchMove);
documentElement.removeEventListener('mouseover', this._onMouseOver);
if (this._isSelectOneElement) {
this.containerOuter.element.removeEventListener('focus', this._onFocus, {
passive: true
});
this.containerOuter.element.removeEventListener('blur', this._onBlur, {
passive: true
});
this.containerOuter.element.removeEventListener('focus', this._onFocus);
this.containerOuter.element.removeEventListener('blur', this._onBlur);
}
this.input.element.removeEventListener('focus', this._onFocus, {
passive: true
});
this.input.element.removeEventListener('blur', this._onBlur, {
passive: true
});
this.input.element.removeEventListener('focus', this._onFocus);
this.input.element.removeEventListener('blur', this._onBlur);
if (this.input.element.form) {
this.input.element.form.removeEventListener('reset', this._onFormReset, {
passive: true
});
this.input.element.form.removeEventListener('reset', this._onFormReset);
}
this.input.removeEventListeners();
@ -5035,7 +5021,7 @@ function () {
var passedCustomProperties = customProperties;
var items = this._store.items;
var passedLabel = label || passedValue;
var passedOptionId = parseInt(choiceId, 10) || -1;
var passedOptionId = choiceId || -1;
var group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
var id = items ? items.length + 1 : 1; // If a prepended value has been passed, prepend it
@ -5135,12 +5121,12 @@ function () {
var choiceElementId = this._baseId + "-" + this._idNames.itemChoice + "-" + choiceId;
this._store.dispatch(choices_addChoice({
value: value,
label: choiceLabel,
id: choiceId,
groupId: groupId,
disabled: isDisabled,
elementId: choiceElementId,
value: value,
label: choiceLabel,
disabled: isDisabled,
customProperties: customProperties,
placeholder: placeholder,
keyCode: keyCode
@ -5296,7 +5282,7 @@ function () {
this._highlightPosition = 0;
this._isSearching = false;
this._setLoading(true);
this._startLoading();
if (this._presetGroups.length) {
this._addPredefinedGroups(this._presetGroups);
@ -5304,7 +5290,7 @@ function () {
this._addPredefinedChoices(this._presetChoices);
}
this._setLoading(false);
this._stopLoading();
}
if (this._isTextElement) {
@ -5342,16 +5328,14 @@ function () {
// If sorting is enabled or the user is searching, filter choices
if (this.config.shouldSort) {
choices.sort(this.config.sorter);
} // Determine whether there is a selected choice
}
var hasSelectedChoice = choices.some(function (choice) {
return choice.selected;
});
var firstEnabledChoiceIndex = choices.findIndex(function (_choice) {
return _choice.disabled === undefined || !_choice.disabled;
}); // Add each choice
var firstEnabledChoiceIndex = choices.findIndex(function (choice) {
return choice.disabled === undefined || !choice.disabled;
});
choices.forEach(function (choice, index) {
var value = choice.value,
label = choice.label,

File diff suppressed because one or more lines are too long

View file

@ -611,13 +611,13 @@ class Choices {
this.containerOuter.removeLoadingState();
this._setLoading(true);
this._startLoading();
choicesArrayOrFetcher.forEach(groupOrChoice => {
if (groupOrChoice.choices) {
this._addGroup({
id: parseInt(groupOrChoice.id, 10) || null,
group: groupOrChoice,
id: groupOrChoice.id || null,
valueKey: value,
labelKey: label,
});
@ -633,7 +633,7 @@ class Choices {
}
});
this._setLoading(false);
this._stopLoading();
return this;
}
@ -1073,8 +1073,12 @@ class Choices {
}
}
_setLoading(isLoading) {
this._store.dispatch(setIsLoading(isLoading));
_startLoading() {
this._store.dispatch(setIsLoading(true));
}
_stopLoading() {
this._store.dispatch(setIsLoading(false));
}
_handleLoadingState(setLoading = true) {
@ -1271,39 +1275,21 @@ class Choices {
documentElement.removeEventListener('touchend', this._onTouchEnd, true);
documentElement.removeEventListener('mousedown', this._onMouseDown, true);
documentElement.removeEventListener('keyup', this._onKeyUp, {
passive: true,
});
documentElement.removeEventListener('click', this._onClick, {
passive: true,
});
documentElement.removeEventListener('touchmove', this._onTouchMove, {
passive: true,
});
documentElement.removeEventListener('mouseover', this._onMouseOver, {
passive: true,
});
documentElement.removeEventListener('keyup', this._onKeyUp);
documentElement.removeEventListener('click', this._onClick);
documentElement.removeEventListener('touchmove', this._onTouchMove);
documentElement.removeEventListener('mouseover', this._onMouseOver);
if (this._isSelectOneElement) {
this.containerOuter.element.removeEventListener('focus', this._onFocus, {
passive: true,
});
this.containerOuter.element.removeEventListener('blur', this._onBlur, {
passive: true,
});
this.containerOuter.element.removeEventListener('focus', this._onFocus);
this.containerOuter.element.removeEventListener('blur', this._onBlur);
}
this.input.element.removeEventListener('focus', this._onFocus, {
passive: true,
});
this.input.element.removeEventListener('blur', this._onBlur, {
passive: true,
});
this.input.element.removeEventListener('focus', this._onFocus);
this.input.element.removeEventListener('blur', this._onBlur);
if (this.input.element.form) {
this.input.element.form.removeEventListener('reset', this._onFormReset, {
passive: true,
});
this.input.element.form.removeEventListener('reset', this._onFormReset);
}
this.input.removeEventListeners();
@ -1801,7 +1787,7 @@ class Choices {
const passedCustomProperties = customProperties;
const { items } = this._store;
const passedLabel = label || passedValue;
const passedOptionId = parseInt(choiceId, 10) || -1;
const passedOptionId = choiceId || -1;
const group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
const id = items ? items.length + 1 : 1;
@ -1895,12 +1881,12 @@ class Choices {
this._store.dispatch(
addChoice({
value,
label: choiceLabel,
id: choiceId,
groupId,
disabled: isDisabled,
elementId: choiceElementId,
value,
label: choiceLabel,
disabled: isDisabled,
customProperties,
placeholder,
keyCode,
@ -2067,7 +2053,7 @@ class Choices {
if (this._isSelectElement) {
this._highlightPosition = 0;
this._isSearching = false;
this._setLoading(true);
this._startLoading();
if (this._presetGroups.length) {
this._addPredefinedGroups(this._presetGroups);
@ -2075,7 +2061,7 @@ class Choices {
this._addPredefinedChoices(this._presetChoices);
}
this._setLoading(false);
this._stopLoading();
}
if (this._isTextElement) {
@ -2113,13 +2099,11 @@ class Choices {
choices.sort(this.config.sorter);
}
// Determine whether there is a selected choice
const hasSelectedChoice = choices.some(choice => choice.selected);
const firstEnabledChoiceIndex = choices.findIndex(
_choice => _choice.disabled === undefined || !_choice.disabled,
choice => choice.disabled === undefined || !choice.disabled,
);
// Add each choice
choices.forEach((choice, index) => {
const { value, label, customProperties, placeholder } = choice;

View file

@ -1539,12 +1539,12 @@ describe('choices', () => {
const label = 'label';
const choices = [
{
id: '1',
id: 1,
value: '1',
label: 'Test 1',
},
{
id: '2',
id: 2,
value: '2',
label: 'Test 2',
},

View file

@ -44,7 +44,7 @@ export default class List {
}
/**
* @param {HTMLElement} element
* @param {Element} element
* @param {1 | -1} direction
*/
scrollToChildElement(element, direction) {

View file

@ -89,8 +89,8 @@ export const getAdjacentEl = (startEl, selector, direction = 1) => {
};
/**
* @param {HTMLElement} element
* @param {HTMLElement} parent
* @param {Element} element
* @param {Element} parent
* @param {-1 | 1} direction
* @returns {boolean}
*/
@ -131,7 +131,7 @@ export const sanitise = value => {
};
/**
* @returns {function}
* @returns {() => (str: string) => Element}
*/
export const strToEl = (() => {
const tmpEl = document.createElement('div');

View file

@ -152,10 +152,10 @@ export default class Store {
/**
* Get group by group id
* @param {string} id Group ID
* @param {number} id Group ID
* @returns {Group | undefined} Group data
*/
getGroupById(id) {
return this.groups.find(group => group.id === parseInt(id, 10));
return this.groups.find(group => group.id === id);
}
}

View file

@ -245,10 +245,8 @@ describe('reducers/store', () => {
describe('getGroupById', () => {
it('returns group by id', () => {
const id = '1';
const expectedResponse = state.groups.find(
group => group.id === parseInt(id, 10),
);
const id = 1;
const expectedResponse = state.groups.find(group => group.id === id);
const actualResponse = instance.getGroupById(id);
expect(actualResponse).to.eql(expectedResponse);
});

16
types/index.d.ts vendored
View file

@ -23,12 +23,12 @@ declare namespace Choices {
}
interface Choice {
id?: string;
id?: number;
customProperties?: Record<string, any>;
disabled?: boolean;
active?: boolean;
elementId?: string;
groupId?: string;
groupId?: number;
keyCode?: number;
label: string;
placeholder?: boolean;
@ -37,14 +37,14 @@ declare namespace Choices {
}
interface Group {
id?: string;
id?: number;
active?: boolean;
disabled?: boolean;
value: any;
}
interface Item extends Choice {
choiceId?: string;
choiceId?: number;
keyCode?: number;
highlighted?: boolean;
}
@ -61,7 +61,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue, keyCode
*/
addItem: CustomEvent<{
id: string;
id: number;
value: string;
label: string;
groupValue: string;
@ -76,7 +76,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue
*/
removeItem: CustomEvent<{
id: string;
id: number;
value: string;
label: string;
groupValue: string;
@ -90,7 +90,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue
*/
highlightItem: CustomEvent<{
id: string;
id: number;
value: string;
label: string;
groupValue: string;
@ -104,7 +104,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue
*/
unhighlightItem: CustomEvent<{
id: string;
id: number;
value: string;
label: string;
groupValue: string;