Skip to content

Commit

Permalink
updating readme on addHandler for hooks (#1116)
Browse files Browse the repository at this point in the history
fixes #1114
  • Loading branch information
jaredwray committed Aug 21, 2024
1 parent 75705db commit 5345e05
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/keyv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ import Keyv, { KeyvHooks } from 'keyv';
```js
//PRE_SET hook
const keyv = new Keyv();
keyv.hooks.addListener(KeyvHooks.PRE_SET, (key, value) => console.log(`Setting key ${key} to ${value}`));
keyv.hooks.addHandler(KeyvHooks.PRE_SET, (key, value) => console.log(`Setting key ${key} to ${value}`));

//POST_SET hook
const keyv = new Keyv();
keyv.hooks.addListener(KeyvHooks.POST_SET, (key, value) => console.log(`Set key ${key} to ${value}`));
keyv.hooks.addHandler(KeyvHooks.POST_SET, (key, value) => console.log(`Set key ${key} to ${value}`));
```

In these examples you can also manipulate the value before it is set. For example, you could add a prefix to all keys.

```js
const keyv = new Keyv();
keyv.hooks.addListener(KeyvHooks.PRE_SET, (key, value) => {
keyv.hooks.addHandler(KeyvHooks.PRE_SET, (key, value) => {
console.log(`Setting key ${key} to ${value}`);
key = `prefix-${key}`;
});
Expand Down

0 comments on commit 5345e05

Please sign in to comment.