Skip to content

Commit

Permalink
Map traceFn param of hangulize() on worker API
Browse files Browse the repository at this point in the history
  • Loading branch information
sublee committed Feb 18, 2023
1 parent f95970d commit ea34f7b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions web/src/hangulize/hangulize.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import * as Comlink from 'comlink'
import { runWebAssembly } from './runWebAssembly'
import type { Specs } from './spec'

export interface HangulizeTrace {
step: string
word: string
why: string
}

interface WasmHangulize {
(lang: string, word: string): Promise<string>
(lang: string, word: string, traceFn?: (t: HangulizeTrace) => void): Promise<string>
version: string
specs: Specs
useTranslit: (method: string, fn: (word: string) => Promise<string>) => void
useTranslit: (method: string, fn: (word: string) => Promise<string>) => boolean
}

declare global {
Expand All @@ -19,16 +25,16 @@ declare global {
const ready = runWebAssembly(new URL('hangulize.wasm', import.meta.url))

export interface HangulizeEndpoint {
hangulize: (lang: string, word: string) => Promise<string>
hangulize: (lang: string, word: string, traceFn?: (t: HangulizeTrace) => void) => Promise<string>
getVersion: () => Promise<string>
getSpecs: () => Promise<Specs>
useTranslit: (method: string, fn: (word: string) => Promise<string>) => Promise<void>
}

const endpoint: HangulizeEndpoint = {
async hangulize(lang: string, word: string) {
async hangulize(lang: string, word: string, traceFn?: (t: HangulizeTrace) => void) {
await ready
return await hangulize(lang, word)
return await hangulize(lang, word, traceFn)
},

async getVersion() {
Expand Down

0 comments on commit ea34f7b

Please sign in to comment.