📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

skypager-registry

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skypager-registry

create queryable directories of lazy loading functions

24.1.0
latest
Source
npm
Version published
Weekly downloads
198
110.64%
Maintainers
1
Weekly downloads
 
Created
Source

Skypager Registry

A Registry is a queryable directory of functions.

Registries can be used for a variety of purposes, such as dependency injection, asynchronous module loading using something like Webpack's require.ensure or System.import functionality, or for building a database of plugins or middlewares that can be dynamically required using different kinds of application logic at runtime.

Installation

npm install skypager-registry --save

Usage Examples

Building a registry of React Components

import registry from 'skypager-registry'
import glob from 'glob'
import { dirname, basename } from 'path'

const componentIndexes = (cwd, componentFolder='components') => {
  const filePaths = glob.sync(`${componentFolder}/*/index.js`, { cwd })

  return filePaths.map((path) => (
    [basename(dirname(path)), path]
  )
}

const components = registry({}, 'components')

componentIndexes.forEach([componentId, modulePath] => {
  components.register(componentId, () => {
    const component = require(modulePath)
    return component.default ? component.default : component
  })
})

Other Examples

For people familiar with react-native for example, there is the AppRegistry

import React, { Component } from 'react'
import { AppRegistry, View } from 'react-native'

const MyScreen = (props = {}) => (
  <View>Hello World</View>
)

AppRegistry.registerComponent('MyScreen', () => MyScreen)

FAQs

Package last updated on 20 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts