Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

direct-vuex

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

direct-vuex

Just Vuex with typing. Compatible with the Vue 3 composition API.

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
increased by43.4%
Maintainers
1
Weekly downloads
 
Created
Source

direct-vuex

Just Vuex with typing. Compatible with the Vue 3 composition API.

How to use

Install

First, add direct-vuex to a Vue application:

npm install direct-vuex

Create the store

The store is implemented in the same way as usual (ie. without typing). However, it is necessary to append as const at the end of store and module implementation objects. It will help direct-vuex to better infer types.

Create the store:

import Vue from "vue"
import Vuex from "vuex"
import { createDirectStore } from "direct-vuex"

Vue.use(Vuex)

export default createDirectStore({
  // … store implementation here …
} as const)

The classic Vuex store is still accessible through the store.original property. We need it to initialize the Vue application:

import Vue from "vue"
import store from "./store"

new Vue({
  store: store.original, // Inject the classic Vuex store
  // …
}).$mount("#app")

Use typed wrappers from outside the store

From a component, import the store.

import store from "./store"

Then, the old way to call an action:

store.dispatch("myModule/myAction", myPayload)

… is replaced by the following wrapper:

store.dispatch.myModule.myAction(myPayload)

… which is fully typed.

Typed getters and mutations are accessible the same way:

store.getters.myModule.myGetter;
store.commit.myModule.myMutation(myPayload);

Notice: The underlying Vuex store can be used simultaneously if you wish, through the injected this.$store or store.original.

Limitations

  • Actions can't be declared with the object alternative syntax.

Contribute

With VS Code, our recommanded plugin is:

  • TSLint from Microsoft (ms-vscode.vscode-typescript-tslint-plugin)

Keywords

FAQs

Package last updated on 19 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc