Skip to content

Commit 8a93359

Browse files
authored
feat: render react app setup into dedicated js file (#686)
1 parent 09f9522 commit 8a93359

File tree

4 files changed

+270
-214
lines changed

4 files changed

+270
-214
lines changed

components/index.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export function Index({ asyncapi, params = {} }) {
2626
if(params.baseHref) {
2727
basehref = `<base href="${params.baseHref}">`;
2828
}
29+
let appJs = `<script type="application/javascript" src="js/app.js"></script>`;
30+
if(params?.singleFile) {
31+
appJs = `<script>${App({asyncapi, params})}</script>`;
32+
}
2933
return (`<!DOCTYPE html>
3034
<html lang="en">
3135
<head>
@@ -42,13 +46,20 @@ export function Index({ asyncapi, params = {} }) {
4246
4347
${asyncapiScript}
4448
45-
<script>
46-
const schema = ${stringifySpec(asyncapi)};
47-
const config = ${stringifyConfiguration(params)};
48-
AsyncApiStandalone.hydrate({ schema, config }, document.getElementById("root"));
49-
</script>
49+
${appJs}
5050
</body>
5151
</html>`
5252
);
5353
}
54-
54+
55+
export function App({ asyncapi, params = {} }) {
56+
return (`
57+
const schema = ${stringifySpec(asyncapi)};
58+
const config = ${stringifyConfiguration(params)};
59+
const appRoot = document.getElementById('root');
60+
AsyncApiStandalone.render(
61+
{ schema, config, }, appRoot
62+
);
63+
`
64+
);
65+
}

template/js/app.js.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { File } from '@asyncapi/generator-react-sdk';
2+
import { App } from '../../components/index';
3+
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
4+
5+
/**
6+
*
7+
* @param {object} param0
8+
* @param {AsyncAPIDocumentInterface} param0.asyncapi
9+
* @returns
10+
*/
11+
export default function({ asyncapi, params = {} }) {
12+
return (
13+
<File name='app.js'>
14+
<App asyncapi={asyncapi} params={params} />
15+
</File>
16+
);
17+
}

0 commit comments

Comments
 (0)