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

@dumshiba/vue-state-modules

v0.1.1

Published

- class based `state store` fully made in `typescript` for vue. - you can just use it like a normal class instance and it just makes your variables(states) `reactive` automatically. - it has functions like (`$watch`, `$on`, `$off`, `$emit`, `$sample` and

Downloads

4

Readme

vue-state-modules

  • class based state store fully made in typescript for vue.
  • you can just use it like a normal class instance and it just makes your variables(states) reactive automatically.
  • it has functions like ($watch, $on, $off, $emit, $sample and $revert...) too.
  • and you can inspect your state modules in vue devtool.

installation

  • first install the node_module from npm
npm i @dumshiba/vue-state-modules
  • then create a file to register the plugin to vue__ file: src/modules/index.ts
import Vue from 'vue'
import { VueSM } from '@dumshiba/vue-state-modules'

import testModule from './testModule'

// installing the vue-state-modules plugin for Vue
Vue.use(VueSM)

export const modules = VueSM.Modules({ 
    // your modules here
    testModule: new testModule() 
})

// making your modules visible for typescript 
declare module 'vue/types/vue'
{
    interface Vue
    {
        $modules: typeof modules
    }
}
  • and create a file for your module
    file: src/modules/testModule.ts
import { Module } from '@dumshiba/vue-state-modules'

export default class testModule extends Module
{
    // runs when the module is ready
    started()
    {
        
    }
}

i might make a vue-cli-plugin for the things above later

usage

file: src/modules/testModule.ts

import { Module } from '@dumshiba/vue-state-modules'

export default class testModule extends Module
{
    // states
    someState = 0
    half = 0

    // runs when the module is ready
    started()
    {
        // watcher for 'someState'
        this.$watch(() => this.someState, (newValue, oldValue) => this.half = newValue / 2)

        setInterval(() => this.incrementSomeState(), 1000)
    }

    // computed, getter
    get double()
    {
        return this.someState * 2   
    }

    // methods
    incrementSomeState()
    {
        this.someState++
    }
}
  • then you can use it like thise
    file: src/components/someVueComponent.vue
<template>
    <div>
        <div>someState: {{$modules.testModule.someState}}</div>
        <div>half: {{$modules.testModule.half}}</div>
        <div>double: {{$modules.testModule.double}}</div>
    </div>
</template>

module methods

you also have some methods that you can access from outside or inside of the module

$watch

watches for changes on states or getters (from vue)

import { Module } from '@dumshiba/vue-state-modules'

export default class testModule extends Module
{
    someState = 0

    // runs when the module is ready
    started()
    {
        // watches changes for 'someValue' and when it changes console.logs the values
        const unwatch = this.$watch(() => this.someState, (newValue, oldValue) => console.log(`someState changed oldValue:${oldValue} newValue:${newValue}`))
        // unwatch()
    }
}

$on, $off, $emit

custom event system (from vue)

import { Module } from '@dumshiba/vue-state-modules'

export default class testModule extends Module
{
    // runs when the module is ready
    started()
    {
        // add listener for 'incremented'
        const listener = this.$on('incremented', this.onIncrement) 
        
        // there are two ways to remove the listener
        // 1.
        // this.$off('incremented', onIncrement)
        // 2.
        // listener.off()
    }

    onIncrement()
    {
        console.log(`someState incremented`)
    }

    someState = 0
    incrementSomeState()
    {
        this.someState++

        // invoke the listeners
        this.$emit('incremented')
    }
}

$waitFor

combination of watch and promise. let's you wait until a state matches with your conditions in async functions

import { Module } from '@dumshiba/vue-state-modules'

export default class testModule extends Module
{
    someState = 0

    // runs when the module is ready
    async started()
    {
        // start the incremention loop
        this.loop()

        // wait until someState is 5
        await this.$waitFor(() => this.someState, (newValue, oldValue) => newValue === 5) 

        console.log('someState reached 5')
    }

    async loop()
    {
        while (this.someState < 10)
        {
            await new Promise((resolve) => setTimeout(resolve, 1000))
            this.someState++
        }
    }
}

$sample, $revert

let's you take a sample of the current states from a module and then you can revert back the module to that state automatically

import { Module, ModuleSample } from '@dumshiba/vue-state-modules'

export default class testAuthModule extends Module
{
    token?: string = undefined
    user?: { name: string, uid: string } = undefined

    private cleanState!: ModuleSample  
    started()
    {
        // takes a sample of the current state of module
        this.cleanState = this.$sample()
    }

    logout()
    {
        // reverts back to clean state of the module
        // (basically sets all of the states based on the sample 'cleanState')
        this.$revert(this.cleanState)
    }

    login(username: string, password: string)
    {
        // ...some login method
        this.user =  { name: 'shiba', uid: '1a2b3c4d' }
        this.token = 'a1b2c3d4...'
    }
}