24 lines
748 B
Markdown
24 lines
748 B
Markdown
# jibo-cai-singleton
|
|
|
|
[](http://jenkins.jibo.com/job/jibo-cai-singleton/)
|
|
|
|
##Purpose
|
|
A library that simplifies creating singleton libraries. It extracts the name and version of the library from its `package.json` (which it searches for using the `module` object). When the singleton is loaded from two different places, a fuzzy version comparison is performed and an exception is thrown only if the major or minor version numbers differ.
|
|
<http://semver.org/>
|
|
|
|
##Usage
|
|
|
|
```js
|
|
import Singleton from 'singleton';
|
|
|
|
class Someclass {
|
|
// Some good stuff
|
|
}
|
|
|
|
let singleton = Singleton.getOrCreateSingleton(
|
|
module, () => new Someclass());
|
|
|
|
export default singleton;
|
|
|
|
```
|