Skip to content

Commit

Permalink
perf: await wasm task
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Apr 6, 2024
1 parent bb22b7e commit c354e25
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/SearchCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { errorTry, errorWrap } from '@/utils/error';
import { getNodeLabel } from '@/utils/node';
import { buildEmptyFn, copy } from '@/utils/others';
import type { Selector } from '@/utils/selector';
import { parseSelector } from '@/utils/selector';
import { parseSelector, wasmLoadTask } from '@/utils/selector';
import { githubJpgStorage, githubZipStorage } from '@/utils/storage';
import type { RawNode, Snapshot } from '@/utils/types';
import { githubUrlToSelfUrl } from '@/utils/url';
Expand Down Expand Up @@ -142,6 +142,7 @@ const searchBySelector = errorTry(() => {
});
onMounted(async () => {
await wasmLoadTask;
let count = 0;
if (route.query.gkd) {
count += searchSelector(base64url.decode(route.query.gkd as string)) || 0;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import matchesWasmUrl from '@gkd-kit/wasm_matches/dist/mod.wasm?url';
import store from './store';
import { settingsStorage } from './storage';

let wasmSupported = false;
matchesInstantiate(fetch(matchesWasmUrl))
export const wasmLoadTask = matchesInstantiate(fetch(matchesWasmUrl))
.then((mod) => {
const toMatches = mod.exports.toMatches;
updateWasmToMatches(toMatches as any);
wasmSupported = true;
store.wasmSupported = true;
if (import.meta.env.PROD) {
console.log('use wasm matches');
}
})
.catch((e) => {
store.wasmSupported = false;
console.error(e);
if (import.meta.env.PROD) {
console.log('use js matches');
Expand Down Expand Up @@ -61,7 +61,7 @@ export type ConnectKeyType = '+' | '-' | '>' | '<' | '<<';
export const parseSelector = (source: string): Selector => {
const ms = MultiplatformSelector.Companion.parse(source);
for (const [name, operator, type] of ms.binaryExpressions) {
if (operator == '~=' && !wasmSupported) {
if (operator == '~=' && !store.wasmSupported) {
if (!settingsStorage.ignoreWasmWarn) {
store.wasmErrorDlgVisible = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const store = reactive({
networkErrorDlgVisible: false,
githubErrorDlgVisible: false,
wasmErrorDlgVisible: false,
wasmSupported: undefined as boolean | undefined,
});

export default store;

0 comments on commit c354e25

Please sign in to comment.