From 76f0187ac18e29ff533739a2d29a490d9543dc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Wed, 12 Jun 2024 12:45:24 +1200 Subject: [PATCH] chore: simplify example smoldot worker --- apps/docs/docs/getting-started/setup.mdx | 9 ++++++--- apps/example/src/config.ts | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/docs/docs/getting-started/setup.mdx b/apps/docs/docs/getting-started/setup.mdx index db7110d9..af4e9d87 100644 --- a/apps/docs/docs/getting-started/setup.mdx +++ b/apps/docs/docs/getting-started/setup.mdx @@ -72,14 +72,17 @@ import { chainSpec } from "polkadot-api/chains/polkadot"; import { getSmProvider } from "polkadot-api/sm-provider"; import { startFromWorker } from "polkadot-api/smoldot/from-worker"; -const smoldot = startFromWorker(new SmWorker()); -const chain = smoldot.addChain({ chainSpec }); +const smoldot = startFromWorker( + new Worker(new URL("polkadot-api/smoldot/worker", import.meta.url), { + type: "module", + }), +); const config: Config = { chains: { polkadot: { descriptor: polkadot, - provider: getSmProvider(chain), + provider: getSmProvider(smoldot.addChain({ chainSpec })), }, }, wallets: [new InjectedConnector()], diff --git a/apps/example/src/config.ts b/apps/example/src/config.ts index e33bccee..1353050c 100644 --- a/apps/example/src/config.ts +++ b/apps/example/src/config.ts @@ -4,10 +4,11 @@ import type { Config } from "@reactive-dot/types"; import { getSmProvider } from "polkadot-api/sm-provider"; import { startFromWorker } from "polkadot-api/smoldot/from-worker"; -const createSmoldotWorker = () => +const smoldotPromise = startFromWorker( new Worker(new URL("polkadot-api/smoldot/worker", import.meta.url), { type: "module", - }); + }), +); const config: Config = { chains: { @@ -15,7 +16,7 @@ const config: Config = { descriptor: polkadot, provider: getSmProvider( import("polkadot-api/chains/polkadot").then(({ chainSpec }) => - startFromWorker(createSmoldotWorker()).addChain({ chainSpec }), + smoldotPromise.addChain({ chainSpec }), ), ), }, @@ -23,7 +24,7 @@ const config: Config = { descriptor: kusama, provider: getSmProvider( import("polkadot-api/chains/ksmcc3").then(({ chainSpec }) => - startFromWorker(createSmoldotWorker()).addChain({ chainSpec }), + smoldotPromise.addChain({ chainSpec }), ), ), }, @@ -31,7 +32,7 @@ const config: Config = { descriptor: westend, provider: getSmProvider( import("polkadot-api/chains/westend2").then(({ chainSpec }) => - startFromWorker(createSmoldotWorker()).addChain({ chainSpec }), + smoldotPromise.addChain({ chainSpec }), ), ), },