Skip to content

Commit

Permalink
feat: render react app setup into dedicated js file (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwiesenbauer authored Nov 4, 2024
1 parent 09f9522 commit 8a93359
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 214 deletions.
23 changes: 17 additions & 6 deletions components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function Index({ asyncapi, params = {} }) {
if(params.baseHref) {
basehref = `<base href="${params.baseHref}">`;
}
let appJs = `<script type="application/javascript" src="js/app.js"></script>`;
if(params?.singleFile) {
appJs = `<script>${App({asyncapi, params})}</script>`;
}
return (`<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -42,13 +46,20 @@ export function Index({ asyncapi, params = {} }) {
${asyncapiScript}
<script>
const schema = ${stringifySpec(asyncapi)};
const config = ${stringifyConfiguration(params)};
AsyncApiStandalone.hydrate({ schema, config }, document.getElementById("root"));
</script>
${appJs}
</body>
</html>`
);
}


export function App({ asyncapi, params = {} }) {
return (`
const schema = ${stringifySpec(asyncapi)};
const config = ${stringifyConfiguration(params)};
const appRoot = document.getElementById('root');
AsyncApiStandalone.render(
{ schema, config, }, appRoot
);
`
);
}
17 changes: 17 additions & 0 deletions template/js/app.js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { File } from '@asyncapi/generator-react-sdk';
import { App } from '../../components/index';
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';

/**
*
* @param {object} param0
* @param {AsyncAPIDocumentInterface} param0.asyncapi
* @returns
*/
export default function({ asyncapi, params = {} }) {
return (
<File name='app.js'>
<App asyncapi={asyncapi} params={params} />
</File>
);
}
Loading

0 comments on commit 8a93359

Please sign in to comment.