michaelolof / vuex-class-component

A Type Safe Vuex Module or Store Using ES6 Classes and ES7 Decorators written in TypeScript.
217 stars 21 forks source link

Reduce boilerplate in store #34

Closed datdefboi closed 5 years ago

datdefboi commented 5 years ago
    private _storages: IStorage[] = [];
    get storages() {
        return this._storages
    }
    @mutation add_storage(payload: IStorage) {
        this._storages.push(payload);
    }

    private _systemStorage?: IStorage = undefined;
    get systemStorage() {
        return this._systemStorage
    }
    @mutation change_systemStorage(payload: IStorage) {
        this._systemStorage = payload;
    }

    private _userFolder: string = "";
    get userFolder() {
        return this._userFolder
    }
    @mutation change_userFolder(payload: string) {
        this._userFolder = payload;
    }

May be we can introduce a new decorator like @managed? There is an example:

@managed systemStorage: IStorage;

or more complex example

@managed((payload, value) => { value.push(payload) }) storages: IStorage[];

and then just get\set it

this.storages = ...
let temp = this.storages
michaelolof commented 5 years ago

The new API addresses the issue of boilerplate in stores.

Thanks for the suggestion.