# request-registry-mobx

> RequestRegistryMobx is a helper to use RequestRegistry ajax endpoints with mobx.

Latest version **0.12.2** (published 2021-01-18) · 0 weekly downloads

## Install

```sh
npm install request-registry-mobx
pnpm add request-registry-mobx
yarn add request-registry-mobx
bun add request-registry-mobx
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.2 |
| Published | 2021-01-18 |
| First published | 2019-05-23 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 59.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | namicsorg, ernscht, jantimon, smollweide, janbiasi, tamara027, zidizei, danielkochde, reeko, jegli, dominic.modalek |

## Links

- npm: https://www.npmjs.com/package/request-registry-mobx
- npm.io page: https://npm.io/package/request-registry-mobx

## Recent versions

- 0.12.2 (latest) — 2021-01-18
- 0.12.1 — 2020-11-10
- 0.12.0 — 2020-06-15
- 0.11.2 — 2020-03-20
- 0.11.1 — 2020-02-19
- 0.11.0 — 2019-12-18
- 0.10.1 — 2019-10-31
- 0.10.0 — 2019-10-31
- 0.9.2 — 2019-10-25
- 0.9.0 — 2019-10-24
- 0.8.0 — 2019-08-26
- 0.7.1 — 2019-06-20
- 0.7.0 — 2019-06-17
- 0.5.0 — 2019-06-14
- 0.4.0 — 2019-06-09
- … 4 more at https://npm.io/package/request-registry-mobx/versions

## README

# Request Registry Mobx

RequestRegistryMobx is a helper to use RequestRegistry ajax endpoints with mobx.

Features:

-   **lazy loading:** ajax requests will be done only if the endpoint is actively observed
-   **auto refresh:** if a cache gets outdated and the endpoint is still observed it will be executed again to update the state with the latest information
-   **garbage collection:** once all observers stop observing the cache will be freed

## Getting started

```
npm install --save request-registry registry-request-mobx
```

## Api

### createObservableEndpoint

The `createObservableEndpoint` can be used to load ajax data and handling the loading state in the same component:

```js
const observedUserEndpoint = createObservableEndpoint(userEndpoint, {
    id: '1',
});
autorun(() => {
    if (observedUserEndpoint.hasData) {
        console.log(observedUserEndpoint.data);
    }
});
```

The useGetEndPoint can also be used inside a store:

```js
class Store {
    userEndpoint = createObservableEndpoint(userEndpoint);

    setUserId(id: string) {
        this.userEndpoint.setKeys({ id: string });
    }

    get userName() {
        return this.userEndpoint.hasData ? this.userEndpoint.name : undefined;
    }
}

const store = new Store();
store.setUserId(1);

autorun(() => {
    console.log(store.userName);
});
```

### endpointState

The return value of `createObservableEndpoint` can have the following states:

-   `state: 'LOADING'`: The endpoint is executed the first time or after an error occured.
-   `state: 'UPDATING'`: The endpoint is executed altough data have already been loaded before.
-   `state: 'DONE'`: The endpoint is done executing.
-   `state: 'ERROR'`: The endpoint is done executing but received an error

## License

[MIT license](http://opensource.org/licenses/MIT)

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