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 🙏

© 2025 – Pkg Stats / Ryan Hefner

resource-factory

v1.0.3

Published

A decorator to turn classes into a store factory

Downloads

7

Readme

ResourceFactory

Super lightweight, drop dead easy to use, class based state management store.

No more centralised store. Instead, every class is responsible for keeping track of ever new instance created. Kinda like a good parent should be doing.

Each ResourceFactory class will store new instances created. It will also publish to all subscribers of the class when a new instance is added or removed.

ResourceFactory also has the ability to give each new instance a pubsub interface. This makes it super nice when multiple ententes rely on knowing when data is changed on a given instance.

Why ResourceFactory?

I was tired of having to set up large and complex state management systems just to hold on to some data and let other ententes/components know when something changed. I loved the idea of a Class being in charge of holding onto any new instance it created and allowing others to subscribe to it. So the idea of ResourceFactory was born.

How to use

The most simplest way to use ResourceFactory is to use ES decorators to decorate any class with ResourceFactory that you want to maintain state and be subscribable

import { ResourceFactory } from 'ResourceFactory';

@ResourceFactory()
export class Person {
	constructor(firstName, lastName) {
		this.firstName = firstName;
		this.lastName = lastName;
	}
}

and then...

import { Person } from 'where/people/come/from/Person';

// Subscribe returns a function to call to unsubscribe
const unsub = Person.subscribe((people) => {
	// This function will be called every
	// time a new Person is created or removed
	console.log(people);
});

// Create a new person
const newPerson = Person.create('John', 'Doe');

// Pass in the resource to have it removed from the store
Person.remove(newPerson);

// Unsubscribe when done with this component or entity
unsub();

API - Static Methods

<Class>.create( classArguments ) ⇒ classInstance

Creates a new class instance. Also adds the instance to the class store and notifies all subscribers.

<Class>.add( classInstance ) ⇒ classInstance

Manually adds a class instance to the class store and notifies all subscribers.

<Class>.remove( classInstance ) ⇒ void

Removes the given in class instance from the class store and notifies all subscribers.

<Class>.publish() ⇒ void

Calls all subscribers and sends the resources array

<Class>.subscribe(function) ⇒ unsubscribeFunction

Registers a function to the class to be called any time publish is called. Returns a function to be invoked when unregistering from the class. Also immediatly calls the passed in function and sends the current state of resources.

<Class>.unsubscribe(function) ⇒ void

Removes a registered function from the subscriber array.

Public static properties

<Class>.resources

Array containing all instances of the given class.

<Class>.subs

Array containing all registered callback functions to be called any time publish is called.

Adding custom methods

import { ResourceFactory } from 'ResourceFactory';

@ResourceFactory()
export class Person {
	// Custom find method
	static find(guid){
		return Person.resources.find((resource) => resource.guid === guid);
	}

	// Custom reset method
	static reset(guid){
		Person.resources = [];
		// Notifies all subscribers
		Person.publish();
	}

	constructor(firstName, lastName) {
		this.guid = Math.random().toString(36).substr(2, 9);
		this.firstName = firstName;
		this.lastName = lastName;
	}
}

Want to help?

To build run `npm run build`.
To server run `http-server dist/`