singleton-decorator

0.2.2 • Public • Published

singleton-decorator

An ES7 decorator that adds singleton behavior to classes. Very tiny and easy-to-use.

Usage

Decorator accepts no arguments. The class will be decorated with the "implicit" and "explicit" styles together. You can treat the class as if it weren't a singleton but only one instance will ever be created:

import singleton from 'singleton-decorator';
 
@singleton
class Foo {
}
 
let a = new Foo(),
    b = new Foo(),
    c = Foo();
    d = Foo.getInstance();
 
// a === b === c === d

Package Sidebar

Install

npm i singleton-decorator

Weekly Downloads

30

Version

0.2.2

License

none

Unpacked Size

1.54 kB

Total Files

3

Last publish

Collaborators

  • dilame