diff --git a/templates/ui-frameworks/svelte/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{pascal_case collection_name}}.svelte.hbs b/templates/ui-frameworks/svelte/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{pascal_case collection_name}}.svelte.hbs index 5069f8c28..84c842111 100644 --- a/templates/ui-frameworks/svelte/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{pascal_case collection_name}}.svelte.hbs +++ b/templates/ui-frameworks/svelte/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{pascal_case collection_name}}.svelte.hbs @@ -11,11 +11,12 @@ import type { HolochainError, } from '@holochain/client'; import { SignalType } from '@holochain/client' -import { clientContext } from '../../contexts'; +import { type ClientContext, clientContext } from '../../contexts'; import {{pascal_case referenceable.name}}Detail from './{{pascal_case referenceable.name}}Detail.svelte'; import type { {{pascal_case coordinator_zome_manifest.name}}Signal } from './types'; -const client: AppClient = (getContext(clientContext) as any).getClient(); +let client: AppClient; +const appClientContext = getContext(clientContext); let hashes: Array<{{referenceable.hash_type}}> = []; let loading = false; @@ -32,6 +33,7 @@ onMount(async () => { throw new Error(`The author input is required for the {{pascal_case collection_name}} element`); } {{/if}} + client = await appClientContext.getClient(); await fetch{{pascal_case (plural referenceable.name)}}(); client.on('signal', signal => { if (!(SignalType.App in signal)) return; diff --git a/templates/ui-frameworks/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/Create{{pascal_case entry_type.name}}.svelte.hbs b/templates/ui-frameworks/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/Create{{pascal_case entry_type.name}}.svelte.hbs index 65a4139e3..a73ccb42a 100644 --- a/templates/ui-frameworks/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/Create{{pascal_case entry_type.name}}.svelte.hbs +++ b/templates/ui-frameworks/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/Create{{pascal_case entry_type.name}}.svelte.hbs @@ -1,7 +1,7 @@
diff --git "a/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.svelte{{\302\241if}}.hbs" "b/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.svelte{{\302\241if}}.hbs" index 9aa119cc3..377df8431 100644 --- "a/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.svelte{{\302\241if}}.hbs" +++ "b/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.svelte{{\302\241if}}.hbs" @@ -11,11 +11,12 @@ import type { HolochainError, } from '@holochain/client'; import { SignalType } from '@holochain/client'; -import { clientContext } from '../../contexts'; +import { type ClientContext, clientContext } from '../../contexts'; import {{pascal_case from_referenceable.name}}Detail from './{{pascal_case from_referenceable.name}}Detail.svelte'; import type { {{pascal_case coordinator_zome_manifest.name}}Signal } from './types'; -const client: AppClient = (getContext(clientContext) as any).getClient(); +let client: AppClient; +const appClientContext = getContext(clientContext); let hashes: Array<{{from_referenceable.hash_type}}> | undefined; let loading = false; @@ -32,6 +33,7 @@ onMount(async () => { try { loading = true; + client = await appClientContext.getClient(); const links: Array = await client.callZome({ role_name: '{{dna_role_name}}', zome_name: '{{snake_case coordinator_zome_manifest.name}}', diff --git "a/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}}.svelte{{\302\241if}}.hbs" "b/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}}.svelte{{\302\241if}}.hbs" index f7ae2c163..636126d13 100644 --- "a/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}}.svelte{{\302\241if}}.hbs" +++ "b/templates/ui-frameworks/svelte/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}}.svelte{{\302\241if}}.hbs" @@ -11,11 +11,12 @@ import type { HolochainError, } from '@holochain/client'; import { SignalType } from '@holochain/client'; -import { clientContext } from '../../contexts'; +import { type ClientContext, clientContext } from '../../contexts'; import {{pascal_case to_referenceable.name}}Detail from './{{pascal_case to_referenceable.name}}Detail.svelte'; import type { {{pascal_case coordinator_zome_manifest.name}}Signal } from './types'; -const client: AppClient = (getContext(clientContext) as any).getClient(); +let client: AppClient; +const appClientContext = getContext(clientContext); let hashes: Array<{{to_referenceable.hash_type}}> | undefined; let loading = false; @@ -29,7 +30,7 @@ onMount(async () => { if (!{{camel_case from_referenceable.singular_arg}}) { throw new Error(`The {{camel_case from_referenceable.singular_arg}} input is required for the {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}} element`); } - + client = await appClientContext.getClient(); try { loading = true; const links: Array = await client.callZome({ diff --git a/templates/ui-frameworks/svelte/web-app/ui/package.json.hbs b/templates/ui-frameworks/svelte/web-app/ui/package.json.hbs index c017f761c..a401f4047 100644 --- a/templates/ui-frameworks/svelte/web-app/ui/package.json.hbs +++ b/templates/ui-frameworks/svelte/web-app/ui/package.json.hbs @@ -18,7 +18,7 @@ "@msgpack/msgpack": "^2.8.0" }, "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^2.5.3", + "@sveltejs/vite-plugin-svelte": "^3.1.2", "@tsconfig/svelte": "^3.0.0", "bestzip": "^2.2.1", "rimraf": "^5.0.10", diff --git a/templates/ui-frameworks/svelte/web-app/ui/src/App.svelte.hbs b/templates/ui-frameworks/svelte/web-app/ui/src/App.svelte.hbs index e2748fd01..81fc46309 100644 --- a/templates/ui-frameworks/svelte/web-app/ui/src/App.svelte.hbs +++ b/templates/ui-frameworks/svelte/web-app/ui/src/App.svelte.hbs @@ -7,7 +7,7 @@ {{/if}} import logo from './assets/holochainLogo.svg'; - import { clientContext } from './contexts'; + import { type ClientContext, clientContext } from './contexts'; {{#if holo_enabled}} const IS_HOLO = ['true', '1', 't'].includes(import.meta.env.VITE_APP_IS_HOLO?.toLowerCase()) @@ -21,6 +21,15 @@ let error: HolochainError | undefined; let loading = false; + const appClientContext = { + getClient: async () => { + if (!client) { + client = await AppWebsocket.connect(); + } + return client; + }, + }; + onMount(async () => { {{#if holo_enabled}} try { @@ -37,7 +46,7 @@ }); (client as WebSdk).signUp({ cancellable: false }); } else { - client = await AppWebsocket.connect(); + client = await appClientContext.getClient(); loading = false; } } catch (e) { @@ -48,7 +57,7 @@ {{else}} try { loading = true; - client = await AppWebsocket.connect(); + client = await appClientContext.getClient(); } catch (e) { error = e as HolochainError; } finally { @@ -57,9 +66,7 @@ {{/if}} }); - setContext(clientContext, { - getClient: () => client, - }); + setContext(clientContext, appClientContext);
diff --git a/templates/ui-frameworks/svelte/web-app/ui/src/contexts.ts.hbs b/templates/ui-frameworks/svelte/web-app/ui/src/contexts.ts.hbs index 9f41a2624..988b48279 100644 --- a/templates/ui-frameworks/svelte/web-app/ui/src/contexts.ts.hbs +++ b/templates/ui-frameworks/svelte/web-app/ui/src/contexts.ts.hbs @@ -1 +1,7 @@ -export const clientContext = 'AppClient'; \ No newline at end of file +import { type AppClient } from "@holochain/client"; + +export const clientContext = "AppClient"; + +export type ClientContext = { + getClient: () => Promise; +};