0.1.0 • Published 9 months ago
@dot357/simpstore v0.1.0
SimpStore
A simple, framework-agnostic state management library inspired by Pinia.
Installation
npm install simpstore
Usage
import { defineStore } from 'simpstore'
// Define a store
const useCounterStore = defineStore('counter', () => {
let count = 0
function increment() {
count++
}
return { count, increment }
}, {
persist: true // optional: enables localStorage persistence
})
// Use the store
const counter = useCounterStore()
counter.increment()
console.log(counter.count)
// Reset store to initial state
counter.$reset()
Features
- 🎯 Framework agnostic
- 📦 Lightweight
- 🔄 State persistence
- 💪 TypeScript support
- 🏭 Singleton stores
- 🔄 Reset capability
API
defineStore
Creates a new store with the given options.
defineStore(id: string, setup: () => T, options?: { persist?: boolean }): () => Store
Store Instance Methods
$reset()
: Reset the store to its initial state
License
MIT
0.1.0
9 months ago