You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

electrolyte-decorator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electrolyte-decorator

Handy reflection and annotation utility for electrolyte components.

0.1.1
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

electrolyte-decorator

Handy wrappers for annotating electrolyte components by reflecting dependencies from the factory method parameter list.

Example

components/settings.js

import { Annotations, decorate } from 'electrolyte-decorator'

// Note the Annotations.Singleton reference being passed as the last argument
// into the decorate method. The decorate method has a signature of:
//
// (Function componentFactory, ... Function componentAnnotations)
//
// This allows us to pass any number (including 0!) of annotations we want to
// apply to our componentFactory. Annotations are Functions that take zero
// arguments and return an object whose keys and values should be assigned onto
// the target function when applied.
//
// This package only supports the @require and @singleton annotations that
// electrolyte ships with. If more annotations are added in the future,
// it is trivial to add support for them.
module.exports = decorate(function () {
  return {
    sqliteFile: ':memory:'
  }
}, Annotations.Singleton)

components/sqlite.js

import sqlite3 from 'sqlite3'
import { decorate } from 'electrolyte-decorator'

// The decorate method inspects the name of the declared function arguments
// and automatically manages setting them for this component.
// This is a shorthand for module.exports['@require'] = [ 'settings' ]
module.exports = decorate(function (settings) {
  return new sqlite3.Database(settings.sqliteFile)
})

Keywords

di

FAQs

Package last updated on 19 Jun 2016

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