Socket
Socket
Sign inDemoInstall

vue-recomputed-async

Package Overview
Dependencies
27
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue-recomputed-async

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


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

vue-recomputed-async

NPM version

Vue.js extended computed composable with async, initial state & 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():

Featurecomputed()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

npm i vue-recomputed-async

Example Usage:

<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 composable from @vueuse/core package the hood, you can override the options

Return object:
FieldDescription
refresh()a function that rexecute the evaluation callback function to refresh the computed value
dataa reactive object that holds the the value returned the callback function, if the callback failed or still evaluation, it holds the initial value provided
loadingreturns true if the callback function is still evaluating

Keywords

FAQs

Last updated on 02 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc