diff options
author | chocolateboy <chocolate@cpan.org> | 2019-07-31 16:17:37 +0100 |
---|---|---|
committer | chocolateboy <chocolate@cpan.org> | 2019-07-31 17:06:48 +0100 |
commit | f65c068c67371f00b7853b4790b926e672f3ca4f (patch) | |
tree | 5de9d7ee7047402d8e341d342e6d5f5c44a1348d /src/shared/operations.ts | |
parent | c57089224ea671178dcf66f5e36b9aed8e6db323 (diff) |
tabs.close: rename selectLeft (boolean) -> select ("left" | "right")
before:
{
"type": "tabs.close",
"selectLeft": true | false // (default: false)
}
after:
{
"type": "tabs.close",
"select": "left" | "right" // (default: "right")
}
Diffstat (limited to 'src/shared/operations.ts')
-rw-r--r-- | src/shared/operations.ts | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/shared/operations.ts b/src/shared/operations.ts index f657db1..2df2e67 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -201,7 +201,7 @@ export interface PageHomeOperation { export interface TabCloseOperation { type: typeof TAB_CLOSE; - selectLeft?: boolean; + select?: 'left' | 'right'; } export interface TabCloseForceOperation { @@ -372,6 +372,19 @@ const assertOptionalBoolean = (obj: any, name: string) => { } }; +const assertOptionalString = (obj: any, name: string, values?: string[]) => { + if (Object.prototype.hasOwnProperty.call(obj, name)) { + let value = obj[name]; + if (typeof value !== 'string') { + throw new TypeError(`Not a string parameter: '${name}'`); + } + if (values && values.length && values.indexOf(value) === -1) { + // eslint-disable-next-line max-len + throw new TypeError(`Invalid parameter for '${name}': '${value}'`); + } + } +}; + const assertRequiredNumber = (obj: any, name: string) => { if (!Object.prototype.hasOwnProperty.call(obj, name) || typeof obj[name] !== 'number') { @@ -418,10 +431,10 @@ export const valueOf = (o: any): Operation => { newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab), }; case TAB_CLOSE: - assertOptionalBoolean(o, 'selectLeft'); + assertOptionalString(o, 'select', ['left', 'right']); return { type: TAB_CLOSE, - selectLeft: Boolean(typeof o.selectLeft === undefined ? false : o.selectLeft), // eslint-disable-line max-len + select: (typeof o.select === undefined ? 'right' : o.select), }; case TAB_RELOAD: assertOptionalBoolean(o, 'cache'); |