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

@crux/app

v0.0.45-alpha

Published

This is the primary way to create a `crux` application. Pass it a configuration object of your services, layout, modules, etc.:

Downloads

24

Readme

@crux/app

This is the primary way to create a crux application. Pass it a configuration object of your services, layout, modules, etc.:

const core = await createApp({
  modules: {
    router: {
      enabled: () => true,
      factory: () => import('./modules/router/redux').then(mod => mod.createRouterRedux)
    },
    layout: {
      enabled: () => true,
      factory: () => import('./modules/layout/redux').then(mod => mod.createLayoutRedux),
    },
  },
  root,
  services: {
    cache: { factory: () => import('./services/cache').then(mod => mod.createCacheService) },
    darkMode: { factory: () => import('./modules/dark-mode/service').then(mod => mod.createDarkModeService), deps: ['cache'] },
  },
  views: {
    layout: {
      selectData: selectLayout,
      factory: () => import('./modules/layout/views/layout').then(mod => mod.createLayoutView),
    },
  }
}, { logger: createLogger('debug') });

There's a lot going on above, let's break it down:

const core = await createApp({

The app constructor is asynchronous.

  root,

The root is an HTMLElement that currently exists in the DOM.

services: {
  cache: { factory: () => import('./services/cache').then(mod => mod.createCacheService) },
  darkMode: { factory: () => import('./modules/dark-mode/service').then(mod => mod.createDarkModeService), deps: ['cache'] },
},

Services are defined as dynamic imports with a factory, which is a function that returns a Promise of the service constructor function, and an optional deps array, which specifies the keys of other services to be injected into the constructor when it is instantiated.

NB: the services object defines a @crux/di container, which is used internally. See the @crux/di docs for more documentation.

Here, we've defined two services, a cache service and a darkMode service, which makes use of the cache service.

views: {
  layout: {
    selectData: selectLayout,
    factory: () => import('./app/layout/views/layout').then(mod => mod.createLayoutView),
  },
}

Views are defined in a similar way to services, except that they can include selectData for selecting data from the store, and selectActions for selecting registered actions from the store (only non-layout views).

The layout view is required. Any other view that is registered also requires a root, which is a data-crux-root as defined by the layout view:

views: {
  layout: { ... },
  otherView: {
    root: 'sidebar',
    selectData: selectOtherViewData,
    selectActions: selecOtherViewActions,
    factory: () => import('./features/other/views/other-view').then(mod => mod.createOtherView),
  }
}

Modules are also defined in a similar way to views and services, but they also define an enabled selector. This enables modules to mount and unmount according to any state-driven criteria.

modules: {
    router: {
      enabled: (state) => true,
      factory: () => import('./modules/router/redux').then(mod => mod.createRouterRedux)
    },
    layout: {
      enabled: (state) => true,
      factory: () => import('./modules/layout/redux').then(mod => mod.createLayoutRedux),
    },
  },