Merge pull request #2551 from hunicus/js-template-formatting

Fix spacing on websocket api examples
This commit is contained in:
wiz 2022-09-25 07:38:59 +09:00 committed by GitHub
commit 6235dc97a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 38 deletions

View File

@ -17,50 +17,50 @@ export const wsApiDocsData = {
codeTemplate: { codeTemplate: {
curl: `/api/v1/ws`, curl: `/api/v1/ws`,
commonJS: ` commonJS: `
const { %{0}: { websocket } } = mempoolJS(); const { %{0}: { websocket } } = mempoolJS();
const ws = websocket.initClient({ const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
}); });
ws.addEventListener('message', function incoming({data}) { ws.addEventListener('message', function incoming({data}) {
const res = JSON.parse(data.toString()); const res = JSON.parse(data.toString());
if (res.block) { if (res.block) {
document.getElementById("result-blocks").textContent = JSON.stringify(res.block, undefined, 2); document.getElementById("result-blocks").textContent = JSON.stringify(res.block, undefined, 2);
} }
if (res.mempoolInfo) { if (res.mempoolInfo) {
document.getElementById("result-mempool-info").textContent = JSON.stringify(res.mempoolInfo, undefined, 2); document.getElementById("result-mempool-info").textContent = JSON.stringify(res.mempoolInfo, undefined, 2);
} }
if (res.transactions) { if (res.transactions) {
document.getElementById("result-transactions").textContent = JSON.stringify(res.transactions, undefined, 2); document.getElementById("result-transactions").textContent = JSON.stringify(res.transactions, undefined, 2);
} }
if (res["mempool-blocks"]) { if (res["mempool-blocks"]) {
document.getElementById("result-mempool-blocks").textContent = JSON.stringify(res["mempool-blocks"], undefined, 2); document.getElementById("result-mempool-blocks").textContent = JSON.stringify(res["mempool-blocks"], undefined, 2);
} }
}); });
`, `,
esModule: ` esModule: `
const { %{0}: { websocket } } = mempoolJS(); const { %{0}: { websocket } } = mempoolJS();
const ws = websocket.initServer({ const ws = websocket.initServer({
options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"], options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"],
}); });
ws.on("message", function incoming(data) { ws.on("message", function incoming(data) {
const res = JSON.parse(data.toString()); const res = JSON.parse(data.toString());
if (res.block) { if (res.block) {
console.log(res.block); console.log(res.block);
} }
if (res.mempoolInfo) { if (res.mempoolInfo) {
console.log(res.mempoolInfo); console.log(res.mempoolInfo);
} }
if (res.transactions) { if (res.transactions) {
console.log(res.transactions); console.log(res.transactions);
} }
if (res["mempool-blocks"]) { if (res["mempool-blocks"]) {
console.log(res["mempool-blocks"]); console.log(res["mempool-blocks"]);
} }
}); });
`, `,
}, },
codeSampleMainnet: emptyCodeSample, codeSampleMainnet: emptyCodeSample,

View File

@ -152,6 +152,7 @@ export class CodeTemplateComponent implements OnInit {
const init = async () => { const init = async () => {
${codeText} ${codeText}
}; };
init();`; init();`;
} }
} }