1.1.1 • Published 2 years ago

pinia-store-decorators v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

pinia-store-decorators

Typescript Decorators to define Pinia stores.

Installation

# npm
npm install -D pinia-store-decorators

# yarn
yarn add -D pinia-store-decorators

# pnpm
pnpm add -D pinia-store-decorators

Usage

Defining a Store

import { defineStore } from 'pinia';
import { Store, createOptions } from 'pinia-store-decorators';

@Store
class MainStore {
    public counter = 0;

    public name = 'Eduardo';

    public get doubleCount(): number {
        return this.counter * 2;
    }

    public get doubleCountPlusOne(): number {
        return this.counter * 2 + 1;
    }

    public reset(): void {
        this.counter = 0;
    }
}

export const useMainStore = defineStore(createOptions('main', MainStore));

Equivalent to the code below

import { defineStore } from 'pinia';

const mainStore = {
    state: () => ({
        counter: 0,
        name: 'Eduardo',
    }),
    getters: {
        doubleCount(): number {
            return this.counter * 2;
        },
        doubleCountPlusOne(): number {
            return this.counter * 2 + 1;
        },
    },
    actions: {
        reset(): void {
            this.counter = 0;
        },
    },
};

export const useMainStore = defineStore('main', mainStore);

WIP...

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago