svelte-wc-bind
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

svelte-wc-bind

Svelte webcomponent bind is all about enabling two way data binding in svelte web component.

Usage

<!-- Input.svelte -->
<svelte:options tag="my-input" />

<script lang="ts">
  export let value: string;

  function dispatch(e: any) {
    e.target.dispatchEvent(
      new CustomEvent("bind", { detail: e.target.value, composed: true })
    );
  }
</script>

<input type="text" bind:value on:input={dispatch} />
<!-- App.svelte -->
<script lang="ts">
  import { BindValue, bind } from "svelte-wc-bind";
  import "./Input.svelte";

  const name = new BindValue<string>("");
</script>

<my-input use:bind={{ value: name }} />
{$name}
<br />
<my-input value={$name} on:bind={(e) => (name.value = e.detail)} />
<br />
<button on:click={() => (name.value = "Updated Value")}> Update Value </button>

Readme

Keywords

none

Package Sidebar

Install

npm i svelte-wc-bind

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

7.76 kB

Total Files

15

Last publish

Collaborators

  • elmdary