vaxee

Vaxee is a simple and easy-to-use library for Vue 3 to manage the state of your application.
1,324 74
Install
npm install vaxee
Latest Version:0.12.1
Vue:3
License:MIT
Last Updated:Dec 21, 2024
Links: GitHub  ·  npm
Maintainer: letstri

Nixle logo

The State Manager for Vue 3
Store your data across whole application

Overview

Vaxee is a simple and easy-to-use library for Vue 3 to manage the state of your application.

  • ✨ Simple and intuitive API.
  • 💪 Incredible TypeScript support.
  • 🤯 Includes a request function.
  • 🫡 Improved DX with reactivity.

Documentation

You can find the documentation and installation steps on the website.

Demo

Let's create a huge demo store with a user and auth logic.

import { createStore } from "vaxee";
import { fetchUser, signIn, parseJwt } from "~/user";

export const useUserStore = createStore(
  "user",
  ({ state, getter, request }) => {
    const tokens = state(
      {
        access: "",
        refresh: "",
      },
      {
        persist: "user.tokens",
      }
    );
    const isAuthorized = getter(
      () => tokens.value.access && tokens.value.refresh
    );
    const userId = getter(() => parseJwt(tokens.value.access).sub);

    const signIn = async (email: string, password: string) => {
      tokens.value = await signIn(email, password);
    };

    const user = request(() => fetchUser(userId.value));

    return {
      user,
      isAuthorized,
    };
  }
);

Now, let's use this store in a component.

<script setup>
import { watch } from "vue";
import { useUserStore } from "../stores/user";

const { isAuthorized } = useUserStore();
const { data: user, refresh: refreshUser } = await useUserStore("user");

watch(isAuthorized, (isAuthorized) => {
  if (isAuthorized) {
    refreshUser();
  }
});
</script>

<template>
  <div>
    <p>Authorized: {{ isAuthorized }}</p>
    <p>User: {{ user.firstName }} {{ user.lastName }}</p>
  </div>
</template>

Author

© letstri, released under the MIT license.

Related Packages

@vaxee/nuxt

Nuxt Module for Vaxee

1,857 74
ee-vuex

More convenient global status manager than Vuex and Pinia

2,452 6
@pinia/nuxt

Nuxt Module for pinia

34,268,649 14,743
pinia-plugin-logger

Logger for Pinia

2,311 4
@pinia/testing

Testing module for Pinia

40,350,592 14,743

Version History

Version Released Vue License
0.12.1 >3.0.0 MIT
0.12.0 >3.0.0 MIT
0.11.2 >3.0.0 MIT
0.11.1 >3.0.0 MIT
0.11.0 >3.0.0 MIT