🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More →
Socket
Book a DemoSign in
Socket

wrasse

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

wrasse

JavaScript dependency injection with the Decorators syntax.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

wrasse

JavaScript dependency injection with the Decorators syntax.

Installing

npm i -S wrasse

Getting Started

First, you can instantiate Wrasse and it needs export. Because it is necessary to solve Wrasse instantiation before any import, it is cut out as a single source.

For example, as wrasse-singleton.js.

import Wrasse from 'wrasse';
const wr = new Wrasse();
export default wr;

Second, you can set a module. You must register the key to get the module.

register-dependencies.js

import wr from './wrasse-singleton';

import _ComponentA from './component-a';
import _ComponentB from './component-b';
import _ComponentC from './component-c';

import {
  ComponentA,
  ComponentB,
  ComponentC
} from './module-keys';

wr.set(ComponentA, _ComponentA);
wr.set(ComponentB, _ComponentB);
wr.set(ComponentC, _ComponentC);

export default wr;

module-keys.js

export const ComponentA = Symbol('ComponentA');
export const ComponentB = Symbol('ComponentB');
export const ComponentC = Symbol('ComponentC');

// Or, it can also be a string.

// export const ComponentA = 'ComponentA';
// export const ComponentB = 'ComponentB';
// export const ComponentC = 'ComponentC';

Usage

You can use the inject in your implementation with Babel. (TypeScript is unverified. We have plan to support.)

babel --optional es7.decorators
import wr from './register-dependencies';

import {
  ComponentA,
  ComponentB,
  ComponentC
} from './module-keys';

@wr.inject({
  ComponentA,
  ComponentB,
  ComponentC
})
export default class Application {
  constructor() {
    console.log(this.ComponentA); // ę ¼ē“ęøˆćæ
  }
}

API

  • Wrasse
  • Wrasse#set(key: string|Symbol, module: any): void
  • Wrasse#inject(keys: {[key: string]: string|Symbol}): constructor @decoratable

Author

  • OKUNOKENTARO @armorik83

License

MIT https://github.com/chatwork/wrasse/blob/master/LICENSE

Keywords

DI

FAQs

Package last updated on 29 Sep 2015

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