Gathering detailed insights and metrics for concent-plugin-loading
Gathering detailed insights and metrics for concent-plugin-loading
Gathering detailed insights and metrics for concent-plugin-loading
Gathering detailed insights and metrics for concent-plugin-loading
npm install concent-plugin-loading
Typescript
Module System
Node Version
NPM Version
65.1
Supply Chain
91.5
Quality
76.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
10,564
Last Day
4
Last Week
14
Last Month
166
Last Year
2,161
3 Stars
45 Commits
1 Forks
2 Watchers
1 Branches
1 Contributors
Updated on Sep 01, 2021
Minified
Minified + Gzipped
Latest Version
2.0.5
Package Id
concent-plugin-loading@2.0.5
Unpacked Size
15.68 kB
Size
5.25 kB
File Count
5
NPM Version
6.14.13
Node Version
14.17.0
Cumulative downloads
Total Downloads
Last Day
100%
4
Compared to previous day
Last Week
-36.4%
14
Compared to previous week
Last Month
-21.7%
166
Compared to previous month
Last Year
97%
2,161
Compared to previous year
1
一个轻松控制concent应用loading状态的插件
在启动concent的时候配置好插件,就可以使用了
1import { run } from 'concent'; 2import loadingPlugin from 'concent-plugin-loading'; 3import student from './models/student'; 4import product from './models/product'; 5 6run( 7 { student, product }, 8 { 9 //配置loading插件 10 plugins:[loadingPlugin], 11 } 12); 13
读取loading值,loadingPlugin
会注册自己的模块loading
,该模块的key就是其他concent
里所有模块的名字,值就是这个模块loading值,true表示该模块正在调用异步函数,
false表示调用异步函数函数结束
1import { register } from 'concent'; 2import React, { Component } from 'react'; 3 4@register({ 5 module: 'student', 6 //连接loading模块,关心student模块的loading状态 7 connect:{'loading':['student']}, 8 //如关心某个具体的方法loading状态,可以写为 9 //connect:{'loading':['student/m1', 'student/m2']}, 10}) 11export default class StudentPanel extends Component { 12 13 changeName = () => { 14 this.ctx.dispatch('handleStudentNameChange', this.state.tmpName); 15 } 16 17 render() { 18 const { name, tmpName } = this.state; 19 const loading = this.ctx.connectedState.loading.student; 20 console.log('@@@ StudentPanel', loading); 21 22 return ( 23 <div> 24 {loading? '提交中':''} 25 <p>name: {name}</p> 26 <input value={tmpName} onChange={this.ctx.sync('tmpName')} /> 27 <button onClick={this.changeName}>修改名字</button> 28 </div> 29 ); 30 } 31} 32
reducer定义
1// code in models/student/reducer.js 2const sleep = (ms = 3000)=> new Promise(resolve=> setTimeout(resolve, ms)); 3 4export async function trackNameChangeEvent(){ 5 console.log('trackNameChangeEvent'); 6} 7 8export async function updateStudentName({payload:name}){ 9 await sleep();//模拟请求后端更新name 10 return {name}; 11} 12 13export async function handleStudentNameChange({dispatch, payload:name}){ 14 await dispatch('updateStudentName', name); 15 await dispatch('trackNameChangeEvent', name); 16}
仅当你的调用的reducer函数为async函数或者generator函数时,loading插件会改变各个模块loading的值
对同一个模块并发起多个dispatch时,只有全部函数执行结束loading才会变成false
changeName = () => {
//假设student模块存在以下3个reducer函数,这里同时调了3次
//全部结束时,student模块的loading才会写为false
this.ctx.dispatch('handleStudentNameChange', this.state.tmpName);
this.ctx.dispatch('handleStudentNameChange2', this.state.tmpName);
this.ctx.dispatch('handleStudentNameChange3', this.state.tmpName);
}
在一个模块的reducer函数里,调用了另外模块的reducer函数,那个模块的loading值也会经历变成true然后变成false的过程
1// code in models/student/reducer.js 2const sleep = (ms = 3000)=> new Promise(resolve=> setTimeout(resolve, ms)); 3 4export async function updateStudentName({payload:name, dispatch}){ 5 await sleep();//模拟请求后端更新name 6 7 //这里会触发loading插件去改写product模块的loading值 8 await dispatch('product/fetchProductList'); 9 return {name}; 10}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
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
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-05-19
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