Comparing version 0.3.0 to 0.3.1
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
// A dependency injection container, holding all modules, mocks and dependencies. | ||
@@ -19,3 +21,4 @@ var Flacon = function () { | ||
if (module.cache === notCached) { | ||
var hasMocks = Object.keys(mocks).length > 0; | ||
if (module.cache === notCached || hasMocks) { | ||
// merge dependencies and mocks | ||
@@ -29,3 +32,4 @@ deps = module.deps.map(function (id) { | ||
}); | ||
module.cache = module.factory.apply(null, deps); | ||
if (hasMocks) return module.factory.apply({}, deps); | ||
module.cache = module.factory.apply({}, deps); | ||
} | ||
@@ -32,0 +36,0 @@ |
{ | ||
"name": "flacon", | ||
"description": "A hyperminimal dependency injection framework.", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "files": ["index.js", "readme.md"], |
@@ -88,3 +88,3 @@ # flacon | ||
During testing, we can easily **manipulate or mock a dependency**. | ||
During testing, we can easily **manipulate or mock a dependency**. Note that this loads the module without caching. | ||
@@ -116,4 +116,31 @@ ```js | ||
## API | ||
### `flacon(id, [mocks])` | ||
Loads a module by `id`. Returns the module. | ||
If `mocks` are passed, they will be used to instead of its dependencies. Otherwise the module will be cached. | ||
- `id`: The identifier, unique to the container. | ||
- `mocks`: A map of callbacks, mapped by module `id`. The return value of each callback will be the mock. | ||
### `flacon.publish(id, [deps], factory)` | ||
Registers a module by `id`. Returns the module's `factory`. | ||
- `id`: The identifier, unique to the container. | ||
- `deps`: An optional array of dependency `id`s. Their corresponding modules will be passed into `factory`. | ||
- `factory`: A function, taking the dependencies, that returns the module. | ||
### `flacon.flush()` | ||
Removes a module from the cache. Returns the container. | ||
- `id`: The identifier, unique to the container. | ||
## Contributing | ||
If you **have a question**, **found a bug** or want to **propose a feature**, have a look at [the issues page](https://github.com/derhuerst/flacon/issues). |
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
7364
54
145