0.0.3 • Published 5 years ago

vuex-mask v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

vuex-mask

usage

@Module
export class Arsenal extends VuexMask {
    guns: Gun[] = [];
    budget = 5000;
    
    get countGuns() {
        return this.guns.length;
    }
    
    @Mutation
    addGun(gun: Gun) {
        this.guns.push(gun);
    }

	@Action
    async requestGunFromStore(gun: Gun) {
        if (gun.cost < this.budget) {
            //mutation for setter
            this.budget -= gun.cost;
            await this.gunDelivery();
            this.addGun(gun);
            return true;
        }
    
        return false;
    }

    gunDelivery() {
        return new Promise((resolve) => {
            setTimeout(resolve, 100);
        });
    }
}

// Store - Vuex instance
export default new Arsenal('arsenal', Store);