Skip to content

Commit

Permalink
Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 14, 2023
1 parent 2a8997e commit 6bc7032
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Options<
CacheKeyType,
> = {
/**
Milliseconds until the cache expires.
Milliseconds until the cache entry expires.
@default Infinity
*/
Expand Down
20 changes: 10 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ By default, only the first argument is compared via exact equality (`===`) to de
```js
import memoize from 'memoize';

const power = memoize((a, b) => Math.power(a, b));
const pow = memoize((a, b) => Math.pow(a, b));

power(2, 2); // => 4, stored in cache with the key 2 (number)
power(2, 3); // => 4, retrieved from cache at key 2 (number), it's wrong
pow(2, 2); // => 4, stored in cache with the key 2 (number)
pow(2, 3); // => 4, retrieved from cache at key 2 (number), it's wrong
```

You will have to use the `cache` and `cacheKey` options appropriate to your function. In this specific case, the following could work:

```js
import memoize from 'memoize';

const power = memoize((a, b) => Math.power(a, b), {
const pow = memoize((a, b) => Math.pow(a, b), {
cacheKey: arguments_ => arguments_.join(',')
});

power(2, 2); // => 4, stored in cache with the key '2,2' (both arguments as one string)
power(2, 3); // => 8, stored in cache with the key '2,3'
pow(2, 2); // => 4, stored in cache with the key '2,2' (both arguments as one string)
pow(2, 3); // => 8, stored in cache with the key '2,3'
```

More advanced examples follow.
Expand All @@ -120,7 +120,7 @@ const heavyMemoizedOperation = memoize(heavyOperation);

heavyMemoizedOperation({full: true}); // Stored in cache with the object as key
heavyMemoizedOperation({full: true}); // Stored in cache with the object as key, again
// The objects look the same but for JS they're two different objects
// The objects appear the same, but in JavaScript, they're different objects
```

You might want to serialize or hash them, for example using `JSON.stringify` or something like [serialize-javascript](https://github.com/yahoo/serialize-javascript), which can also serialize `RegExp`, `Date` and so on.
Expand Down Expand Up @@ -161,7 +161,7 @@ const addOneListener = memoize(addListener, {
});

addOneListener(header, 'click', console.log); // `addListener` is run, and it's cached with the `arguments` array as key
addOneListener(header, 'click', console.log); // `addListener` is not run again
addOneListener(header, 'click', console.log); // `addListener` is not run again because the arguments are the same
addOneListener(mainContent, 'load', console.log); // `addListener` is run, and it's cached with the `arguments` array as key
```

Expand All @@ -186,7 +186,7 @@ Type: `object`
Type: `number`\
Default: `Infinity`

Milliseconds until the cache expires.
Milliseconds until the cache entry expires.

##### cacheKey

Expand All @@ -209,7 +209,7 @@ Use a different cache storage. Must implement the following methods: `.has(key)`

Refer to the [caching strategies](#caching-strategy) section for more information.

### memDecorator(options)
### memoizeDecorator(options)

Returns a [decorator](https://github.com/tc39/proposal-decorators) to memoize class methods or static class methods.

Expand Down

0 comments on commit 6bc7032

Please sign in to comment.