# rx-thunk-subject

> thunk subject

Latest version **2.0.2** (published 2017-12-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install rx-thunk-subject
pnpm add rx-thunk-subject
yarn add rx-thunk-subject
bun add rx-thunk-subject
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2017-12-08 |
| First published | 2017-10-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Rafael Salguero Iturrios |
| Maintainers | rafaelsalguero |

## Links

- npm: https://www.npmjs.com/package/rx-thunk-subject
- npm.io page: https://npm.io/package/rx-thunk-subject

## Dependencies (2)

- [rxjs](https://npm.io/package/rxjs.md) ^5.4.3
- [expect](https://npm.io/package/expect.md) ^21.2.1

## Recent versions

- 2.0.2 (latest) — 2017-12-08
- 2.0.1 — 2017-12-08
- 2.0.0 — 2017-12-08
- 1.0.8 — 2017-10-26
- 1.0.7 — 2017-10-26
- 1.0.6 — 2017-10-24
- 1.0.5 — 2017-10-24
- 1.0.4 — 2017-10-20
- 1.0.3 — 2017-10-20
- 1.0.0 — 2017-10-17

## README

# rx-thunk-subject
An rx subject from an async thunk.
- The thunk is not executed until the first subscription is done
- The value can be invalidated thus refreshing existing subscribers values
- Useful for managing changing values from the server
- Subscribers only need to manage sync values

## Create a `ThunkSubject` from an async thunk
```js
async function query() : Promise<Data> {
    return fetch("/api/myquery");
}

//The query function will not be executed until the first subscribe call
const data = new ThunkSubject(query);
```

## Subscribe to your data
```js
function handleData(value: Data) {
    //handle your data.
}

//The query function is called, handleData gets the query promise
data.subscribe(handleData)

...
//Other handler receives the last thunk value, the query function is not called
data.subscribe(otherHandler);
```

## Refresh your data
```js
//The query function is called if there are any subscribers, all subscribers get the new value
//If there isn't any subscribers, the function is called on the next subscription
data.invalidate();
```

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