-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
import { Compendium as Client1 } from 'bot_client'; | ||
import { Compendium as Client2 } from 'bot_client2'; | ||
import store from '../../src/store/index'; | ||
|
||
function getClient() { | ||
const useClient2 = 1 === 1; // store.state.userSettings.disableFilters; // нужно где то что то придумать вместо фильтра | ||
return useClient2 ? new Client2() : new Client1(); | ||
} | ||
const clients = [Client1, Client2]; | ||
|
||
const client = getClient(); | ||
let initialized = false; | ||
let client: Client1|Client2 = new Client1(); | ||
|
||
const compendiumClient = localStorage.getItem('compendium_client'); | ||
if (compendiumClient) { | ||
switchInstance(parseInt(compendiumClient)); | ||
} | ||
|
||
export default client; | ||
export default new Proxy(client, { | ||
get(target: Client1 | Client2, p: string | symbol): unknown { | ||
return client[p]; | ||
}, | ||
}); | ||
|
||
export async function init() { | ||
if (!initialized) { | ||
console.log(client); | ||
await client.initialize(); | ||
initialized = true; | ||
} | ||
} | ||
|
||
export function stop() { | ||
client.shutdown(); | ||
initialized = false; | ||
} | ||
|
||
export function switchInstance(clientNum: number) { | ||
stop(); | ||
client = new clients[clientNum](); | ||
localStorage.setItem('compendium_client', String(clientNum)); | ||
} |