# dekorator

> Ultra light weight dependency injection library using ES7 (2016) decorators.

Latest version **0.2.3** (published 2016-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install dekorator
pnpm add dekorator
yarn add dekorator
bun add dekorator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2016-07-06 |
| First published | 2015-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Origin1 Technologies |
| Maintainers | origin1tech |
| Keywords | ES6, ES7, Decorators, ES2016, Dependencies, Dependency Injection |

## Links

- npm: https://www.npmjs.com/package/dekorator
- Repository: https://github.com/origin1tech/dekorator
- Homepage: https://github.com/origin1tech/dekorator#readme
- Issues: https://github.com/origin1tech/dekorator/issues
- npm.io page: https://npm.io/package/dekorator

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2016-07-06
- 0.2.2 — 2016-06-22
- 0.2.1 — 2016-06-22
- 0.1.36 — 2015-10-15
- 0.1.35 — 2015-10-15

## README

# Dekorator

[![wercker status](https://app.wercker.com/status/5aa3d785a8e99ed8322da7e7df56fad5/m "wercker status")](https://app.wercker.com/project/bykey/5aa3d785a8e99ed8322da7e7df56fad5)

Simple dependency injection lib exposing inject and singleton decorators. Dekorator can be used with Node or in browser with an ES6 transpiler such as (Babel)[https://babeljs.io/].

Dekorator is an extremely stripped down dependency injection library. It is meant to provide a lightweight solution for embedding into other libraries. If you are looking for a robust solution with lots of features this isn't it. It has a very specific use case. This doesn't mean it won't work exactly as indicated but rather you may need additional features it does not provide.

## Install

**For use with Node**

```sh
$ npm install dekorator
```
**For use in browser & JSPM**

NOTE: jspm is a package manager which sets up your project for use with System.js, the ES6 module loader system. You can read more on (jspm here)[http://jspm.io].

```sh
jspm install npm:dekorator
```
or

```sh
jspm install github:origin1tech/dekorator
```

## Getting Started

Using **dekorator** is very simple. You need merely decorate an ES6 class to have it's dependency(s) injected into the constructor or specify the class as a singleton.

#### Injecting

```js
// NOTE: import below shown using System.js if you
// reference typings (dist/index.d.ts) you can import
// as ... from 'dekorator';
import {inject, invoke} from 'origin1tech/dekorator';

class Vehicle {
	constructor() {
	}
}

@inject(Vehicle)
class Car {
	constructor(vehicle) {
		this.vehicle = vehicle;
	}
	getVehicle() {
		return this.vehicle;
	}
}

// Invoke the class.
let car = invoke(Car);

// do something with car and
// injected vehicle.
let vehicle = car.getVehicle();
```

#### singleton

Nothing special here simply decorate your class with "@singleton" and it just works. Decorating with this decorator will ensure the class is a singleton in turn it will return the same instance when injected in other classes.

```js
@singleton
class MyClass {
	constructor() {}
}
```

## Additional Notes

One thing that trips up devs when first using decorators, well at least for those that actually use semi colons is that when using an ES7/ES2016 decorator you DO NOT use a semi colon after the decoration. Think of it in terms of a fluent api where you wouldn't terminate as you're using dot notation to further define some class/function etc.

**What NOT to do**

The below example with fail and not work

```js
@inject(OtherClass);
class MyClass {
	constructor() {}
}
```

## Testing

You will notice a few specs in the **test** folder which can be run using **Mocha**. Simply type mocha in your terminal from the root of the project or run:

```sh
npm test
```

## License

Basically you can do just about anything you like. Enjoy!

See LICENSE.md

---
_Source: https://npm.io/package/dekorator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
