Open artm opened 6 months ago
A workaround for now:
<script>
// automerge
import { Repo } from "@automerge/automerge-repo";
import { IndexedDBStorageAdapter } from "@automerge/automerge-repo-storage-indexeddb";
import { document, setContextRepo } from "@automerge/automerge-repo-svelte-store";
// own stuff
import ActualComponent from "$lib/components/ActualComponent.svelte";
setContextRepo(
new Repo({
storage: new IndexedDBStorageAdapter(),
network: [],
}),
);
const docHandle = repo.find( URL_GOT_ELSEWHERE );
</script>
{#await docHandle.whenReady()}
<div>Loading...</div>
{:then _} <!-- the async value of whenReady doesn't matter -->
<!-- I guess the documents are cached in the repo so now the docHandle inside the store will be ready right away -->
{@const doc = document( URL_GOT_ELSEWHERE )}
<!-- ActualComponent may assume doc (the store) is ready and $doc is not undefined -->
<ActualComponent {doc} />
{/await}
The automerge svelte store hides the doc handle so there is no way to do something like
I'm not sure what makes sense API-wise, maybe just expose the doc handle on the object returned from
document
, so the first line would be something like: