
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
decorator-loading
Advanced tools
在项目中使用 loading,一般是在组件中用一个变量( 如 isLoading)来保存请求数据时的 loading 状态,请求 api 前将 isLoading 值设置为 true,请求 api 后再将 isLoading 值设置为 false,从而对实现 loading 状态的控制,但是如果很多异步需求都这样做势必会增加冗余代码,而且对 loading 状态的控制与我们的业务完全无关,我们完全可以解耦出来,所以使用装饰器抽离这部分逻辑代码
import loading from "decorator-loading"
class Demo extends React.Component<any, any> {
constructor(props: any) {
super(props)
this.state = {
count: 0
}
}
@loading()
public sendGetDemoReq() {
axios.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
}
public render() {
return (
<div styleName="page-demo">
<h2>hellos 🍺🍺🍺🍺🍺🍺</h2>
<Button onClick={this.sendGetDemoReq} type="primary" style={{ marginTop: '8px' }}>
request
</Button>
{window.isLoading&&<YourLoading />}
</div>
)
}
}
现在支持的是一个全局window参数,所以我们建议你初始化的时候就先把这个参数挂载到window上,当然你如果不想挂载到window上,而是自定义变量(现在还没有支持这个操作),你可以直接copy这个
装饰器代码进行修改
| 参数名 | 值 |
|---|---|
| window.isLoading | false |
module.exports = loading = () => {
return function (
target,
name,
descriptor
) {
let v
return {
enumerable: true,
configurable: true,
get: function () {
if (descriptor) {
v = descriptor.value
}
if (typeof v === 'function') {
return async function () {
window.isLoading = true
try {
await v.apply(this, arguments)
} catch (error) {
// 做一些错误上报之类的处理
throw error;
} finally {
window.isLoading = false
}
}
}
},
set: function (c) {
v = c;
}
}
}
}
如果是你的项目有配置ts需要在tsconfig配置 "experimentalDecorators": true
FAQs
解决页面loading逻辑的复用于业务的解耦
We found that decorator-loading demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.