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

vtate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vtate

A type-safe decentralized state management tool for vue3.

  • 0.0.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Vtate

A type-safe decentralized state management tool for vue3.

Motivation

With the use of Composition API, business logic and state are gradually decentralized. The centralized state management tool (vuex) will become a burden. On the other hand, many people are now using Vue3's reactive-api to build stores, which reduced a lot of boilerplate code. But too flexible code can easily bring disasters in code maintainability and readability.

Therefore, I think there should be a tool to constrain the process of creating stores. It should combine the advantages of vue3 and vuex, be flexible, and have rules to follow.

Features

  • Create store easily
  • Modify data by dispatching an action

Usage

// userProfile.js
import { createState } from 'vtate'

export const userProfile = createState({
  name: 'userInfo',
  initialState: {
    username: 'futengda',
  },
  reducers: {
    updateName: (state, payload) => {
      state.username = payload
    },
  },
})

// main.js
import { useDispatch } from 'vtate'
import { userProfile } from './userProfile'

export default {
  setup() {
    const [dispatch, actions] = useDispatch(userProfile)

    function changeUserName() {
      // directly use string as action-name
      dispatch('updateName', 'fxxjdedd')

      // or, use actions.x to get action-name
      dispatch(actions.updateName, 'fxxjdedd')

      // or,directly modify reactive state
      userProfile.username = 'fxxjdedd'
    }

    return () => {
      return (
        <div>
          username: {userProfile.username} <br/>
          <button onClick={changeUserName}>click</button>
        </div>
      )
    }
  }
}

License

MIT

FAQs

Package last updated on 04 Aug 2020

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