aboutsummaryrefslogtreecommitdiff
path: root/src/console/actions
diff options
context:
space:
mode:
Diffstat (limited to 'src/console/actions')
-rw-r--r--src/console/actions/console.ts34
-rw-r--r--src/console/actions/index.ts76
2 files changed, 81 insertions, 29 deletions
diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts
index 3713a76..ceb419c 100644
--- a/src/console/actions/console.ts
+++ b/src/console/actions/console.ts
@@ -1,40 +1,40 @@
-import messages from 'shared/messages';
-import actions from 'console/actions';
+import messages from '../../shared/messages';
+import * as actions from './index';
-const hide = () => {
+const hide = (): actions.ConsoleAction => {
return {
type: actions.CONSOLE_HIDE,
};
};
-const showCommand = (text) => {
+const showCommand = (text: string): actions.ConsoleAction => {
return {
type: actions.CONSOLE_SHOW_COMMAND,
text: text
};
};
-const showFind = () => {
+const showFind = (): actions.ConsoleAction => {
return {
type: actions.CONSOLE_SHOW_FIND,
};
};
-const showError = (text) => {
+const showError = (text: string): actions.ConsoleAction => {
return {
type: actions.CONSOLE_SHOW_ERROR,
text: text
};
};
-const showInfo = (text) => {
+const showInfo = (text: string): actions.ConsoleAction => {
return {
type: actions.CONSOLE_SHOW_INFO,
text: text
};
};
-const hideCommand = () => {
+const hideCommand = (): actions.ConsoleAction => {
window.top.postMessage(JSON.stringify({
type: messages.CONSOLE_UNFOCUS,
}), '*');
@@ -43,15 +43,17 @@ const hideCommand = () => {
};
};
-const enterCommand = async(text) => {
+const enterCommand = async(
+ text: string,
+): Promise<actions.ConsoleAction> => {
await browser.runtime.sendMessage({
type: messages.CONSOLE_ENTER_COMMAND,
text,
});
- return hideCommand(text);
+ return hideCommand();
};
-const enterFind = (text) => {
+const enterFind = (text: string): actions.ConsoleAction => {
window.top.postMessage(JSON.stringify({
type: messages.CONSOLE_ENTER_FIND,
text,
@@ -59,14 +61,14 @@ const enterFind = (text) => {
return hideCommand();
};
-const setConsoleText = (consoleText) => {
+const setConsoleText = (consoleText: string): actions.ConsoleAction => {
return {
type: actions.CONSOLE_SET_CONSOLE_TEXT,
consoleText,
};
};
-const getCompletions = async(text) => {
+const getCompletions = async(text: string): Promise<actions.ConsoleAction> => {
let completions = await browser.runtime.sendMessage({
type: messages.CONSOLE_QUERY_COMPLETIONS,
text,
@@ -78,13 +80,13 @@ const getCompletions = async(text) => {
};
};
-const completionNext = () => {
+const completionNext = (): actions.ConsoleAction => {
return {
type: actions.CONSOLE_COMPLETION_NEXT,
};
};
-const completionPrev = () => {
+const completionPrev = (): actions.ConsoleAction => {
return {
type: actions.CONSOLE_COMPLETION_PREV,
};
@@ -92,5 +94,5 @@ const completionPrev = () => {
export {
hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText,
- enterCommand, enterFind, getCompletions, completionNext, completionPrev
+ enterCommand, enterFind, getCompletions, completionNext, completionPrev,
};
diff --git a/src/console/actions/index.ts b/src/console/actions/index.ts
index b394179..3770496 100644
--- a/src/console/actions/index.ts
+++ b/src/console/actions/index.ts
@@ -1,13 +1,63 @@
-export default {
- // console commands
- CONSOLE_HIDE: 'console.hide',
- CONSOLE_SHOW_COMMAND: 'console.show.command',
- CONSOLE_SHOW_ERROR: 'console.show.error',
- CONSOLE_SHOW_INFO: 'console.show.info',
- CONSOLE_HIDE_COMMAND: 'console.hide.command',
- CONSOLE_SET_CONSOLE_TEXT: 'console.set.command',
- CONSOLE_SET_COMPLETIONS: 'console.set.completions',
- CONSOLE_COMPLETION_NEXT: 'console.completion.next',
- CONSOLE_COMPLETION_PREV: 'console.completion.prev',
- CONSOLE_SHOW_FIND: 'console.show.find',
-};
+// console commands
+export const CONSOLE_HIDE = 'console.hide';
+export const CONSOLE_SHOW_COMMAND = 'console.show.command';
+export const CONSOLE_SHOW_ERROR = 'console.show.error';
+export const CONSOLE_SHOW_INFO = 'console.show.info';
+export const CONSOLE_HIDE_COMMAND = 'console.hide.command';
+export const CONSOLE_SET_CONSOLE_TEXT = 'console.set.command';
+export const CONSOLE_SET_COMPLETIONS = 'console.set.completions';
+export const CONSOLE_COMPLETION_NEXT = 'console.completion.next';
+export const CONSOLE_COMPLETION_PREV = 'console.completion.prev';
+export const CONSOLE_SHOW_FIND = 'console.show.find';
+
+interface HideAction {
+ type: typeof CONSOLE_HIDE;
+}
+
+interface ShowCommand {
+ type: typeof CONSOLE_SHOW_COMMAND;
+ text: string;
+}
+
+interface ShowFindAction {
+ type: typeof CONSOLE_SHOW_FIND;
+}
+
+interface ShowErrorAction {
+ type: typeof CONSOLE_SHOW_ERROR;
+ text: string;
+}
+
+interface ShowInfoAction {
+ type: typeof CONSOLE_SHOW_INFO;
+ text: string;
+}
+
+interface HideCommandAction {
+ type: typeof CONSOLE_HIDE_COMMAND;
+}
+
+interface SetConsoleTextAction {
+ type: typeof CONSOLE_SET_CONSOLE_TEXT;
+ consoleText: string;
+}
+
+interface SetCompletionsAction {
+ type: typeof CONSOLE_SET_COMPLETIONS;
+ completions: any[];
+ completionSource: string;
+}
+
+interface CompletionNextAction {
+ type: typeof CONSOLE_COMPLETION_NEXT;
+}
+
+interface CompletionPrevAction {
+ type: typeof CONSOLE_COMPLETION_PREV;
+}
+
+export type ConsoleAction =
+ HideAction | ShowCommand | ShowFindAction | ShowErrorAction |
+ ShowInfoAction | HideCommandAction | SetConsoleTextAction |
+ SetCompletionsAction | CompletionNextAction | CompletionPrevAction;
+