Skip to content

Commit

Permalink
fix: minor refactor of message / command definitions. (#549)
Browse files Browse the repository at this point in the history
* fix: minor refactor of message / command definitions.

* Update snapshots
  • Loading branch information
Jason3S authored Sep 20, 2020
1 parent ebcb513 commit 99c8570
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 28 deletions.
6 changes: 3 additions & 3 deletions packages/_settingsViewer/src/api/MessageBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Message, Commands, isMessage, Messages } from './message';

export interface Listener {
cmd: Commands;
fn: (message: Message) => any;
fn: (message: Message) => void;
dispose(): void;
}

export interface Messenger {
listenFor<M extends Messages>(cmd: M['command'], fn: (message: M) => any): Listener;
postMessage<M extends Messages>(msg: M): any;
listenFor<M extends Messages>(cmd: M['command'], fn: (message: M) => void): Listener;
postMessage<M extends Messages>(msg: M): void;
}

export class MessageBus implements Messenger {
Expand Down
36 changes: 15 additions & 21 deletions packages/_settingsViewer/src/api/message.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { Settings, ConfigTarget } from './settings';
export type Commands = 'ConfigurationChangeMessage'
| 'EnableLanguageIdMessage'
| 'EnableLocaleMessage'
| 'RequestConfigurationMessage'
| 'SelectFileMessage'
| 'SelectFolderMessage'
| 'SelectTabMessage'
;

interface DefinedCommands {
ConfigurationChangeMessage: ConfigurationChangeMessage;
EnableLanguageIdMessage: EnableLanguageIdMessage;
EnableLocaleMessage: EnableLocaleMessage;
RequestConfigurationMessage: RequestConfigurationMessage;
SelectFileMessage: SelectFileMessage;
SelectFolderMessage: SelectFolderMessage;
SelectTabMessage: SelectTabMessage;
}

export type Commands = keyof DefinedCommands;

export interface Message {
command: Commands;
}

export type Messages =
ConfigurationChangeMessage
| EnableLanguageIdMessage
| EnableLocaleMessage
| RequestConfigurationMessage
| SelectFileMessage
| SelectFolderMessage
| SelectTabMessage
;
export type Messages = DefinedCommands[Commands];

export function isMessage(data: unknown): data is Message {
return !!(data
Expand Down Expand Up @@ -95,7 +91,5 @@ export const isSelectFileMessage = isA<SelectFileMessage>('SelectFileMessage', [
export const isSelectFolderMessage = isA<SelectFolderMessage>('SelectFolderMessage', [['value', isString]]);
export const isSelectTabMessage = isA<SelectTabMessage>('SelectTabMessage', [['value', isString]]);

interface Record {}

function isObject(v: any): v is Record { return typeof v === 'object' && v !== null; }
function isString(v: any): v is string { return typeof v === 'string'; }
function isObject(v: unknown): v is Record<string, unknown> { return typeof v === 'object' && v !== null; }
function isString(v: unknown): v is string { return typeof v === 'string'; }
6 changes: 3 additions & 3 deletions packages/_settingsViewer/src/test/samples/sampleSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const languageIdsA = [
'c', 'cpp', 'csharp', 'css',
'go', 'handlebars', 'html',
'jade', 'javascript', 'javascriptreact', 'json',
'latex', 'less',
'latex', 'less', 'literate haskell',
'markdown',
'php', 'plaintext', 'pub', 'python',
'restructuredtext', 'rust',
'scss',
'text', 'typescript', 'typescriptreact',
'yml'].sort();
const languageIdsB = languageIdsA.concat(['cfml', 'java', 'scala', 'yaml']).sort();
'yml'];
const languageIdsB = languageIdsA.concat(['cfml', 'java', 'scala', 'yaml']);
const languageIdsUser = languageIdsB;
const languageIdsWorkspace = languageIdsA;
const knownLanguageIds = languageIdsA.concat(languageIdsB).concat(['jsonc', 'perl', 'sh', 'bash', 'avro']).filter(uniqueFilter()).sort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,40 @@ exports[`Config Panel Verification tests the snapshot 1`] = `
less
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-12 MuiChip-clickable"
id="literate haskell"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiChip-icon WithStyles(ForwardRef(Chip))-icon-15"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"
/>
</svg>
<span
className="MuiChip-label WithStyles(ForwardRef(Chip))-label-14"
>
literate haskell
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-12 MuiChip-clickable"
id="markdown"
Expand Down Expand Up @@ -2604,6 +2638,43 @@ exports[`Config Panel Verification tests the snapshot 2`] = `
className="MuiTouchRipple-root"
/>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-12 MuiChip-clickable"
id="literate haskell"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiChip-icon WithStyles(ForwardRef(Chip))-icon-15"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"
/>
</svg>
<span
className="MuiChip-label WithStyles(ForwardRef(Chip))-label-14"
>
literate haskell
</span>
<span
className="MuiTouchRipple-root"
/>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-12 MuiChip-clickable"
id="markdown"
Expand Down Expand Up @@ -4194,6 +4265,40 @@ exports[`Config Panel Verification tests the snapshot 3`] = `
less
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-12 MuiChip-clickable"
id="literate haskell"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiChip-icon WithStyles(ForwardRef(Chip))-icon-15"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"
/>
</svg>
<span
className="MuiChip-label WithStyles(ForwardRef(Chip))-label-14"
>
literate haskell
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-12 MuiChip-clickable"
id="markdown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,40 @@ exports[`SectionFileTypes Verification tests the snapshots: <SectionFiletypes> f
less
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-2 MuiChip-clickable"
id="literate haskell"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiChip-icon WithStyles(ForwardRef(Chip))-icon-5"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"
/>
</svg>
<span
className="MuiChip-label WithStyles(ForwardRef(Chip))-label-4"
>
literate haskell
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-2 MuiChip-clickable"
id="markdown"
Expand Down Expand Up @@ -1868,6 +1902,40 @@ exports[`SectionFileTypes Verification tests the snapshots: <SectionFiletypes> f
less
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-2 MuiChip-clickable"
id="literate haskell"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiChip-icon WithStyles(ForwardRef(Chip))-icon-5"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"
/>
</svg>
<span
className="MuiChip-label WithStyles(ForwardRef(Chip))-label-4"
>
literate haskell
</span>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-2 MuiChip-clickable"
id="markdown"
Expand Down Expand Up @@ -3128,6 +3196,43 @@ exports[`SectionFileTypes Verification tests the snapshots: <SectionFiletypes> f
className="MuiTouchRipple-root"
/>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-2 MuiChip-clickable"
id="literate haskell"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiChip-icon WithStyles(ForwardRef(Chip))-icon-5"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"
/>
</svg>
<span
className="MuiChip-label WithStyles(ForwardRef(Chip))-label-4"
>
literate haskell
</span>
<span
className="MuiTouchRipple-root"
/>
</div>
<div
className="MuiButtonBase-root MuiChip-root WithStyles(ForwardRef(Chip))-root-2 MuiChip-clickable"
id="markdown"
Expand Down
2 changes: 1 addition & 1 deletion packages/_settingsViewer/src/viewer/vsCodeTestWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const localeDisplay: [ConfigTarget, string][] = [
];

@observer
class VsCodeTestWrapperView extends React.Component<{appState: AppState}, {}> {
class VsCodeTestWrapperView extends React.Component<{appState: AppState}> {
render() {
const appState = this.props.appState;
const settings = appState.settings;
Expand Down

0 comments on commit 99c8570

Please sign in to comment.