Skip to content

Commit 3a4f124

Browse files
authored
Merge pull request #12 from leapfrogtechnology/readme-fix
Minor improvements on the documentation
2 parents f44f851 + 5cbe7fb commit 3a4f124

File tree

1 file changed

+40
-22
lines changed

1 file changed

+40
-22
lines changed

README.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,51 @@ yarn add @leapfrogtechnology/async-store
2828
```js
2929
const store = require('@leapfrogtechnology/async-store');
3030

31+
store.initialize()(callback);
32+
3133
function callback() {
32-
store({ foo: 'Hello', bar: 'World' });
34+
store.set({ foo: 'Hello', bar: 'World' });
3335

3436
Promise.resolve()
3537
.then(() => {
3638
console.log('Value of foo: ', store.get('foo'));
3739
})
3840
.then(() => {
39-
console.log('Value of foo: ', store.get('foo'));
41+
console.log('Value of bar: ', store.get('bar'));
4042
})
4143
.then(() => {
4244
console.log('Value of foo: ', store.get('foo'));
4345
})
4446
.then(() => {
45-
// Store value is available at the end of the promise chain.
46-
console.log('Value of foo: ', store.get('foo'));
47+
console.log('Value of bar: ', store.get('bar'));
4748
});
4849
}
49-
50-
store.initialize()(callback);
5150
```
5251

5352
### TypeScript Example
5453

5554
```js
5655
import * as store from '@leapfrogtechnology/async-store';
5756

57+
store.initialize()(callback);
58+
5859
function callback() {
59-
store({ foo: 'Hello', bar: 'World' });
60+
store.set({ foo: 'Hello', bar: 'World' });
6061

6162
Promise.resolve()
6263
.then(() => {
6364
console.log('Value of foo: ', store.get('foo'));
6465
})
6566
.then(() => {
66-
console.log('Value of foo: ', store.get('foo'));
67+
console.log('Value of bar: ', store.get('bar'));
6768
})
6869
.then(() => {
69-
// Store value is available at the end of the promise chain.
7070
console.log('Value of foo: ', store.get('foo'));
71+
})
72+
.then(() => {
73+
console.log('Value of bar: ', store.get('bar'));
7174
});
7275
}
73-
74-
store.initialize()(callback);
7576
```
7677

7778
### Express Example
@@ -95,7 +96,7 @@ app.use((req, res, next) => {
9596
// Get request Id from store
9697
app.get('/', (req, res) => {
9798
const reqId = store.get('reqId');
98-
console.log(`[${reqId}]`);
99+
console.log(`Request Id: ${reqId}`);
99100

100101
res.json({ message: 'Hello World' });
101102
});
@@ -109,12 +110,29 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`));
109110

110111
## API Docs
111112

113+
### initialize()
114+
115+
Initialize the async store based on the adapter provided.
116+
117+
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]` - Async store adapter to use.
118+
- `@returns {(params: AsyncStoreParams) => void}` - Returns a function that takes a callback which will be triggered once the store has been initialized.
119+
120+
```js
121+
const store = require('@leapfrogtechnology/async-store');
122+
123+
store.initialize()(callback);
124+
125+
function callback() {
126+
// Do something with the store.
127+
}
128+
```
129+
112130
### initializeMiddleware()
113131

114132
Middleware to initialize the async store and make it accessible from all the subsequent middlewares or async operations triggered afterwards.
115133

116-
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]`: Store adapter.
117-
- `@returns {(req, res, next) => void}`
134+
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]` - Async store adapter to use.
135+
- `@returns {(req, res, next) => void}` - Returns the express middleware function.
118136

119137
```js
120138
const express = require('express');
@@ -126,9 +144,9 @@ app.use(store.initializeMiddleware());
126144

127145
### set()
128146

129-
It sets properties in the store.
147+
Persists properties in the store.
130148

131-
- `@params {any} properties`: Properties to set in store.
149+
- `@params {any} properties` - Persist properties to set in store.
132150
- `@returns {void}`
133151

134152
```js
@@ -137,21 +155,21 @@ store.set({ foo: 'Hello', bar: 'World' });
137155

138156
### get()
139157

140-
It gets a value by a key from the store.
158+
Gets a value by a key from the store.
141159

142-
- `@params {string} key`: Key specifies property of store.
143-
- `@returns {any}`
160+
- `@params {string} key` - Key to get from the store.
161+
- `@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.
144162

145163
```js
146164
const foo = store.get('foo');
147165
```
148166

149167
### find()
150168

151-
It gets a value by a key from the store. If anything fails, it returns null without emitting error event.
169+
Gets a value by a key from the store. If anything fails, it returns `null` without emitting error event.
152170

153-
- `@params {string} key`: Key specifies property of store.
154-
- `@returns {any}`
171+
- `@params {string} key` - Key to get from the store.
172+
- `@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.
155173

156174
```js
157175
const foo = store.find('foo');

0 commit comments

Comments
 (0)