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

@grlt-hub/app-compose

v1.4.0

Published

Create scalable, module-based applications with ease.

Downloads

849

Readme

App Compose

Create scalable, module-based applications with ease.

Motivation

Modern applications thrive on modular architecture, adapting seamlessly to evolving business needs. To achieve true modularity, though, you need more than just independent components—you need an efficient way to bring them together. This means controlling how modules load, in what order, and with which dependencies. It gets even trickier when you want to turn off parts of the system without any traces in the code, like if/else statements, and without affecting the stability of other components.

How does this library solve this problem?

app-compose is designed to make this seamless. It lets you dynamically enable or disable modules as needed, not only preventing their code from loading when they’re off but also excluding all related dependencies. This means no excess resource use and optimized performance, even as the app grows.

With app-compose, you can scale your applications effortlessly—whether you’re building a lightweight tool or a complex, feature-rich system. By managing dependency flow and on-demand module loading, app-compose provides the control you need to build applications that are both flexible and robust.

Example

There are three entities: users, accounts, and wallets.

If the user exists, then the accounts entity should be started. If the accounts entity is done, then the wallets entity should be started.

import { createContainer, compose } from '@grlt-hub/app-compose';

// wrap the module in a container
const user = createContainer({
  id: 'user',
  start: async () => {
    const data = await fetchUser();

    return { api: { data } };
  },
});

const accounts = createContainer({
  id: 'accounts',
  dependsOn: [user],
  start: async ({ user }) => {
    const data = await fetchAccounts({ id: user.data.id });

    return { api: { data } };
  },
  enable: ({ user }) => user.data.id !== null,
});

const wallets = createContainer({
  id: 'wallets',
  dependsOn: [accounts],
  start: () => ({ api: null }),
});

// up the containers
await compose.up([user, wallets, accounts]);

// { user: 'idle',     accounts: 'idle',     wallets: 'idle' }
// { user: 'pending',  accounts: 'idle',     wallets: 'idle' }
// { user: 'done',     accounts: 'idle',     wallets: 'idle' }
//
/* if user.data.id !== null */
/** { user: 'done',    accounts: 'pending',  wallets: 'idle' } **/
/** { user: 'done',    accounts: 'done',     wallets: 'pending' } **/
/** { user: 'done',    accounts: 'done',     wallets: 'done' } **/
//
/* else */
/** { user: 'done',    accounts: 'off',      wallets: 'off' } **/
//
// compose.up done

The library offers convenient functions for creating and composing modules into a single system. Each module is encapsulated in a container with a clear configuration, including parameters like id, dependsOn, optionalDependsOn, start, and enable. Developers describe containers and launch them using compose.up fn, without the need to worry about the order of execution. This approach makes working with containers intuitive and close to natural language.

Strengths of the Library

  • Provides a simple and intuitive developer experience (DX).
  • Designed with a focus on quality and performance.
  • Weighs less than 1.6 kB (runtime), making it lightweight.
  • Covered by 100% tests, including type tests.
  • Ensures high performance, suitable for scalable applications.
  • Includes debugging tools to facilitate the development process.
  • Offers the ability to visualize the system composed of containers effectively (including transitive dependencies and their paths).
  • Follows semantic versioning (semver), guaranteeing stability and predictability of changes with each release.

Documentation

For additional information, guides and api reference visit documentation site.

Community