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

0.1.1 • Public • Published

svelte-writable-array-store

Writable array store in Svelte.

Adds Array methods to a Svelte store, including: push, pop, shift, unshift, splice, sort, reverse and copyWithin.

Install

npm install svelte-writable-array-store

Usage

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

License

MIT

Package Sidebar

Install

npm i svelte-writable-array-store

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

16 kB

Total Files

8

Last publish

Collaborators

  • sophiamersmann