redux-svelte-store
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

redux-svelte-store

Simple wrapper to convert a redux store to a synthetic svelte readable store that conforms to the svelte store contract.

Install

npm install redux-svelte-store

Usage

Basic usage

<script>
  import toReadable from 'redux-svelte-store'
  const svelteStore = toReaable(reduxStore)

  svelteStore.subscribe(state => { /* ... */ })
</script>

<!-- now you can use $ prefix-->
<h1>{$svelteStore.prop}</h1>

Use selector

Pass a selector function as second argument.

const foobarStore = toReaable(reduxStore, (state) => {
  return state.foobar
})

// listener will only be notified when `state.foobar` changed
foobarStore.subscribe(foobar => { /* ... */ })

Also support string key paths as arguments.

/**
 * Example the app state is of shape:
 * {
 *   foo: {
 *     bar: "zoo"
 *   }
 * }
 */

const zooStore = toReaable(reduxStore, "foo", "bar")
console.log($zooStore) // "zoo"

Readme

Keywords

none

Package Sidebar

Install

npm i redux-svelte-store

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

4.67 kB

Total Files

4

Last publish

Collaborators

  • hackape