refactor: dynamic import
This commit is contained in:
parent
5429913587
commit
667eaded8e
|
@ -1,8 +1,6 @@
|
||||||
import {useEffect, useState} from 'react';
|
import {useEffect, useState} from 'react';
|
||||||
import {Outlet, useParams} from 'react-router-dom';
|
import {Outlet, useParams} from 'react-router-dom';
|
||||||
|
|
||||||
import LocalClient from '@/net/client/local.js';
|
|
||||||
import RemoteClient from '@/net/client/remote.js';
|
|
||||||
import {decode, encode} from '@/packets/index.js';
|
import {decode, encode} from '@/packets/index.js';
|
||||||
|
|
||||||
import styles from './play.module.css';
|
import styles from './play.module.css';
|
||||||
|
@ -12,24 +10,27 @@ export default function Play() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const [type] = params['*'].split('/');
|
const [type] = params['*'].split('/');
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let Client;
|
async function loadClient() {
|
||||||
switch (type) {
|
let Client;
|
||||||
case 'local':
|
switch (type) {
|
||||||
Client = LocalClient;
|
case 'local':
|
||||||
break;
|
({default: Client} = await import('@/net/client/local.js'));
|
||||||
case 'remote':
|
break;
|
||||||
Client = RemoteClient;
|
case 'remote':
|
||||||
break;
|
({default: Client} = await import('@/net/client/remote.js'));
|
||||||
}
|
break;
|
||||||
class SilphiusClient extends Client {
|
|
||||||
accept(packed) {
|
|
||||||
super.accept(decode(packed));
|
|
||||||
}
|
}
|
||||||
transmit(packet) {
|
class SilphiusClient extends Client {
|
||||||
super.transmit(encode(packet));
|
accept(packed) {
|
||||||
|
super.accept(decode(packed));
|
||||||
|
}
|
||||||
|
transmit(packet) {
|
||||||
|
super.transmit(encode(packet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
setClient(() => SilphiusClient);
|
||||||
}
|
}
|
||||||
setClient(() => SilphiusClient);
|
loadClient();
|
||||||
}, [type]);
|
}, [type]);
|
||||||
return (
|
return (
|
||||||
<div className={styles.play}>
|
<div className={styles.play}>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user