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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vue-modeler/dc

v2.0.3

Published

Dependency container based on VUE effected scope and shared composable.

Downloads

570

Readme

Dependency container for VUE

test

Compatible with Vue 2 only.

Overview

Plugin implements a lightweight dependency container for Vue applications based on the effectScope API. Similar to VueUse's createSharedComposable, but with enhanced instance management.

Key Features

  • 🗑️ Automatic cleanup when instances are not in use
  • 🔒 Type Safe
  • 🪶 Lightweight
  • 🎯 Simple API
  • 🔄 Supports sharing any data type
  • ✨ Single responsibility principle compliant

Why Use This?

Modern applications (PWA, SPA) often need to share instances across:

  • Components on the same page
  • Different routes/pages
  • Device-specific implementations (mobile/desktop)

This plugin:

  • simplifies instance sharing
  • helps separate business logic from view logic, enabling proper Domain-Driven Design (DDD) architecture.
  • helps to create persistent instances which will not be disposed when the component is unmounted
  • provides direct access to the container instance by $vueModelerDc property of the Vue instance

Important Notes:

  1. The container manages instance scope, not state
  2. SSR compatible, but doesn't handle state transfer from server to client

Instalation

import { vueModelerDc } from '@vue-modeler/dc'
import Vue from 'vue'

...

Vue.use(vueModelerDc)

...

const app = new Vue()
...
// Get instance by factory function
const instance = app.$vueModelerDc.get(factoryFunction)

Basic Usage

Define provider

Create a provider using defineProvider:

import { defineProvider } from '@vue-modeler/dc'

const useMyProvider = defineProvider(() => {
  // Your factory function
  return {
    // Instance data/methods
  }
})

Usage in Components

<template>
  <div>{{ model.state }}</div>
</template>

<script setup lang="ts">
import { useMyProvider } from '@/providers/myProvider'

const model = useMyProvider()
</script>

Best Practices

1. Possible File Organization

src/
  ├── application/         # Business logic
  │   ├── models/          # Domain models
  │   └── services/        # Business services
  ├── infrastructure/      # External services, APIs
  └── providers/           # Container providers

2.Example Implementation

// infrastructure/api.ts
export const api = {
  fetchState(): Promise<Record<string, unknown>> {
    // Simulating API call with timeout
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ someField: 'someValue' })
      }, 1000)
    })
  }
}

// application/models/MyModel.ts
import { shallowRef, type ShallowRef } from 'vue'

interface Api {
  fetchState(): Promise<Record<string, unknown>>
}

export class MyModel {
  private state: ShallowRef<Record<string, unknown>>

  constructor(private api: Api) {
    this.state = shallowRef({})
    this.initialize()
  }

  private async initialize(): Promise<void> {
    this.state.value = await this.api.fetchState()
  }

  destroy(): void {
    this.state.value = {}
  }
}

// providers/myProvider.ts
import { defineProvider } from '@vue-modeler/dc'
import { MyModel } from '@/application/models/MyModel'
import { api } from '@/infrastructure/api'

export const useMyModel = defineProvider(() => new MyModel(api))