24.1.0 • Published 7 years ago

skypager-registry v24.1.0

Weekly downloads
5
License
UNLICENSED
Repository
github
Last release
7 years ago

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)
24.1.0

7 years ago

24.0.0

7 years ago

21.0.0

7 years ago

20.1.0

7 years ago

17.2.0

7 years ago

16.0.0

7 years ago

15.1.0

7 years ago

15.0.0

7 years ago

14.0.0

7 years ago

13.3.1

7 years ago

13.1.0

7 years ago

13.0.0

7 years ago

12.3.0

7 years ago

12.2.0

7 years ago

11.8.0

7 years ago

11.2.0

7 years ago

11.1.0

7 years ago

11.0.0

7 years ago

10.0.0

7 years ago

8.7.0

7 years ago

8.6.0

7 years ago

8.2.0

7 years ago

7.7.0

7 years ago

7.0.0

7 years ago

6.6.0

7 years ago

6.5.0

7 years ago

5.30.0

7 years ago

5.20.0

8 years ago

5.19.0

8 years ago

5.18.3

8 years ago

5.17.3

8 years ago

5.11.0

8 years ago

5.10.2

8 years ago

5.10.0

8 years ago

5.8.0

8 years ago

5.7.1

8 years ago

5.7.0

8 years ago

5.6.0

8 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.7

8 years ago

5.0.3

8 years ago

4.2.1

8 years ago

4.2.0

8 years ago

4.1.2

8 years ago

4.0.2

8 years ago