Skip to content

Commit

Permalink
fix(bindgen): demo preRun execution for production builds
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Sep 23, 2023
1 parent 3d4eb6c commit 6771346
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
24 changes: 18 additions & 6 deletions src/bindgen/typescript/demo/interface-functions-demo-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ class ${functionNamePascalCase}Model {
result += outputDemoTypeScript(functionName, '', indent, output)
})

result += `\n${indent}const tabGroup = document.querySelector('sl-tab-group')
tabGroup.addEventListener('sl-tab-show', async (event) => {
result += `\n${indent}const preRun = async () => {
if (!this.webWorker && loadSampleInputs && usePreRun) {
await loadSampleInputs(model, true)
await this.run()
}
}
const onSelectTab = async (event) => {
if (event.detail.name === '${functionName}-panel') {
const params = new URLSearchParams(window.location.search)
if (!params.has('functionName') || params.get('functionName') !== '${functionName}') {
Expand All @@ -149,10 +155,16 @@ class ${functionNamePascalCase}Model {
url.search = params
window.history.replaceState({ functionName: '${functionName}' }, '', url)
}
if (!this.webWorker && loadSampleInputs && usePreRun) {
await loadSampleInputs(model, true)
await this.run()
}
await preRun()
}
}
const tabGroup = document.querySelector('sl-tab-group')
tabGroup.addEventListener('sl-tab-show', onSelectTab)
document.addEventListener('DOMContentLoaded', () => {
const params = new URLSearchParams(window.location.search)
if (params.has('functionName') && params.get('functionName') === '${functionName}') {
preRun()
}
})
Expand Down
13 changes: 6 additions & 7 deletions src/bindgen/typescript/typescript-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,12 @@ function typescriptBindings (outputDir, buildDir, wasmBinaries, options, forNode
readmePipelines += readmeResult
})

demoFunctionsTypeScript += `\nconst tabGroup = document.querySelector('sl-tab-group')
const params = new URLSearchParams(window.location.search)
if (params.has('functionName')) {
const functionName = params.get('functionName')
tabGroup.show(functionName + '-panel')
} else {
tabGroup.show('${firstFunctionName}-panel')
demoFunctionsTypeScript += `\nconst params = new URLSearchParams(window.location.search)
if (!params.has('functionName')) {
params.set('functionName', '${firstFunctionName}')
const url = new URL(document.location)
url.search = params
window.history.replaceState({ functionName: '${firstFunctionName}' }, '', url)
}
`

Expand Down

0 comments on commit 6771346

Please sign in to comment.