Comparing version 0.0.2 to 0.1.0
@@ -15,3 +15,3 @@ var EventEmitter = require("events").EventEmitter; | ||
if(!(typeof callback == "function")) { | ||
callback = function(){}; | ||
callback = function(){ }; | ||
} | ||
@@ -21,3 +21,3 @@ | ||
if(singletonArgs) { | ||
callback.apply(null, singletonArgs); | ||
callback.apply(this, singletonArgs); | ||
@@ -29,3 +29,3 @@ //return the value if there is one | ||
em.on("singleton", callback); | ||
em.once("singleton", callback); | ||
@@ -43,5 +43,2 @@ //still loading? add listener to event emitter | ||
em.emit.apply(em, ["singleton"].concat(singletonArgs)); | ||
//dispose | ||
em.removeAllListeners("singleton"); | ||
}; | ||
@@ -57,8 +54,5 @@ | ||
//returned a value? Then it's not async... | ||
if (ret = fn.apply(this, args)) { | ||
cb(ret); | ||
return ret; | ||
} | ||
fn.apply(this, args); | ||
return this; | ||
}; | ||
@@ -65,0 +59,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "asynchronously generate singletons", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -0,1 +1,2 @@ | ||
[![build status](https://secure.travis-ci.org/crcn/asyngleton.js.png)](http://travis-ci.org/crcn/asyngleton.js) | ||
### Example | ||
@@ -86,2 +87,34 @@ | ||
- `name` - the name of the singleton in the dictionary | ||
- `factory` - the factory method incase the singleton doesn't exist | ||
- `factory` - the factory method incase the singleton doesn't exist | ||
### [Structr](/crcn/structr.js) Integration | ||
```javascript | ||
var structr = require("structr"); | ||
structr.mixin(require("asyngleton")); | ||
var TestClass = structr({ | ||
/** | ||
*/ | ||
"singleton load": function(onLoad) { | ||
fs.readFile(__dirname + "/config.json", onLoad); | ||
} | ||
}); | ||
var test = new TestClass(); | ||
test.load(function(config) { | ||
}); | ||
//fs.readFile is NOT called again at this point | ||
test.load(function(config) { | ||
}); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5258
7
119
118