singleton-decorator
v0.2.2
Published
An ES7 decorator for making classes act as singletons
Downloads
109
Maintainers
Readme
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