-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
configurable timeout and delay values #61
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e59a00e
configurable timeout and delay values
gnarf cdeffd1
types draft
gnarf 85864e6
individual options for each time
gnarf 01d05fb
more restrictive types for the helper functions
gnarf c644f56
prefer lowercase string and number type (seems to be tsc standard)
gnarf 0d7edeb
remove makeSnakeCasedKey function
gnarf ea8d351
pass timesOption config to modules instead of stateful module
gnarf 639688d
fix jsdoc
gnarf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/// <reference path="./types.js" /> | ||
|
||
/** | ||
* @module shared | ||
*/ | ||
|
||
/** | ||
* @type AriaATCIShared.timesOption | ||
*/ | ||
const timesDefaults = { | ||
afterNav: 1000, | ||
afterKeys: 5000, | ||
testSetup: 1000, | ||
modeSwitch: 750, | ||
docReady: 2000, | ||
}; | ||
|
||
/** | ||
* Create a yargs description for the specified timesOption. | ||
* @param {keyof AriaATCIShared.timesOption} optionName Key from timesOption | ||
* @param {string} argName The text used for the argument (without leading --) | ||
* @param {string} describe Description to be used in --show-help | ||
*/ | ||
function addOptionConfig(optionName, argName, describe) { | ||
timesOptionsArgNameMap.set(optionName, argName); | ||
timesOptionsConfig[argName] = { | ||
hidden: true, | ||
default: timesDefaults[optionName], | ||
describe, | ||
coerce(arg) { | ||
const isNumber = typeof arg === 'number'; | ||
if (!isNumber && !arg.match(/^\d+$/)) { | ||
throw new Error('option value not a number'); | ||
} | ||
const time = isNumber ? arg : parseInt(arg, 10); | ||
if (time <= 0) { | ||
throw new Error('time must be positive and non-zero'); | ||
} | ||
return time; | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* @type Map<keyof AriaATCIShared.timesOption, string> | ||
*/ | ||
const timesOptionsArgNameMap = new Map(); | ||
|
||
/** | ||
* the yargs configuration for the time options | ||
*/ | ||
export const timesOptionsConfig = {}; | ||
addOptionConfig( | ||
'afterNav', | ||
'time-after-nav', | ||
'Timeout used after navigation to collect and discard speech.' | ||
); | ||
addOptionConfig( | ||
'afterKeys', | ||
'time-after-keys', | ||
'Timeout used to wait for speech to finish after pressing keys.' | ||
); | ||
addOptionConfig( | ||
'testSetup', | ||
'time-test-setup', | ||
'Timeout used after pressing test setup button to collect and discard speech.' | ||
); | ||
addOptionConfig( | ||
'modeSwitch', | ||
'time-mode-switch', | ||
'Timeout used after switching modes to check resulting speech (NVDA).' | ||
); | ||
addOptionConfig('docReady', 'time-doc-ready', 'Timeout used waiting for document ready (Safari).'); | ||
|
||
/** | ||
* Convert the times dictionary to an array of strings to pass back to args. | ||
* @param {AriaATCIShared.timesOption} opts | ||
* @returns [string] | ||
*/ | ||
export function timesArgs(opts) { | ||
const args = []; | ||
for (const key of Object.keys(opts)) { | ||
const value = opts[key]; | ||
// no need to pass on "default" value | ||
if (value == timesDefaults[key]) continue; | ||
// casting in jsdoc syntax is complicated - the extra () around key are | ||
// required to make the type annotation work. | ||
const argName = timesOptionsArgNameMap.get(/** @type keyof AriaATCIShared.timesOption */ (key)); | ||
args.push('--' + argName); | ||
args.push(String(value)); | ||
} | ||
return args; | ||
} | ||
|
||
/** | ||
* Convert the arguments parse result into a timesOption object. | ||
* @param {any} args The parsed arguments | ||
* @returns {AriaATCIShared.timesOption} | ||
*/ | ||
export function getTimesOption(args) { | ||
const result = { ...timesDefaults }; | ||
for (const key in result) { | ||
const mapped = timesOptionsArgNameMap.get(/** @type keyof AriaATCIShared.timesOption */ (key)); | ||
if (mapped) { | ||
if (args[mapped]) result[key] = args[mapped]; | ||
} | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[string]
means "an array with exactly one string element"; what we want here is(The compiler isn't flagging this right now, presumably due to the absence of curly braces. I guess it considers that "not JSDoc" rather than "invalid JSDoc".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops! thanks! (still not super used to the jsdoc format)