Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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 C



Parameters:

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


Source:




*generated with [docme](https://github.com/thlorenz/docme)*

## License

MIT