Gathering detailed insights and metrics for @xunlei/vuex-connector
Gathering detailed insights and metrics for @xunlei/vuex-connector
Gathering detailed insights and metrics for @xunlei/vuex-connector
Gathering detailed insights and metrics for @xunlei/vuex-connector
基于 Vue 生态实现的 Vuex store connector,借鉴 React 容器组件(Smart/Container Components)和展示组件(Dumb/Presentational Components)的模式,demo地址:
npm install @xunlei/vuex-connector
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
62 Stars
35 Commits
4 Forks
9 Watchers
1 Branches
6 Contributors
Updated on May 18, 2022
Latest Version
0.3.2
Package Id
@xunlei/vuex-connector@0.3.2
Unpacked Size
12.04 kB
Size
4.99 kB
File Count
5
NPM Version
5.5.1
Node Version
8.9.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
基于 Vue 生态实现的 Vuex store connector,借鉴 React 容器组件和展示组件的模式。在 迅雷前端 掘金专栏 发表的 致敬 React: 为 Vue 引入容器组件和展示组件 详细说明了为什么我们应该使用容器组件,以及如何在 Vue 中编写容器组件。
1npm install @xunlei/vuex-connector
store/index.js
1import VuexConnector from '@xunlei/vuex-connector'; 2 3// 将store传入connecor进行连接 4export const connector = new VuexConnector(store);
containers/CounterContainer.vue
1import Counter from '@/components/Counter'; 2import {connector} from '@/store'; 3 4export default connector.connect({ 5 mapStateToProps: { 6 // total是Counter接收的prop之一 7 total: state => state.count, 8 }, 9 mapCommitToProps: { 10 // onIncrease,onDecrease都是是Counter接收的prop 11 onIncrease: 'increment', 12 onDecrease: 'decrement', 13 }, 14})(Counter);
App.vue
1<template> 2 <div> 3 <h1>容器组件-展示组件模式</h1> 4 <CounterContainer/> 5 </div> 6</template> 7 8<script lang="ts"> 9import CounterContainer from '@/containers/CounterContainer' 10 11export default { 12 components: { 13 CounterContainer 14 } 15} 16</script>
class
VuexConnector构造函数需要传入一个 Vuex store 的实例
typescript 定义
1connect({ 2 mapStateToProps?, 3 mapGettersToProps?, 4 mapDispatchToProps?, 5 mapCommitToProps? 6}): (Component: typeof Vue) => FunctionalComponentOptions<any>
connect 函数根据传入配置,生成一个高阶函数,高阶函数传入一个要连接的展示组件,即可生成最终的容器组件。
1{ 2 // state 指的是 vuex store 的state 3 // props 指的是调用容器组件时传来的所有的props,是个对象 4 [prop: string]: (state, props) => anyState; 5}
例子:
1connector.connect({ 2 mapStateToProps: { 3 userId: state => state.userId, 4 }, 5})(Counter);
1{ 2 [prop: string]: (getters, props) => anyGetter; 3}
例子:
1connector.connect({ 2 mapGettersToProps: { 3 isLogin: getters => getters.isLogin, 4 }, 5})(Counter);
1{ 2 [prop: string]: action: string; 3}
例子:
1connector.connect({ 2 mapDispatchToProps: { 3 // onIncrease,onDecrease都是是Counter接收的prop 4 onIncrease: 'increment', 5 onDecrease: 'decrement', 6 }, 7})(Counter);
1{ 2 [prop: string]: mutation: string; 3}
例子:
1connector.connect({ 2 mapCommitToProps: { 3 // onIncrease,onDecrease都是是Counter接收的prop 4 onIncrease: 'increment', 5 onDecrease: 'decrement', 6 }, 7})(Counter);
Copyright (c) 2017 XunleiF2E
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/28 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
59 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More