
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
vue-call-store
Advanced tools
A Vue & Vuex plugin to simplify tracking API call statuses.
Vue Call Store provides a Vuex module and component methods to make it easy to update API call statuses and keep track of them.
yarn add -D vue-call-store
yarn add -D vuex
# or
npm i -D vue-call-store
npm i -D vuex
import Vuex from 'vuex';
import VueCallStore from 'vue-call-store';
/**
* If Vuex isn't installed,
* it will be installed.
*/
Vue.use(Vuex);
const store = new Vuex.Store({});
/**
* If a store isn't passed,
* one will be created.
*/
Vue.use(VueCallStore, { store });
/**
* @arg {string} identifier
* @arg {*} [message]
*/
vm.$calls.start('fetchUsers');
vm.$calls.end('fetchUsers');
vm.$calls.fail('fetchUsers', error);
// Example usage in a Vuex action
new Vuex.Store({
actions: {
fetchUsers({ commit }) {
const identifier = 'fetchUsers';
commit('calls/START', { identifier });
axios
.get('/api/users')
.then(({data} => {
commit('users/set', data);
commit('calls/END', { identifier });
})
.catch(({response}) => {
commit('calls/FAIL', { identifier, message: response.data.errors });
});
},
},
});
/**
* @arg {string | array} identifier
* @returns {boolean}
*/
const isPending = vm.$calls.isPending('fetchUsers');
const isDone = vm.$calls.isDone('fetchUsers');
const hasFailed = vm.$calls.hasFailed(['fetchUsers', 'second']);
Directives accept string or array of identifiers.
<template>
<loading-indicator v-call:pending="'fetchUsers'" />
<div v-call:done="'fetchUsers'" class="content">
<ul>
<li v-for="user in users" :key="user.id">{{ user.name }}</li>
</ul>
</div>
<div v-call:failed="['fetchUsers', 'second']" class="content">
Oops! Unable to fetch users.
</div>
Components' identifier
props accept string or array of identifiers.
Components' once
props accept a boolean. When true
, the slot contents will only be hidden once.
<v-call-pending identifier="fetchUsers" :once="true">
<loading-indicator />
</v-call-pending>
<v-call-failed identifier="fetchUsers">
<div class="content">
<ul>
<li v-for="user in users" :key="user.id">{{ user.name }}</li>
</ul>
</div>
</v-call-failed>
<v-call-failed :identifier="['fetchUsers', 'second']">
<div class="content">
Oops! Unable to fetch users.
</div>
</v-call-failed>
</template>
State | Method | to be true |
---|---|---|
pending | `$callIsPending | $calls.isPending` |
done | `$callIsDone | $calls.isDone` |
failed | `$callHasFailed | $calls.hasFailed` |
/**
* @arg {string} identifier
* @arg {*} [defaultValue = null]
* @returns {object|null}
*/
const notFoundValue = { status: 'done' };
const call = vm.$calls.get('fetchUsers', notFoundValue);
// Format
{
_duration: 200, // milliseconds
_started: moment('2019-04-02T15:19:05.000'), // or null
_stopped: moment('2019-04-02T15:19:05.200'), // or null
message: 'message',
status: 'done',
}
these mutations are useful in Vuex actions
vm.$store.commit('calls/START', { identifier, message });
vm.$store.commit('calls/END', { identifier, message });
vm.$store.commit('calls/FAIL', { identifier, message });
vm.$store.commit('calls/RESET'); // Removes all call objects
Ends a call.
{string} identifier
{*} message
optional{void}
Fails a call.
{string} identifier
{*} message
optional{void}
Starts a call.
{string} identifier
{*} message
optional{void}
Gets raw call.
{string} identifier
{*} defaultValue (default: null)
optional{object}
Gets if one or at least one of many calls has failed.
{string | array} identifier
{boolean}
Gets if one or all calls are done.
{string} identifier
{boolean}
Gets if one or at least one of many calls is pending.
{string} identifier
{boolean}
yarn lint
yarn test
yarn build
FAQs
A Vuex module and Vue mixin to track the status of all API calls
The npm package vue-call-store receives a total of 3 weekly downloads. As such, vue-call-store popularity was classified as not popular.
We found that vue-call-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.