mirror of
https://github.com/thelounge/thelounge
synced 2024-11-24 21:13:06 +00:00
client/commands: statically import commands
Dynamic imports won't work very well with modules and we don't really need them, it's just there to save us an import statement. Let's flip this to a static version.
This commit is contained in:
parent
9ae9482223
commit
3fbbc39cd6
6 changed files with 22 additions and 38 deletions
|
@ -56,7 +56,7 @@
|
|||
import Mousetrap from "mousetrap";
|
||||
import {wrapCursor} from "undate";
|
||||
import autocompletion from "../js/autocompletion";
|
||||
import commands from "../js/commands/index";
|
||||
import {commands} from "../js/commands/index";
|
||||
import socket from "../js/socket";
|
||||
import upload from "../js/upload";
|
||||
import eventbus from "../js/eventbus";
|
||||
|
@ -185,10 +185,7 @@ export default defineComponent({
|
|||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(commands, cmd) &&
|
||||
commands[cmd].input(args)
|
||||
) {
|
||||
if (Object.prototype.hasOwnProperty.call(commands, cmd) && commands[cmd](args)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import socket from "../socket";
|
||||
import {store} from "../store";
|
||||
|
||||
function input() {
|
||||
export function input(): boolean {
|
||||
if (!store.state.activeChannel) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const messageIds: number[] = [];
|
||||
|
@ -34,5 +34,3 @@ function input() {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default {input};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import socket from "../socket";
|
||||
import {store} from "../store";
|
||||
|
||||
function input() {
|
||||
export function input(): boolean {
|
||||
if (!store.state.activeChannel) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const messageIds: number[] = [];
|
||||
|
@ -34,5 +34,3 @@ function input() {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default {input};
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
// Taken from views/index.js
|
||||
import {input as collapse} from "./collapse";
|
||||
import {input as expand} from "./expand";
|
||||
import {input as join} from "./join";
|
||||
import {input as search} from "./search";
|
||||
|
||||
// This creates a version of `require()` in the context of the current
|
||||
// directory, so we iterate over its content, which is a map statically built by
|
||||
// Webpack.
|
||||
// Second argument says it's recursive, third makes sure we only load javascript.
|
||||
const commands = require.context("./", true, /\.ts$/);
|
||||
|
||||
export default commands.keys().reduce<Record<string, unknown>>((acc, path) => {
|
||||
const command = path.substring(2, path.length - 3);
|
||||
|
||||
if (command === "index") {
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc[command] = commands(path).default;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
export const commands = {
|
||||
collapse: collapse,
|
||||
expand: expand,
|
||||
join: join,
|
||||
search: search,
|
||||
};
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import socket from "../socket";
|
||||
import {store} from "../store";
|
||||
import {switchToChannel} from "../router";
|
||||
import {ChanType} from "../../../shared/types/chan";
|
||||
|
||||
function input(args: string[]) {
|
||||
export function input(args: string[]): boolean {
|
||||
if (args.length > 0) {
|
||||
let channels = args[0];
|
||||
|
||||
|
@ -35,7 +36,7 @@ function input(args: string[]) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
} else if (store.state.activeChannel?.channel.type === "channel") {
|
||||
} else if (store.state.activeChannel?.channel.type === ChanType.CHANNEL) {
|
||||
// If `/join` command is used without any arguments, re-join current channel
|
||||
socket.emit("input", {
|
||||
target: store.state.activeChannel.channel.id,
|
||||
|
@ -44,6 +45,6 @@ function input(args: string[]) {
|
|||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export default {input};
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {store} from "../store";
|
||||
import {router} from "../router";
|
||||
|
||||
function input(args: string[]) {
|
||||
export function input(args: string[]): boolean {
|
||||
if (!store.state.settings.searchEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
@ -23,5 +23,3 @@ function input(args: string[]) {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default {input};
|
||||
|
|
Loading…
Reference in a new issue