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

comstock

v0.0.17

Published

Simple alternative to Vuex, written in TypeScript

Downloads

8

Readme

Comstock, the simpler alternative to Vuex.

This is a work-in-progress. use at your own risk

I pretty much wrote this library as a state management solution for my side project. It works, but I'm not going to production with it yet. If you are successfully using this in production, please feel free to let me know on github, I'd love to hear about it!


Background

After getting frustrated with the amount of ceremony and boilerplate involved with using vuex, and after spending some time researching different store alternatives, I resolved that there must be a better way.

Comstock is designed to be simple, while still allowing for single-responsibility state management. This means your state is IN ONE PLACE for your application (or, a section of your application, in the event that it is a huge application).

But how did you get the name Comstock?

Well, my thought process was something like this:

  • State management
  • Store
  • something similar to Store
  • Gold Mine
  • I read a book once about a famouse mine
  • oh yeah!, the Comstock Lode.
  • does NPM have any packages named that?
  • No? Alright, we got ourselves a name, boys.

No real significance to the name besides it was unique enough to remember, and it wasn't taken on NPM yet. Well, that, and gold mines are somehow tangentially related (in my mind at least) to state management, apparently.


Documentation

Store

A store within Comstock. Classes extending this should be a singleton. See example below.

StoreState

Decorator used by Comstock to declare a property on the Store as stateful. Any time this property is updated, the changes propogate through Vue and into your UI.

StoreStateOptions

Options to be passed to the StoreState decorator.

StorePlugin

Plugin that can accept property change events within the store. Currently, can register a before change listener, or an after change listener, or both!

StoreOptions

Options to pass to the store upon construction. Currently just has a single property: plugins, which is an array of StorePlugin.

Example:

//in TestStorePlugin.ts

import { StorePlugin, StorePluginValueChangeEvent } from 'comstock';

export default class TestStorePlugin implements StorePlugin {
    public beforeValueChange(event: StorePluginValueChangeEvent<any>): void {
        console.log(`Before Property Change: ${JSON.stringify({
            old: event.oldValue,
            new: event.newValue,
            property: event.property,
        })}`);
    }

    public afterValueChange(event: StorePluginValueChangeEvent<any>): void {
        console.log(`After Property Change: ${JSON.stringify({
            old: event.oldValue,
            new: event.newValue,
            property: event.property,
        })}`);
    }
}
//in ExampleStore.ts

import { Store, StoreState } from 'comstock';
import TestStorePlugin from './TestStorePlugin';

class ExampleStore extends Store {

    private static pExampleStore: ExampleStore | null;

    @StoreState({ defaultValue: 'foo' })
    public foo!: string;

    // Singleton pattern with private constructor and public static getter.
    private constructor() {
        super({
            plugins: [new TestStorePlugin()],
        });
    }

    public static get instance(): ExampleStore {
        // Ensures once the static instance is set, it never gets re-instantiated.
        if (ExampleStore.pExampleStore == null) {
            ExampleStore.pExampleStore = new ExampleStore();
        }

        return ExampleStore.pExampleStore;
    }
}

// Even though we used singleton pattern, just export the single instance. 
export default ExampleStore.instance;
//in ExampleComponent.ts, or ExampleComponent.vue (vue.js component)

import { Component, Vue } from 'vue-property-decorator';
import ExampleStore from './ExampleStore';

@Component({
    template: `
        <div class="foo-value">{{ foo }}</div>
    `,
})
export default class FooDisplay extends Vue {
    public get foo(): string {
        return ExampleStore.foo;
    }
}

And that's it! Your store is a singleton, so any changes on the properties declares as StoreState will propogate through all the components that utilize them.

Example

Planned features down the road to v1.0:

  • Write decorator for making it easier to map properties within vue components.