performances: async loading
This commit is contained in:
+9
-33
@@ -1,17 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onBeforeMount } from "vue";
|
import { ref, onMounted, defineAsyncComponent } from "vue";
|
||||||
import PageRandom from "@/components/PageRandom.vue";
|
const PageRandom = defineAsyncComponent(() => import("@/components/PageRandom.vue"));
|
||||||
import PageInput from "@/components/PageInput.vue";
|
const PageInput = defineAsyncComponent(() => import("@/components/PageInput.vue"));
|
||||||
|
const PageHistory = defineAsyncComponent(() => import("./components/PageHistory.vue"));
|
||||||
import { DomainFactory } from "@/lib/factory";
|
import { DomainFactory } from "@/lib/factory";
|
||||||
import PageHistory from "./components/PageHistory.vue";
|
|
||||||
|
|
||||||
const visible = ref<boolean>(false);
|
const visible = ref<boolean>(false);
|
||||||
const factory = ref<DomainFactory>(new DomainFactory());
|
const factory = ref<DomainFactory>(new DomainFactory());
|
||||||
|
|
||||||
onBeforeMount(() => {
|
|
||||||
factory.value.init();
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
@@ -22,37 +18,17 @@ onMounted(() => {
|
|||||||
<template>
|
<template>
|
||||||
<div :style="{ display: visible ? 'inherit' : 'none' }">
|
<div :style="{ display: visible ? 'inherit' : 'none' }">
|
||||||
<div class="tabs tabs-xs tabs-bottom w-xl max-w-svw shrink-0">
|
<div class="tabs tabs-xs tabs-bottom w-xl max-w-svw shrink-0">
|
||||||
<input
|
<input type="radio" name="app_tabs" class="tab" :aria-label="$t('tab.random')" checked />
|
||||||
type="radio"
|
<div class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden">
|
||||||
name="app_tabs"
|
|
||||||
class="tab"
|
|
||||||
:aria-label="$t('tab.random')"
|
|
||||||
checked
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden"
|
|
||||||
>
|
|
||||||
<PageRandom :factory="factory" />
|
<PageRandom :factory="factory" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input
|
<input type="radio" name="app_tabs" class="tab" :aria-label="$t('tab.input')" />
|
||||||
type="radio"
|
<div class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden">
|
||||||
name="app_tabs"
|
|
||||||
class="tab"
|
|
||||||
:aria-label="$t('tab.input')"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden"
|
|
||||||
>
|
|
||||||
<PageInput :factory="factory" />
|
<PageInput :factory="factory" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input
|
<input type="radio" name="app_tabs" class="tab" :aria-label="$t('tab.history')" />
|
||||||
type="radio"
|
|
||||||
name="app_tabs"
|
|
||||||
class="tab"
|
|
||||||
:aria-label="$t('tab.history')"
|
|
||||||
/>
|
|
||||||
<div
|
<div
|
||||||
class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-x-hidden overflow-y-scroll max-h-96"
|
class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-x-hidden overflow-y-scroll max-h-96"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { DomainFactory } from "@/lib/factory";
|
import type { DomainFactory } from "@/lib/factory";
|
||||||
import CoolDomain from "./CoolDomain.vue";
|
import { defineAsyncComponent } from "vue";
|
||||||
|
const CoolDomain = defineAsyncComponent(() => import("./CoolDomain.vue"));
|
||||||
|
|
||||||
defineProps<{ factory: DomainFactory }>();
|
defineProps<{ factory: DomainFactory }>();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from "vue";
|
import { defineAsyncComponent, ref } from "vue";
|
||||||
import type { DomainFactory } from "@/lib/factory";
|
import type { DomainFactory } from "@/lib/factory";
|
||||||
import CoolDomain from "./CoolDomain.vue";
|
const CoolDomain = defineAsyncComponent(() => import("./CoolDomain.vue"));
|
||||||
import type { Domain } from "@/types";
|
import type { Domain } from "@/types";
|
||||||
import { isDomainAvailable } from "@/lib/whois";
|
import { isDomainAvailable } from "@/lib/whois";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onBeforeMount, watch } from "vue";
|
import { ref, onBeforeMount, watch, defineAsyncComponent } from "vue";
|
||||||
import { isDomainAvailable } from "@/lib/whois";
|
import { isDomainAvailable } from "@/lib/whois";
|
||||||
import type { DomainFactory } from "@/lib/factory";
|
import type { DomainFactory } from "@/lib/factory";
|
||||||
import CoolDomain from "./CoolDomain.vue";
|
const CoolDomain = defineAsyncComponent(() => import("./CoolDomain.vue"));
|
||||||
import type { Domain } from "@/types";
|
import type { Domain } from "@/types";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
|
||||||
|
|||||||
+25
-9
@@ -1,11 +1,9 @@
|
|||||||
import rawTldList from "@/data/tld.txt?raw";
|
const rawTldList = () => import("@/data/tld.txt?raw");
|
||||||
import englishWords from "@/data/english.txt?raw";
|
const englishWords = () => import("@/data/english.txt?raw");
|
||||||
import frenchWords from "@/data/french.txt?raw";
|
const frenchWords = () => import("@/data/french.txt?raw");
|
||||||
import { randomElement, shuffled } from "./random";
|
import { randomElement, shuffled } from "./random";
|
||||||
import type { Domain } from "@/types";
|
import type { Domain } from "@/types";
|
||||||
|
|
||||||
const TLD_LIST: string[] = rawTldList.trim().split("\n");
|
|
||||||
|
|
||||||
export class DomainFactory {
|
export class DomainFactory {
|
||||||
error: string | null = null;
|
error: string | null = null;
|
||||||
words: Record<string, string[]> = {};
|
words: Record<string, string[]> = {};
|
||||||
@@ -13,10 +11,20 @@ export class DomainFactory {
|
|||||||
history: Domain[] = [];
|
history: Domain[] = [];
|
||||||
tldList: string[] = [];
|
tldList: string[] = [];
|
||||||
|
|
||||||
init() {
|
async init(lang: string | null = null) {
|
||||||
this.words.fr = this.initWords(frenchWords);
|
if (lang && !this.words[lang]) {
|
||||||
this.words.en = this.initWords(englishWords);
|
switch (lang) {
|
||||||
this.tldList = TLD_LIST;
|
case "en":
|
||||||
|
this.words.en = this.initWords((await englishWords()).default);
|
||||||
|
break;
|
||||||
|
case "fr":
|
||||||
|
this.words.fr = this.initWords((await frenchWords()).default);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.tldList.length == 0) {
|
||||||
|
this.tldList = (await rawTldList()).default.trim().split("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
escapeWord(word: string): string {
|
escapeWord(word: string): string {
|
||||||
@@ -64,6 +72,8 @@ export class DomainFactory {
|
|||||||
|
|
||||||
next(lang: string): Promise<Domain> {
|
next(lang: string): Promise<Domain> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
this.init(lang)
|
||||||
|
.then(() => {
|
||||||
let k = 10000;
|
let k = 10000;
|
||||||
while (k > 0) {
|
while (k > 0) {
|
||||||
k--;
|
k--;
|
||||||
@@ -78,6 +88,8 @@ export class DomainFactory {
|
|||||||
}
|
}
|
||||||
this.error = "Could not generate a valid domain";
|
this.error = "Could not generate a valid domain";
|
||||||
reject(new Error(this.error));
|
reject(new Error(this.error));
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +109,8 @@ export class DomainFactory {
|
|||||||
allFromWord(word: string): Promise<Domain[]> {
|
allFromWord(word: string): Promise<Domain[]> {
|
||||||
const escapedWord = this.escapeWord(word.replace(/ /gm, "-"));
|
const escapedWord = this.escapeWord(word.replace(/ /gm, "-"));
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
this.init()
|
||||||
|
.then(() => {
|
||||||
const domains = [];
|
const domains = [];
|
||||||
for (const tld of shuffled(this.tldList.slice())) {
|
for (const tld of shuffled(this.tldList.slice())) {
|
||||||
const tldEscaped: string = tld.replace(".", "");
|
const tldEscaped: string = tld.replace(".", "");
|
||||||
@@ -113,6 +127,8 @@ export class DomainFactory {
|
|||||||
resolve(domains);
|
resolve(domains);
|
||||||
}
|
}
|
||||||
reject(new Error("Could not generate a valid domain"));
|
reject(new Error("Could not generate a valid domain"));
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
import { createApp } from "vue";
|
import { createApp, defineAsyncComponent } from "vue";
|
||||||
import { createI18n } from "vue-i18n";
|
import { createI18n } from "vue-i18n";
|
||||||
import App from "./App.vue";
|
const App = defineAsyncComponent(() => import("./App.vue"));
|
||||||
import en from "./i18n/en.json";
|
const en = await import("./i18n/en.json");
|
||||||
import fr from "./i18n/fr.json";
|
const fr = await import("./i18n/fr.json");
|
||||||
|
|
||||||
function getLang() {
|
function getLang() {
|
||||||
return document.location.hash === "#french" ? "fr" : "en";
|
return document.location.hash === "#french" ? "fr" : "en";
|
||||||
|
|||||||
Reference in New Issue
Block a user