npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vuvice

v0.0.4

Published

## Introduction

Readme

Vuvice - A Reactive State Management Library

Introduction

Vuvice is a powerful Vue.js package designed to help developers integrate object-oriented and service-based architectures into their applications. Unlike traditional state management tools, Vuvice focuses on providing a flexible architecture that allows developers to build Vue.js applications in a way that best suits their needs.

Vuvice isn't about competing with tools like Pinia or Vuex — instead, it complements them by offering an alternative approach for managing logic and structure in your application. With Vuvice, you can apply solid OOP principles and design patterns, making your codebase more modular, scalable, and maintainable.

Whether you're working on a large-scale enterprise app or a small side project, Vuvice empowers you to organize your application logic with clean, reusable services and class-based components — all while staying fully compatible with the Vue ecosystem.


Features

  • BehaviorSubject: A reactive data structure that holds a value and allows components to subscribe to changes.
  • @UiSync Decorator: Automatically syncs getter methods to the UI, ensuring that the UI remains up-to-date with service data.
  • Manual Unsubscription: Developers are responsible for manually unsubscribing from reactive values to prevent memory leaks.
  • Memory Management: Vuvice handles subscriptions internally and helps manage the lifecycle of subscriptions within your components.
  • Easy-to-use API: Provides a clean and straightforward API to manage reactive state and sync it with your Vue components.

Installation

To install Vuvice, you can use npm:

npm install vuvice

Core Concepts

BehaviorSubject

A BehaviorSubject is a core component in Vuvice that holds and manages a reactive value. Components can subscribe to this value and receive updates whenever the value changes.

Methods

  • next(value): Updates the current value and notifies all subscribers.
  • getValue(): Returns the current value of the BehaviorSubject.
  • attach(observer): Attaches an observer (or callback) to the BehaviorSubject to receive updates.
  • detach(observer): Detaches an observer from the BehaviorSubject.
  • notify(): Notifies all attached observers with the latest value.

@UiSync Decorator

The @UiSync decorator binds getter methods in services to reactive data sources and automatically keeps the UI in sync with the data.

Generics of @UiSync Decorator

The @UiSync decorator accepts two generic types:

  1. First Generic (V): Represents the type of the reactive value being observed in the BehaviorSubject.
  2. Second Generic (T): Represents the type returned by the updater function (the second argument passed to the decorator). This function can transform or modify the reactive value before it’s returned to the UI.

Example Usage:

@UiSync<{ title: string; id: string }[], { title: string; id: string }[]>('todos', (value) => value)
public getTodos(_id: string): UiConnection<{ title: string; id: string }[]> {
  return {
    value: this.todos.getValue()
  }
}
  • First Generic ({ title: string; id: string }[]): Represents the type of the reactive value inside the BehaviorSubject (an array of todos).
  • Second Generic ({ title: string; id: string }[]): Represents the return type of the updater function. In this case, it returns the same type ({ title: string; id: string }[]), but you could modify or transform the value in this function if needed.

useSubscribe Hook

The useSubscribe hook subscribes to a BehaviorSubject and automatically updates the UI when the value changes. It manages the subscription lifecycle and unsubscribes when the component is unmounted. It does not return the unSubscribe method.

  • Subscription Management: The hook subscribes to the BehaviorSubject and automatically updates the UI when the value changes. It handles the subscription lifecycle when the component mounts and unmounts.
  • No Unsubscription: The useSubscribe hook does not return the unSubscribe method. Developers are expected to manage unsubscribing manually using the unSubscribe method provided by the @UiSync decorator.

Example: Todo Service

TodosService.ts

This service manages the todo list and exposes it reactively to the UI using Vuvice.

import { BehaviorSubject, type UiConnection, UiSync } from 'vuvice'

export class TodosService {
  private static Instance: TodosService | null = null

  // Internal reactive store for todos
  private todos = new BehaviorSubject<{ title: string; id: string }[]>([])

  private constructor() {}

  // Public method to add a new todo item
  public addTodo(title: string) {
    this.todos.next((currentTodos) => {
      currentTodos.push({ title, id: Math.random().toString() })
      return [...currentTodos]
    })
  }

  // Expose todos reactively to the UI
  @UiSync<{ title: string; id: string }[], { title: string; id: string }[]>('todos', (value) => value)
  public getTodos(_id: string): UiConnection<{ title: string; id: string }[]> {
    return {
      value: this.todos.getValue()
    }
  }

  // Singleton access to the service instance
  public static GetInstance() {
    if (!TodosService.Instance) {
      TodosService.Instance = new TodosService()
    }
    return TodosService.Instance
  }
}

Example Usage in Vue Component

TodosList.vue

In the TodosList component, you can subscribe to the getTodos method and automatically update the UI when the todo list changes. You need to pass the unique component ID to the decorated getter method.

<script setup lang="ts">
import { TodosService } from "@/TodosService.ts"
import { useComponentId } from "vuvice"
import { onBeforeUnmount } from "vue"

// Get the singleton instance of TodosService
const todosService = TodosService.GetInstance()

// Retrieve the unique component ID
const uuId = useComponentId().uuId

// Set up the subscription and retrieve the data using useSubscribe
const todos = useSubscribe(todosService.getTodos(uuId).value)

// Clean up by disconnecting from the BehaviorSubject
onBeforeUnmount(() => {
  todosService.getTodos(uuId).unSubscribe(uuId)
})
</script>

<template>
  <div v-for="todo in todos" :key="todo.id">
    {{ todo.title }}
  </div>
</template>

<style scoped>
/* Add styles for the todo list */
</style>