Skip to content

Commit

Permalink
feat: wasm matches
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Mar 26, 2024
1 parent 8a2992b commit fb1292d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
],
"dependencies": {
"@antv/g6": "^4.8.24",
"@gkd-kit/selector": "0.0.22",
"@gkd-kit/selector": "0.0.23",
"@gkd-kit/wasm_matches": "0.0.1",
"@rushstack/eslint-patch": "^1.7.2",
"@tsconfig/node20": "^20.1.2",
"@types/file-saver": "^2.0.7",
Expand Down
15 changes: 11 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/utils/selector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import {
MultiplatformSelector,
MultiplatformTransform,
updateWasmToMatches,
} from '@gkd-kit/selector';
import type { RawNode } from './types';
import matchesInstantiate from '@gkd-kit/wasm_matches';
import matchesWasmUrl from '@gkd-kit/wasm_matches/dist/mod.wasm?url';

matchesInstantiate(fetch(matchesWasmUrl))
.then((mod) => {
const toMatches = mod.exports.toMatches;
updateWasmToMatches(toMatches as any);
if (import.meta.env.PROD) {
console.log('use wasm matches');
}
})
.catch((e) => {
console.error(e);
if (import.meta.env.PROD) {
console.log('use js matches');
}
});

const transform = new MultiplatformTransform<RawNode>(
(node, name) => {
Expand Down
4 changes: 4 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default defineConfig(() => {
host: '127.0.0.1',
port: 8444,
},
preview: {
host: '127.0.0.1',
port: 8444,
},
build: {
target: `chrome70`,
sourcemap: true,
Expand Down

0 comments on commit fb1292d

Please sign in to comment.