Writable array store in Svelte.
Adds Array methods to a Svelte store, including: push
, pop
, shift
, unshift
, splice
, sort
, reverse
and copyWithin
.
npm install svelte-writable-array-store
Create a store:
import { writableArray } from 'svelte-writable-array-store';
export const arrayStore = writableArray([1, 2, 3, 4, 5]);
Use it:
import { arrayStore } from './whereever';
// exposes all built-in store functions
arrayStore.subscribe(...)
arrayStore.set(...)
arrayStore.update(...)
$arrayStore
// offers additional array methods
arrayStore.push(6, 7, 8) // add elements to the end
arrayStore.pop() // remove last element
arrayStore.shift() // remove first element
arrayStore.unshift(0) // add elements to the beginning
arrayStore.splice(2) // changes the contents of an array
arrayStore.sort() // sort elements
arrayStore.reverse() // reverse elements
arrayStore.copyWithin(1, 2) // shallow copies part of an array to another location in the same array
MIT