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

@madappgang/registry

v3.0.7

Published

Globally available central service registry

Downloads

3

Readme

Registry

Build Status Coverage Status

What is it?

This package implements a concept of a globally available registry that enables access to your logic throughout the application. It is quite similar to service locator software development pattern.

What might you need it for?

You want to initialize your logic right after the application starts. The place to do it is the applications entry point. The issue is that you would then have to export services from the entry point module, which is not a good thing to do. Entry point code should only be run once. If you're exporting logic in your entry point module, you're probably better off moving that functionality in to a re-usable module.

With this package you can create a registry and export it at one place, but delegate the registering to another. This is the key idea of the package.

How do you use it?

First off you need to install it. It is available on npm.

$ npm install --save @madappgang/registry

Creating a registry

// serviceRegistry.js

import createRegistry from '@madappgang/registry';

const { register, exposeRegistered } = createRegistry();

// here you delegate the registering so it can be performed in another file
export { register };

export default exposeRegistered();

Default import of this file is an object that contains all registered stuff. At first it is an empty object since nothing has been registered yet, but it's going to update each time you register something.

The idea is that you register stuff somewhere else, but then access it from here.

Registering logic

All you need to do now is to init your logic and get it registered globally.

// entry point or whatever place you want to configure your services at
import { register } from './serviceRegistry';
...

const registerServices = async () => {
  const httpService = await configureHttpService();
  const storageService = await configureStorageService();

  return register({
    http: httpService,
    storage: storageService,
  });
};

const services = await registerServices();

...

Accessing logic

Then you simply access you services in another file

// anotherFile.js

// this is imported from the place where the registry was created
import services from './serviceRegistry';

console.log(services.http); // httpService
console.log(services.storage); // storageService

As you can see you did the registering at the entry point, but access the results from servieRegistry.js

As simple as that.

API

Registry

Registry is created with packages createRegistry method.

| Property | Type | Description | | --- | --- | --- | | register | function | This is used to register units. It accepts an object, keys of which are aliases, and values are units. You will then be able to access units by those aliases. Returns all that was ever registered. | exposeRegistered | function | This returns the object that holds everything that has ever been registered to this instance of registry. Returns all that was ever registered.

License

This project is licensed under the MIT License - see the LICENSE file for details.