Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/1t
Ensures that only one instance of your module exists either serverside or in the browser.
https://github.com/thlorenz/1t
Last synced: 24 days ago
JSON representation
Ensures that only one instance of your module exists either serverside or in the browser.
- Host: GitHub
- URL: https://github.com/thlorenz/1t
- Owner: thlorenz
- License: mit
- Created: 2014-04-18T17:42:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-04-18T18:30:24.000Z (over 10 years ago)
- Last Synced: 2024-11-22T16:35:18.235Z (about 1 month ago)
- Homepage: https://github.com/thlorenz/1t
- Size: 145 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 1t [![build status](https://secure.travis-ci.org/thlorenz/1t.png)](http://travis-ci.org/thlorenz/1t)
Ensures that only one instance of your module exists either serverside or in the browser.
*1t == [one ton](http://en.wikipedia.org/wiki/Tonne) == a singleton*
```js
var singleton = require('1t');// #ifndef
singleton('__FOO__', module, function () {
// #define __FOO__var path = require('path');
exports.hello = 'world';
exports.filename = path.basename(__filename);})
// #endif
```## Installation
npm install 1t
## API
singleton(id, mdl, fn)Ensures that only one instance for the wrapped module is instantiated.
Works similar to #ifndef/#define pragmas in CParameters:
Name
Type
Description
id
string
the unique id under which the module is stored in the global namespace
mdl
Object
the module variable that is passed to each node/browserify module
fn
function
function that wraps the code of the module
*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT