simple-store-svelte
v1.0.6
Published
Simpler store using setters and getters for Svelte.
Downloads
360
Maintainers
Readme
simple-store-svelte
A drop in replacement for svelte/store
which uses setters/getters to write/read the store's value.
Now you can do:
// stores.js
import { writable } from 'simple-store-svelte'
const store = writable(null)
store.value = 'Hello world!'
const { value } = store
console.log(value) // 'new value!'
Instead of:
// stores.js
import { writable, get } from 'svelte/store'
const store = writable(null)
store.set('Hello world!')
const value = get(store)
console.log(value) // 'new value!'
Other than the example above, the store is identical as the Svelte one, which means you can use it as you always did.
<!-- App.svelte -->
<script>
import { store } from './stores.js'
$store = 'Goodbye world!'
</script>
<div>
{ $store }
<!-- null -->
<!-- Hello world! -->
<!-- Goodbye world! -->
</div>