# vue-recomputed-async

> Vue.js extended computed composable with async, initial state & manual refresh support

Latest version **1.0.3** (published 2022-08-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-recomputed-async
pnpm add vue-recomputed-async
yarn add vue-recomputed-async
bun add vue-recomputed-async
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-08-02 |
| First published | 2022-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ahmed Chakhoum |
| Maintainers | rainxh11 |
| Keywords | vue, compositionapi, vueuse, vue-compositionapi, vuejs, computed, async, reactive, refresh |

## Links

- npm: https://www.npmjs.com/package/vue-recomputed-async
- Homepage: https://github.com/rainxh11/vue-recomputed-async#readme
- Issues: https://github.com/rainxh11/vue-recomputed-async/issues
- npm.io page: https://npm.io/package/vue-recomputed-async

## Dependencies (2)

- [vue-demi](https://npm.io/package/vue-demi.md) ^0.13.6
- [@vueuse/core](https://npm.io/package/@vueuse/core.md) ^8.9.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.0.3 (latest) — 2022-08-02
- 1.0.2 — 2022-08-02
- 1.0.1 — 2022-08-02
- 1.0.0 — 2022-07-17

## README

# vue-recomputed-async
[![NPM version](https://img.shields.io/npm/v/vue-recomputed-async.svg)](https://www.npmjs.com/package/vue-recomputed-async)

Vue.js extended computed composable with async, initial state &amp; manual refresh support
this library aims to provide better code integration by providing a single function that eliminate the need to create and call a fetch function, creating a sperate loading & data objects manually handling the fetch function errors, lazy evualation, providing an initial default state in case of in progress evaluation or failure
### Comparison with regular `computed()` & `vueuse` `computedAsync()`:
|Feature|`computed()`|`computedAsync()`|`recomputedAsync()`|
|-|-|-|-|
|Dependency Tracking & Reactivity|✅|✅|✅|
|Async Support|❌|✅|✅|
|Initial State|❌|✅|✅|
|Lazy Evaluation|❌|✅|✅|
|Evaulation State|❌|✅|✅|
|Manual Re-evaluation|❌|❌|✅|
#### Use cases:
- providing initial data state, while fetching data from API
- ability to refresh the data that might be changed without being tied to any dependecy a normal computed would not be able to react to
# Install
```bash
npm i vue-recomputed-async
```
# Example Usage:
```vue
<template>
    <div>
        <div v-if="peopleLoading">Loading People...</div>
        <div v-for="person in people" :key="person.name">
            {{ person.name }}
        </div>
        <button @click="refreshPeople">Refresh</button>
    </div>
</template>

<script setup>
import { recomputedAsync } from 'vue-recomputed-async';
import { getPeople } from './people-api'

const {
    data: people,
    loading: peopleLoading,
    refresh: refreshPeople,
} = recomputedAsync(async () => {
    return await getPeople()
}, [])
</script>
```

#### The `options` parameter:
Since this package is an extension that uses [`computedAsync`](https://vueuse.org/core/computedasync/) composable from [`@vueuse/core`](https://vueuse.org/) package the hood, you can override the `options`

#### Return object:
|Field|Description|
|-|-|
|`refresh()`| a function that rexecute the evaluation callback function to refresh the computed value |
|`data`| a reactive object that holds the the value returned the callback function, if the callback failed or still evaluation, it holds the initial value provided|
|`loading`| returns `true` if the callback function is still evaluating

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