-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LRUCache/LRUMap family -- inspect and toString improvements #187
base: master
Are you sure you want to change the base?
Conversation
41d5464
to
839c3cf
Compare
* LRUCache and family .inspect limits its output -- showing the youngest items, and ellipsis, and the oldest item. Options allow dumping the raw object or controlling the size of output (and the number of items a console.log will mindlessly iterate over). * LRUCache and family all have inspect wired up to the magic 'nodejs.util.inspect.custom' symbol property that drives console.log output * LRUCache and family all have a summaryString method returning eg 'LRUCache[8/200]' for a cache with size 8 and capacity 200, wired to the magic Symbol.toStringTag property that drives string interpolation (partially addresses Yomguithereal#129).
@@ -302,6 +303,7 @@ function makeTests(Cache, name) { | |||
assert.equal(dead, missingMarker); | |||
|
|||
cache.set('one', 'uno'); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the fact that the maintainer is present but busy, if you want your changes to be merged, I would recommend to split them into smaller code changes like:
- One PR for #.isEqual addition on Set and related test code cleanups
- One PR for isString() improvements
- One PR for inspect() improvements
- One PR for eslint enhancements
That would permit the maintainer to review the code changes broken into more logical pieces
* If possible, attaching the | ||
* * #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`) | ||
* * the summaryString method to Symbol.toStringTag (allowing `\`${cache}\`` to work) | ||
* * the inspect method to Symbol.for('nodejs.util.inspect.custom') (making `console.log(cache)` liveable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why two level of comments? One is enough I guess.
|
||
/** | ||
* If possible, attaching the | ||
* * #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* * #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`) | |
* #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`) |
/** | ||
* If possible, attaching the | ||
* * #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`) | ||
* * the summaryString method to Symbol.toStringTag (allowing `\`${cache}\`` to work) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* * the summaryString method to Symbol.toStringTag (allowing `\`${cache}\`` to work) | |
* the summaryString method to Symbol.toStringTag (allowing `\`${cache}\`` to work) |
* If possible, attaching the | ||
* * #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`) | ||
* * the summaryString method to Symbol.toStringTag (allowing `\`${cache}\`` to work) | ||
* * the inspect method to Symbol.for('nodejs.util.inspect.custom') (making `console.log(cache)` liveable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* * the inspect method to Symbol.for('nodejs.util.inspect.custom') (making `console.log(cache)` liveable) | |
* the inspect method to Symbol.for('nodejs.util.inspect.custom') (making `console.log(cache)` liveable) |
* If possible, attaching the | ||
* * #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`) | ||
* * the summaryString method to Symbol.toStringTag (allowing `\`${cache}\`` to work) | ||
* * the inspect method to Symbol.for('nodejs.util.inspect.custom') (making `console.log(cache)` liveable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
@@ -5,7 +5,7 @@ | |||
"scripts": { | |||
"lint": "eslint --cache ./*.js ./utils ./test", | |||
"lint:fix": "eslint --cache --fix ./*.js ./utils ./test", | |||
"prepublishOnly": "npm run lint && npm test && npm run test:types", | |||
"prepublishOnly": "npm run lint && npm test && npm run test:types && echo 'Success! All checks passed!'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt that kind of changes is really expected in such a PR :D
The current inspect will put the entire contents of its key/value set onto the screen, causing voluminous dump and/or hiding the end of the contents, and makes it harder to examine its internals. This makes all the LRU classes inherit the method properly; tastefully limits the output while showing both the head and tail; and has an
all: true
trap door to get a shallow copy of the cache as a POJO.