Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mrflip
Copy link
Contributor

@mrflip mrflip commented Aug 7, 2022

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.

  • 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 Support toStringTag #129).

@mrflip mrflip force-pushed the LRUInspection branch 3 times, most recently from 41d5464 to 839c3cf Compare August 7, 2022 01:42
@mrflip mrflip marked this pull request as draft August 7, 2022 05:17
@mrflip mrflip marked this pull request as ready for review August 8, 2022 23:12
* 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');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor

@jerome-benoit jerome-benoit left a 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)
Copy link
Contributor

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) { ... }`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* * #.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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* * 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* * 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)
Copy link
Contributor

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!'",
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants