Skip to content

Commit

Permalink
feat: only one parameter in the constructor
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Instead of `new KeyvLru(100, {...})` use `new KeyvLru({ max: 100, ... }`.
  • Loading branch information
Mateu Aguiló Bosch committed Jun 15, 2018
1 parent 931bb4d commit 5eb1014
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .emdaer/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ Create your Keyv object by executing:

```js
const options = {
max: 1000,
notify: false,
ttl: 0,
expire: 0,
};
const keyvLru = new KeyvLru(max, options);
const keyvLru = new KeyvLru(options);
```

See [`tiny-lru`](https://www.npmjs.com/package/tiny-lru) to learn about the
Expand Down
6 changes: 3 additions & 3 deletions src/KeyvLru.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class KeyvLru implements MapInterface {
cache: Object;

constructor(
max: number,
options: {
max: number,
notify?: boolean,
ttl?: number,
expire?: number,
} = {}
} = { max: 500 }
) {
this.cache = lru(max, options.notify, options.ttl, options.expire);
this.cache = lru(options.max, options.notify, options.ttl, options.expire);
}

clear(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/KeyvLru.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const KeyvLru = require('./KeyvLru');
describe('KeyvLru', () => {
test('constructor', () => {
expect.assertions(2);
const sut = new KeyvLru(1);
const sut = new KeyvLru();
expect(sut.cache).not.toBeUndefined();
expect(sut).toBeInstanceOf(KeyvLru);
});
describe('KeyvLru methods', () => {
let sut;

beforeEach(() => {
sut = new KeyvLru(100);
sut = new KeyvLru({ max: 100 });
});

afterEach(() => {
Expand Down

0 comments on commit 5eb1014

Please sign in to comment.