# mobx-loading

> 参考了 dva-loading 的思路，基于 mobx 实现了用于监控各个 mode 和 effect 加载状态的组件

Latest version **1.2.5** (published 2019-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install mobx-loading
pnpm add mobx-loading
yarn add mobx-loading
bun add mobx-loading
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.5 |
| Published | 2019-06-19 |
| First published | 2019-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | niqingyang |
| Maintainers | niqingyang |
| Keywords | mobx, loading, promise |

## Links

- npm: https://www.npmjs.com/package/mobx-loading
- Repository: https://github.com/niqingyang/mobx-loading
- Homepage: https://github.com/niqingyang/mobx-loading#readme
- Issues: https://github.com/niqingyang/mobx-loading/issues
- npm.io page: https://npm.io/package/mobx-loading

## Dependencies (3)

- [mobx](https://npm.io/package/mobx.md) ^5.9.4
- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.4.4
- [@babel/plugin-proposal-decorators](https://npm.io/package/@babel/plugin-proposal-decorators.md) ^7.4.4

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.2.5 (latest) — 2019-06-19
- 1.2.4 — 2019-06-19
- 1.2.3 — 2019-06-14
- 1.2.2 — 2019-06-03
- 1.2.1 — 2019-06-03
- 1.2.0 — 2019-06-03
- 1.1.9 — 2019-05-30
- 1.1.8 — 2019-05-30
- 1.1.7 — 2019-05-28
- 1.1.6 — 2019-05-27
- 1.1.5 — 2019-05-27
- 1.1.4 — 2019-05-26
- 1.1.3 — 2019-05-26
- 1.1.2 — 2019-05-26
- 1.1.1 — 2019-05-26
- … 7 more at https://npm.io/package/mobx-loading/versions

## README

# mobx-loading


参考了 dva-loading 的思路，基于 mobx 实现了用于监控各个 mode 和 effect 加载状态的组件


## Installation

```js
npm install --save mobx-loading
```


## Usage

### 1.使用装饰器监控相关的 action

```js
import {action} from 'mobx'
import {loading} from 'mobx-loading'

class User {
    
    // .... some things
    
    @loading
    @action
    fetchUser = () => {
        // ...do some things
        // 返回一个 Promise 对象
        return Promise;
    }
    
    @loading
    @action
    fetchList = () => {
        // ...do some things
        // 也可以不返回 Promise 对象
    }
    
    @loading('user')
    @action
    fetchA = () => {
        // ...do some things
        // 返回一个 Promise 对象
        return Promise;
    }
    
    @loading('user/a')
    @action
    fetchB = () => {
        // ...do some things
        // 返回一个 Promise 对象
        return Promise;
    }
    
    @loading(['user', 'c'])
    @action
    fetchC = () => {
        // ...do some things
        // 返回一个 Promise 对象
        return Promise;
    }
    
    // .... some things
}
```

### 2.放入 store 中


```js
import {loadingStore} from 'mobx-loading'

// ....

store.loading = loadingStore;

ReactDOM.render(
    <Provider {...store}>
        <App/>
    </Provider>,
    document.getElementById('root')
);
```

### 3.React 组件中应用

```js
import {inject} from 'mobx-react';

@inject(({loading}) => {
    featchUserLoading: loading.actions['user/fetchUser'],
    featchListLoading: loading.actions['user/fetchList'],
    featchALoading: loading.actions['user/a'],
    featchBLoading: loading.actions['user/b'],
    featchCLoading: loading.actions['user/c'],
    userLoading: loading.models.user,
    globalLoading: loading.global
})
class XXX extends React.Component {
    // ....
}
```


## License

[MIT](http://opensource.org/licenses/MIT) Copyright (c) 2019

---
_Source: https://npm.io/package/mobx-loading · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
