vtate

所属分类:其他
开发工具:TypeScript
文件大小:0KB
下载次数:0
上传日期:2023-01-06 12:24:21
上 传 者sh-1993
说明:  去中心化状态管理工具,
(Decentralized state management tool,)

文件列表:
.editorconfig (146, 2020-08-04)
.eslintignore (3, 2020-08-04)
.eslintrc.js (617, 2020-08-04)
.prettierrc.js (195, 2020-08-04)
LICENSE (1065, 2020-08-04)
commitlint.config.js (69, 2020-08-04)
package.json (1809, 2020-08-04)
src/ (0, 2020-08-04)
src/index.ts (3090, 2020-08-04)
tsconfig.json (469, 2020-08-04)
yarn.lock (283375, 2020-08-04)

# 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 # Install ```bash yarn add vtate ``` # Usage ```jsx // 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 (
username: {userProfile.username}
) } } } ``` # License MIT

近期下载者

相关文件


收藏者