Comparing version 0.2.1 to 0.3.0
@@ -1,51 +0,25 @@ | ||
<a name="0.2.1"></a> | ||
## [0.2.1](https://github.com/w33ble/carafe/compare/v0.1.2...v0.2.1) (2018-04-12) | ||
### Changelog | ||
#### [v0.3.0](https://github.com/w33ble/carafe/compare/v0.2.1...v0.3.0) (18 April 2018) | ||
- docs: update the readme [`cab3ba3`](https://github.com/w33ble/carafe/commit/cab3ba3b490740faf6a8ad99b4cb68b4c7385462) | ||
- feat: log warning about replacement type mismatch [`4c0da58`](https://github.com/w33ble/carafe/commit/4c0da5822d3672c886bc93c846686ca6c575191f) | ||
- docs: update changelog [`216458d`](https://github.com/w33ble/carafe/commit/216458d5c3f91749df19b2bc56be42529b2bbed4) | ||
- feat: make replacement optional, opt-in [`d3d10d7`](https://github.com/w33ble/carafe/commit/d3d10d745e2461eb848b4127a9e8b82570f183d6) | ||
- docs: fix quick example [`be9de00`](https://github.com/w33ble/carafe/commit/be9de0046c814f789999010a8d24aa436303f551) | ||
### Bug Fixes | ||
#### [v0.2.1](https://github.com/w33ble/carafe/compare/v0.1.2...v0.2.1) (11 April 2018) | ||
- fix: rename add to register [`c3be9e2`](https://github.com/w33ble/carafe/commit/c3be9e24e17507ac61ffff0cc0c5ca32ea044930) | ||
- feat: inject at call time, pass extra args [`aea0e5c`](https://github.com/w33ble/carafe/commit/aea0e5c2f586efa278b078489010a7ae852a726b) | ||
- docs: update the readme for the inject function [`7a1ce9d`](https://github.com/w33ble/carafe/commit/7a1ce9dfade1b28861fa1143e4d2fc16702dcba0) | ||
* rename add to register ([c3be9e2](https://github.com/w33ble/carafe/commit/c3be9e2)) | ||
#### [v0.1.2](https://github.com/w33ble/carafe/compare/v0.1.1...v0.1.2) (10 April 2018) | ||
- feat: add inject method, with tests [`6902e23`](https://github.com/w33ble/carafe/commit/6902e23c137fbb8e60c8c2d0991d8316f0bb9282) | ||
- docs: update readme with method use [`0e5751d`](https://github.com/w33ble/carafe/commit/0e5751d54a8e91df11b6bb3d1acb83bc7f83d04c) | ||
#### [v0.1.1](https://github.com/w33ble/carafe/compare/v0.1.0...v0.1.1) (9 April 2018) | ||
- deps: switch to esm from @std/esm [`c375dcf`](https://github.com/w33ble/carafe/commit/c375dcf8c21b5ff7550499f060250fa69b39fdba) | ||
### Features | ||
#### v0.1.0 (9 April 2018) | ||
- feat: working dependency manager [`a4a637c`](https://github.com/w33ble/carafe/commit/a4a637c775ba8c9d936c7ac6079611d411cb639d) | ||
- initial commit [`ef82303`](https://github.com/w33ble/carafe/commit/ef8230317c07c79cc95f2c50d45f339d62d525d2) | ||
* inject at call time, pass extra args ([aea0e5c](https://github.com/w33ble/carafe/commit/aea0e5c)) | ||
### BREAKING CHANGES | ||
* this completely changes what inject returns, but also makes it a lot more useful now that the dependencies can be replaced | ||
* public api change, add became register | ||
<a name="0.1.2"></a> | ||
## [0.1.2](https://github.com/w33ble/carafe/compare/v0.1.1...v0.1.2) (2018-04-11) | ||
### Features | ||
* add inject method, with tests ([6902e23](https://github.com/w33ble/carafe/commit/6902e23)) | ||
<a name="0.1.1"></a> | ||
## [0.1.1](https://github.com/w33ble/carafe/compare/v0.1.0...v0.1.1) (2018-04-11) | ||
### Dependencies | ||
* switch to esm from [@std](https://github.com/std)/esm ([c375dcf](https://github.com/w33ble/carafe/commit/c375dcf)) | ||
<a name="0.1.0"></a> | ||
# [0.1.0](https://github.com/w33ble/carafe/compare/a4a637c...v0.1.0) (2018-04-10) | ||
### Features | ||
* working dependency manager ([a4a637c](https://github.com/w33ble/carafe/commit/a4a637c)) | ||
{ | ||
"name": "carafe", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Crazy simple dependency container", | ||
@@ -9,6 +9,6 @@ "module": "index.mjs", | ||
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"version": "npm run changelog", | ||
"version": "auto-changelog -p && git add CHANGELOG.md", | ||
"test": "npm run lint && npm run test:only", | ||
"test:only": "nyc --require esm node test/index.mjs" | ||
"test:only": "nyc --require esm node test/index.mjs", | ||
"prepush": "npm run test" | ||
}, | ||
@@ -19,3 +19,10 @@ "repository": { | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"dependency", | ||
"dependency injection", | ||
"di", | ||
"inversion of control", | ||
"ioc", | ||
"ioc container" | ||
], | ||
"files": [ | ||
@@ -50,2 +57,8 @@ "src/", | ||
}, | ||
"auto-changelog": { | ||
"output": "CHANGELOG.md", | ||
"template": ".changelog_template.hbs", | ||
"ignoreCommitPattern": "(chore|test):", | ||
"commitLimit": false | ||
}, | ||
"dependencies": { | ||
@@ -55,4 +68,4 @@ "esm": "^3.0.17" | ||
"devDependencies": { | ||
"auto-changelog": "^1.4.6", | ||
"codecov": "^3.0.0", | ||
"conventional-changelog-cli": "^1.3.21", | ||
"eslint": "^4.9.0", | ||
@@ -59,0 +72,0 @@ "eslint-config-airbnb": "^16.1.0", |
@@ -9,5 +9,5 @@ # carafe | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/w33ble/carafe/master/LICENSE) | ||
[![npm](https://img.shields.io/npm/v/carafe.svg)](https://www.npmjs.com/package/carafe) | ||
[![Build Status](https://img.shields.io/travis/w33ble/carafe.svg?branch=master)](https://travis-ci.org/w33ble/carafe) | ||
[![Coverage](https://img.shields.io/codecov/c/github/w33ble/carafe.svg)](https://codecov.io/gh/w33ble/carafe) | ||
[![npm](https://img.shields.io/npm/v/carafe.svg)](https://www.npmjs.com/package/carafe) | ||
[![Project Status](https://img.shields.io/badge/status-experimental-orange.svg)](https://nodejs.org/api/documentation.html#documentation_stability_index) | ||
@@ -22,20 +22,58 @@ | ||
```js | ||
// simple dependency providing | ||
// provider.mjs | ||
import Carafe from 'carafe' | ||
const container = new Carafe(); | ||
container.add('water', () => 'fresh and cool'); | ||
container.register('water', 'fresh and cool'); | ||
export default container; | ||
// elsewhere.mjs | ||
// status.mjs | ||
import container from 'provider.mjs'; | ||
const water = container.get('water'); | ||
return water(); // fresh and cool | ||
// in your tests... | ||
// get happens in the function so it always gets the current value | ||
const waterStatus = () => container.get('water')(); | ||
export default waterStatus; | ||
// status.mjs, alternatively using inject | ||
import container from 'provider.mjs'; | ||
import elsewhere from 'elsewhere.mjs'; | ||
container.replace('water', () => 'mock water'); | ||
elsewhere(); // mock water | ||
// the function returned always gets the updated dependency | ||
const waterStatus = container.inject(['water'], (water) => water); | ||
export default waterStatus; | ||
// consumer.mjs | ||
import status from 'status.mjs'; | ||
console.log(status()); // fresh and cool | ||
``` | ||
You can also opt in to dependency replacement by passing true as the only argument to Carafe. | ||
```js | ||
// dependency replacement | ||
// provider.mjs | ||
import Carafe from 'carafe' | ||
const allowReplace = process.env.NODE_ENV === 'test'; // optionally enable replacement | ||
const container = new Carafe(allowReplace); | ||
container.register('water', 'fresh and cool'); | ||
export default container; | ||
// status.mjs does not change | ||
const waterStatus = container.inject(['water'], (water) => water); | ||
export default waterStatus; | ||
// then in your tests... | ||
import container from 'provider.mjs'; | ||
import status from 'status.mjs'; | ||
container.replace('water', 'mock water'); | ||
console.log(status()); // mock water | ||
container.restore('water'); // or to restore all mocks, use restore() | ||
elsewhere(); // fresh and cool | ||
console.log(status()); // fresh and cool | ||
``` | ||
@@ -45,22 +83,30 @@ | ||
Carafe instances should be `new`ed up, and the instance returns will have the following methods. You can call Carafe() as well, and it will return a new instance for you. | ||
Carafe instances should be `new`ed up, and the instance returned will have the following methods. You can call Carafe() as well, and it will return a new instance for you. | ||
### register(name, payload) | ||
### Carafe([enableReplacement]) | ||
Creates and returns a new instance of Carafe. If `enableReplacement` is true, dependencies can be replaced. | ||
#### register(name, payload) | ||
Registered a new dependency by name. `name` should be a string, and the method will throw if it's not. | ||
### get(name) | ||
#### get(name) | ||
Returns a registered dependency by name. If there is no matching depdendency, the method will throw. | ||
### inject(dependencies[], function) | ||
#### inject(dependencies[], function) | ||
Takes an array of named depdendencies, passing them in order as arguments to `function`. Returns the original `function` with the depdendencies partially applied. | ||
### replace(name, payload) | ||
#### replace(name, payload) | ||
*Only available if `enableReplacement` is true* | ||
Used to replace a dependency's value in a recoverable way. `replace` can be called multiple times, and the resulting value when `get` is used will always be whatever the last value provided was. Use `restore` to restore the original dependency's payload. | ||
### restore([name]) | ||
#### restore([name]) | ||
*Only available if `enableReplacement` is true* | ||
Used to restore a given dependency to its original registered value, undoing any `replace` calls. If no name is provided, *all* dependencies are restored. | ||
@@ -67,0 +113,0 @@ |
Sorry, the diff of this file is not supported yet
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
11836
80
113