loading-watch-mobx

watch loading by Reactive style

Usage no npm install needed!

<script type="module">
  import loadingWatchMobx from 'https://cdn.skypack.dev/loading-watch-mobx';
</script>

README

安装

npm install loading-watch-mobx --save

使用

model

import {loadingWatch} from 'loading-watch-mobx'; import {observable} from 'mobx'; const data = observable(new class { @loadingWatch async getList() { return await request(...); } });

component

import {loading} from 'loading-watch-mobx';
import dataModel from './model';
@observer
class Com extends React.Component {
    componentDidMount() {
        dataModel.getList();
    }
    render() {
        return <div>
            {loading.get(dataModel, 'getList') ? 'loading...' : 'already loading'}
        </div>
    }
}