From 19a86cbd596bb7586f03e391053a24de77d409aa Mon Sep 17 00:00:00 2001 From: hunicus <93150691+hunicus@users.noreply.github.com> Date: Tue, 13 Sep 2022 07:14:03 -0400 Subject: [PATCH 1/2] Fix spacing on ws commonjs api example --- .../src/app/docs/api-docs/api-docs-data.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/docs/api-docs/api-docs-data.ts b/frontend/src/app/docs/api-docs/api-docs-data.ts index 7ea01584e..35cdb76ca 100644 --- a/frontend/src/app/docs/api-docs/api-docs-data.ts +++ b/frontend/src/app/docs/api-docs/api-docs-data.ts @@ -17,27 +17,27 @@ export const wsApiDocsData = { codeTemplate: { curl: `/api/v1/ws`, commonJS: ` - const { %{0}: { websocket } } = mempoolJS(); + const { %{0}: { websocket } } = mempoolJS(); - const ws = websocket.initClient({ - options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], - }); + const ws = websocket.initClient({ + options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], + }); - ws.addEventListener('message', function incoming({data}) { - const res = JSON.parse(data.toString()); - if (res.block) { - document.getElementById("result-blocks").textContent = JSON.stringify(res.block, undefined, 2); - } - if (res.mempoolInfo) { - document.getElementById("result-mempool-info").textContent = JSON.stringify(res.mempoolInfo, undefined, 2); - } - if (res.transactions) { - document.getElementById("result-transactions").textContent = JSON.stringify(res.transactions, undefined, 2); - } - if (res["mempool-blocks"]) { - document.getElementById("result-mempool-blocks").textContent = JSON.stringify(res["mempool-blocks"], undefined, 2); - } - }); + ws.addEventListener('message', function incoming({data}) { + const res = JSON.parse(data.toString()); + if (res.block) { + document.getElementById("result-blocks").textContent = JSON.stringify(res.block, undefined, 2); + } + if (res.mempoolInfo) { + document.getElementById("result-mempool-info").textContent = JSON.stringify(res.mempoolInfo, undefined, 2); + } + if (res.transactions) { + document.getElementById("result-transactions").textContent = JSON.stringify(res.transactions, undefined, 2); + } + if (res["mempool-blocks"]) { + document.getElementById("result-mempool-blocks").textContent = JSON.stringify(res["mempool-blocks"], undefined, 2); + } + }); `, esModule: ` const { %{0}: { websocket } } = mempoolJS(); From 7014ac2335b0c1329e184a6508d9e2cdf49fc3f3 Mon Sep 17 00:00:00 2001 From: hunicus <93150691+hunicus@users.noreply.github.com> Date: Tue, 13 Sep 2022 07:16:39 -0400 Subject: [PATCH 2/2] Fix spacing on ws esmodule api example --- .../src/app/docs/api-docs/api-docs-data.ts | 38 +++++++++---------- .../code-template/code-template.component.ts | 1 + 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/docs/api-docs/api-docs-data.ts b/frontend/src/app/docs/api-docs/api-docs-data.ts index 35cdb76ca..4a95c5015 100644 --- a/frontend/src/app/docs/api-docs/api-docs-data.ts +++ b/frontend/src/app/docs/api-docs/api-docs-data.ts @@ -40,27 +40,27 @@ export const wsApiDocsData = { }); `, esModule: ` -const { %{0}: { websocket } } = mempoolJS(); + const { %{0}: { websocket } } = mempoolJS(); -const ws = websocket.initServer({ -options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"], -}); + const ws = websocket.initServer({ + options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"], + }); -ws.on("message", function incoming(data) { -const res = JSON.parse(data.toString()); -if (res.block) { -console.log(res.block); -} -if (res.mempoolInfo) { -console.log(res.mempoolInfo); -} -if (res.transactions) { -console.log(res.transactions); -} -if (res["mempool-blocks"]) { -console.log(res["mempool-blocks"]); -} -}); + ws.on("message", function incoming(data) { + const res = JSON.parse(data.toString()); + if (res.block) { + console.log(res.block); + } + if (res.mempoolInfo) { + console.log(res.mempoolInfo); + } + if (res.transactions) { + console.log(res.transactions); + } + if (res["mempool-blocks"]) { + console.log(res["mempool-blocks"]); + } + }); `, }, codeSampleMainnet: emptyCodeSample, diff --git a/frontend/src/app/docs/code-template/code-template.component.ts b/frontend/src/app/docs/code-template/code-template.component.ts index 1875e175a..b9ec5972f 100644 --- a/frontend/src/app/docs/code-template/code-template.component.ts +++ b/frontend/src/app/docs/code-template/code-template.component.ts @@ -152,6 +152,7 @@ export class CodeTemplateComponent implements OnInit { const init = async () => { ${codeText} }; + init();`; } }