Commit 5e94d371 authored by Mark Stenglein's avatar Mark Stenglein

Parameter: Refactoring

I know I told @rhitt I don't use the backspace key, and instead write
perfect code, but this was super awkward.

This commit eliminates an unneeded boolean flag variable as well as some
hacky control structures by throwing the exception when the problem is
detected instead of waiting.

As a bonus, this should help increase speed when dealing with longer
lists of parameter values where one may be invalid.
Signed-off-by: Mark Stenglein's avatarMark Stenglein <mark@stengle.in>
parent 32d76c54
Pipeline #1169 passed with stage
in 41 seconds
......@@ -132,25 +132,19 @@ export default class Parameter implements ICalElement {
* @throws TypeError if any of the input values are not valid param-value's
*/
set paramValues(newValues: string[]) {
let valid: boolean = true;
newValues.forEach(newValue => {
if (
!((Parameter.isParamText(newValue)) ||
(Parameter.isQuotedString(newValue)))
) {
valid = false;
throw new TypeError(
"param-value must either be valid paramtext or" +
" quoted-string"
);
}
});
if (!valid) {
throw new TypeError(
"param-value must either be valid paramtext or" +
" quoted-string"
);
}
else {
this._paramValues = newValues;
}
this._paramValues = newValues;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment