hyper-svelte-component

1.1.0 • Public • Published

Hyper-Svelte-Component

A Svelte <Component /> for managing Hyperdrives using the dat-sdk.

You can also bind Hypercores to the component.

Why

When using the dat SDK you've got to close it when you're done with the SDK, and keeping track of the close is a bit of a pain. So I bundled the creation of the hyperdrive and the close function into a Svelte component. Whenever the component is destroyed or the window.unloads the await close() function for the SDK's Hyperdrive will be closed. So you don't have to worry about it.

Usage

All you do is pass in an instance of the SDK and bind the componet's output what you want Hyperdrive to be called (if you wan to rename it, or have multiple SDK instances, to simulate many peers on one device).

import HyperComponent from "hyper-svelte-component";

<HyperComponent {SDK} bind:Hyperdrive={makeDrives} bind:Hypercore={makeCores} />
<HyperComponent {SDK} bind:Hyperdrive={makeDriveCopies} />

const original = makeDrives("original-drive-name")
await original.ready()
// ... more Hyperdrive moves afterward

// To simulate two peers in the same browser, you'll need another SDK instance
const copy = makeDriveCopies(original.key)

See also

Svelte

dat-sdk

Hyperdrives

Package Sidebar

Install

npm i hyper-svelte-component

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

21.4 kB

Total Files

6

Last publish

Collaborators

  • douganderson444