Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: render react app setup into dedicated js file #686

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading