aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/profile-conditions-ui.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-28 22:17:38 -0500
committerGitHub <noreply@github.com>2023-12-29 03:17:38 +0000
commit1e254fd1d4423b984e176547ef36a14383bbd7f5 (patch)
tree8aae2c47f80265d5f1f39c927e19455ec3986387 /ext/js/pages/settings/profile-conditions-ui.js
parenta51ae1533c54162f14785652e9128f90afb86aed (diff)
Event dispatcher refactor (#463)
* Refactor EventDispatcher template type * Update core types * Update log * Update clipboard monitor * Update application events * Update popup events * Update text scanner * Update cross frame API * Update display events * Type updates * Update display history * Update query parser * Update search persistent state controller * Update panel element * Update popup menu * Update audio system * Update hotkey handler * Update settings controller * Update audio controller * Update types * Update types * Update types * Add event handler types * Update type * Fix issues * Remove error suppression * Fix typo
Diffstat (limited to 'ext/js/pages/settings/profile-conditions-ui.js')
-rw-r--r--ext/js/pages/settings/profile-conditions-ui.js33
1 files changed, 14 insertions, 19 deletions
diff --git a/ext/js/pages/settings/profile-conditions-ui.js b/ext/js/pages/settings/profile-conditions-ui.js
index 29e7460f..22e47a9b 100644
--- a/ext/js/pages/settings/profile-conditions-ui.js
+++ b/ext/js/pages/settings/profile-conditions-ui.js
@@ -22,7 +22,7 @@ import {querySelectorNotNull} from '../../dom/query-selector.js';
import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js';
/**
- * @augments EventDispatcher<import('profile-conditions-ui').EventType>
+ * @augments EventDispatcher<import('profile-conditions-ui').Events>
*/
export class ProfileConditionsUI extends EventDispatcher {
/**
@@ -440,9 +440,7 @@ export class ProfileConditionsUI extends EventDispatcher {
* @param {number} count
*/
_triggerConditionGroupCountChanged(count) {
- /** @type {import('profile-conditions-ui').ConditionGroupCountChangedEvent} */
- const event = {count, profileIndex: this._profileIndex};
- this.trigger('conditionGroupCountChanged', event);
+ this.trigger('conditionGroupCountChanged', {count, profileIndex: this._profileIndex});
}
}
@@ -747,7 +745,7 @@ class ProfileConditionUI {
/**
* @param {import('profile-conditions-ui').InputData} details
- * @param {import('keyboard-mouse-input-field').ChangeEvent} event
+ * @param {import('keyboard-mouse-input-field').EventArgument<'change'>} event
*/
_onModifierInputChange({validate, normalize}, event) {
const modifiers = this._joinModifiers(event.modifiers);
@@ -863,10 +861,6 @@ class ProfileConditionUI {
let inputValue = value;
let inputStep = null;
let showMouseButton = false;
- /** @type {import('event-listener-collection').AddEventListenerArgs[]} */
- const events1 = [];
- /** @type {import('event-listener-collection').OnArgs[]} */
- const events2 = [];
/** @type {import('profile-conditions-ui').InputData} */
const inputData = {validate, normalize};
const node = this._valueInput;
@@ -875,7 +869,6 @@ class ProfileConditionUI {
case 'integer':
inputType = 'number';
inputStep = '1';
- events1.push([node, 'change', this._onValueInputChange.bind(this, inputData), false]);
break;
case 'modifierKeys':
case 'modifierInputs':
@@ -883,10 +876,6 @@ class ProfileConditionUI {
showMouseButton = (type === 'modifierInputs');
this._kbmInputField = this._parent.parent.createKeyboardMouseInputField(node, this._mouseButton);
this._kbmInputField.prepare(null, this._splitModifiers(value), showMouseButton, false);
- events2.push([this._kbmInputField, 'change', this._onModifierInputChange.bind(this, inputData)]);
- break;
- default: // 'string'
- events1.push([node, 'change', this._onValueInputChange.bind(this, inputData), false]);
break;
}
@@ -902,11 +891,17 @@ class ProfileConditionUI {
node.removeAttribute('step');
}
this._mouseButtonContainer.hidden = !showMouseButton;
- for (const args of events1) {
- this._inputEventListeners.addEventListener(...args);
- }
- for (const args of events2) {
- this._inputEventListeners.on(...args);
+
+ switch (type) {
+ case 'modifierKeys':
+ case 'modifierInputs':
+ if (this._kbmInputField !== null) {
+ this._inputEventListeners.on(this._kbmInputField, 'change', this._onModifierInputChange.bind(this, inputData));
+ }
+ break;
+ default: // 'integer', 'string'
+ this._inputEventListeners.addEventListener(node, 'change', this._onValueInputChange.bind(this, inputData), false);
+ break;
}
return this._validateValue(value, validate);