pinia-class-store
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

Class Style Store for pinia

inspired by vuex-class-modules

Install

pnpm add pinia-class-store

Usage

//define Store
import {useStore} from 'pinia-class-store'

class TestStore {
    //state
    hello = "INIT"

    //getters
    get helloMe() {
        return this.hello + "me"
    }

    //actions
    changeHello() {
        this.hello = "hello"
    }

    async asyncHello() {
        await new Promise(resolve => setTimeout(resolve, 1000))
        this.changeHello()
    }
}

setActivePinia(createPinia())
//use store
const store = useStore(TestStore)
//access store like normal class
console.log(store.hello)
await store.asyncHello()
console.log(store.helloMe)

//If you want name it
export const useAnotherTestStore = useStore.bind(undefined, TestStore, "another_name")

License - MIT

I would thank you if you give this a star.

Readme

Keywords

Package Sidebar

Install

npm i pinia-class-store

Weekly Downloads

22

Version

1.1.3

License

MIT

Unpacked Size

5.57 kB

Total Files

6

Last publish

Collaborators

  • wayzer