Skip to content

svelte: provide a way to await the document becoming ready #342

Open
@artm

Description

The automerge svelte store hides the doc handle so there is no way to do something like

<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 doc = document( URL_GOT_ELSEWHERE );
</script>

<!-- wait for the document to become ready, imaginary method by analogy with DocHandle -->
{#await doc.whenReady()}
    <div>Loading...</div>
{:then _}
    <!-- ActualComponent may assume doc (the store) is ready and $doc is not undefined -->
    <ActualComponent {doc} />
{/await}

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:

{#await doc.handle().whenReady()}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions