Skip to content

Commit

Permalink
render react app setup into dedicated js file
Browse files Browse the repository at this point in the history
  • Loading branch information
mwiesenbauer committed Oct 14, 2024
1 parent 77d68a0 commit 8599967
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
19 changes: 13 additions & 6 deletions components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ export function Index({ asyncapi, params = {} }) {
${asyncapiScript}
<script>
const schema = ${stringifySpec(asyncapi)};
const config = ${stringifyConfiguration(params)};
AsyncApiStandalone.hydrate({ schema, config }, document.getElementById("root"));
</script>
<script type="application/javascript" src="js/app.js"></script>
</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>
);
}

0 comments on commit 8599967

Please sign in to comment.