Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r3wt/singl
create readable singleton modules easily using basic javascript syntax.
https://github.com/r3wt/singl
Last synced: about 2 months ago
JSON representation
create readable singleton modules easily using basic javascript syntax.
- Host: GitHub
- URL: https://github.com/r3wt/singl
- Owner: r3wt
- Created: 2016-06-19T19:02:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-20T20:55:16.000Z (over 8 years ago)
- Last Synced: 2024-04-14T10:16:04.978Z (8 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/singl
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### install
`npm install singl`
### singl 1.0.3
singl provides a concise interface for developing singleton objects.
the goal of the project is to make your module code more organized and readable. don't worry about decorating prototypes. singl does it for you.# basic usage
*create yourself a module cityboy *
```js
module.exports = require('singl')( 'my.module', {options: {},
//this is the constructor!
init: function(options){
this.options = options;
},
//your methods here.
foobar: function(){
console.log('hello world');
}
});```
*now use your module somewhere*
```js
var myInstance = require('my-module')(myOptions);myInstance.foobar();
myInstance2 = require('my-module')(myOptions);
console.log(myInstance === myInstance2);
```
# function signature
```js
function singl( namespace, object[, freeze = false] )
```
# implementation notes
- singl expects argument `namespace` to be of type `string`. it is required.
- singl expects argument `object` to be of type `object`, ie a plain object. it is also required.
- singl accepts an optional 3rd argument, `freeze`, of type `bool`, which would freeze the object if the parameter is `true`.
- the `object` parameter must have a property called `init` which is defined as a function. this is the constructor for your class/object/thingy-ma-jig.
- singl returns a constructor function which will apply all arguments given to the `init` method, and return the instantiated instance.# license
MIT