@leapfrogtechnology/async-store
Advanced tools
Comparing version
# Change Log | ||
## [1.0.2](https://github.com/leapfrogtechnology/async-store/tree/1.0.2) (2019-07-31) | ||
[Full Changelog](https://github.com/leapfrogtechnology/async-store/compare/1.0.1...1.0.2) | ||
**Closed Issues** | ||
- Make store.getId\(\) fail-safe [\#15](https://github.com/leapfrogtechnology/async-store/issues/15) | ||
**Changes** | ||
- Add isInitialized\(\) doc [\#19](https://github.com/leapfrogtechnology/async-store/pull/19) [[documentation](https://github.com/leapfrogtechnology/async-store/labels/documentation)] ([cham11ng](https://github.com/cham11ng)) | ||
- Add test cases for getId\(\) method [\#18](https://github.com/leapfrogtechnology/async-store/pull/18) [[test](https://github.com/leapfrogtechnology/async-store/labels/test)] ([cham11ng](https://github.com/cham11ng)) | ||
- Minor improvements on the documentation [\#12](https://github.com/leapfrogtechnology/async-store/pull/12) [[documentation](https://github.com/leapfrogtechnology/async-store/labels/documentation)] ([kabirbaidhya](https://github.com/kabirbaidhya)) | ||
## [1.0.1](https://github.com/leapfrogtechnology/async-store/tree/1.0.1) (2019-07-19) | ||
@@ -4,0 +17,0 @@ [Full Changelog](https://github.com/leapfrogtechnology/async-store/compare/1.0.0...1.0.1) |
{ | ||
"name": "@leapfrogtechnology/async-store", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Global store utility for an async operation lifecycle and chain of callbacks", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -31,4 +31,6 @@ # Async Store | ||
store.initialize()(callback); | ||
function callback() { | ||
store({ foo: 'Hello', bar: 'World' }); | ||
store.set({ foo: 'Hello', bar: 'World' }); | ||
@@ -40,3 +42,3 @@ Promise.resolve() | ||
.then(() => { | ||
console.log('Value of foo: ', store.get('foo')); | ||
console.log('Value of bar: ', store.get('bar')); | ||
}) | ||
@@ -47,8 +49,5 @@ .then(() => { | ||
.then(() => { | ||
// Store value is available at the end of the promise chain. | ||
console.log('Value of foo: ', store.get('foo')); | ||
console.log('Value of bar: ', store.get('bar')); | ||
}); | ||
} | ||
store.initialize()(callback); | ||
``` | ||
@@ -61,4 +60,6 @@ | ||
store.initialize()(callback); | ||
function callback() { | ||
store({ foo: 'Hello', bar: 'World' }); | ||
store.set({ foo: 'Hello', bar: 'World' }); | ||
@@ -70,11 +71,11 @@ Promise.resolve() | ||
.then(() => { | ||
console.log('Value of bar: ', store.get('bar')); | ||
}) | ||
.then(() => { | ||
console.log('Value of foo: ', store.get('foo')); | ||
}) | ||
.then(() => { | ||
// Store value is available at the end of the promise chain. | ||
console.log('Value of foo: ', store.get('foo')); | ||
console.log('Value of bar: ', store.get('bar')); | ||
}); | ||
} | ||
store.initialize()(callback); | ||
``` | ||
@@ -103,3 +104,3 @@ | ||
const reqId = store.get('reqId'); | ||
console.log(`[${reqId}]`); | ||
console.log(`Request Id: ${reqId}`); | ||
@@ -118,2 +119,19 @@ res.json({ message: 'Hello World' }); | ||
### initialize() | ||
Initialize the async store based on the adapter provided. | ||
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]` - Async store adapter to use. | ||
- `@returns {(params: AsyncStoreParams) => void}` - Returns a function that takes a callback which will be triggered once the store has been initialized. | ||
```js | ||
const store = require('@leapfrogtechnology/async-store'); | ||
store.initialize()(callback); | ||
function callback() { | ||
// Do something with the store. | ||
} | ||
``` | ||
### initializeMiddleware() | ||
@@ -123,4 +141,4 @@ | ||
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]`: Store adapter. | ||
- `@returns {(req, res, next) => void}` | ||
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]` - Async store adapter to use. | ||
- `@returns {(req, res, next) => void}` - Returns the express middleware function. | ||
@@ -135,7 +153,19 @@ ```js | ||
### isInitialized() | ||
Check if the store has been initialized or not. | ||
- `@returns {boolean}` - Returns either true or false. | ||
```js | ||
if (store.isInitialized()) { | ||
// Do something. | ||
} | ||
``` | ||
### set() | ||
It sets properties in the store. | ||
Persists properties in the store. | ||
- `@params {any} properties`: Properties to set in store. | ||
- `@params {any} properties` - Persist properties to set in store. | ||
- `@returns {void}` | ||
@@ -149,6 +179,6 @@ | ||
It gets a value by a key from the store. | ||
Gets a value by a key from the store. | ||
- `@params {string} key`: Key specifies property of store. | ||
- `@returns {any}` | ||
- `@params {string} key` - Key to get from the store. | ||
- `@returns {any}` - Returns the value persisted in the store by `key` which could be `null` if key not found. Any error caught during the retrieval will be thrown and cascaded. | ||
@@ -161,6 +191,6 @@ ```js | ||
It gets a value by a key from the store. If anything fails, it returns null without emitting error event. | ||
Gets a value by a key from the store. If anything fails, it returns `null` without emitting error event. | ||
- `@params {string} key`: Key specifies property of store. | ||
- `@returns {any}` | ||
- `@params {string} key` - Key to get from the store. | ||
- `@returns {any}` - Returns the value persisted in the store by `key` which could be `null` if key not found. Any error caught during the retrieval will be supressed and `null` value is returned. | ||
@@ -171,2 +201,13 @@ ```js | ||
### getId() | ||
Gets the unique store id created for the current context/scope. | ||
Example: If used in express, it returns unique store id per request. | ||
- `@returns {string | undefined}` - Returns the unique store id. | ||
```js | ||
const requestIdentifier = store.getId(); | ||
``` | ||
## Changelog | ||
@@ -173,0 +214,0 @@ |
36009
6.81%212
23.98%