Repository navigation
cytoscape-style: drop lodash for small local memoize and throttle - #15
Merged
Merged
Conversation
lodash is CommonJS, so the library's named imports of it carried the whole of lodash (about 73 KB) into every app bundle that used the library -- including WebsiteAngular's embeddable diagram, which is over its size target (reactome/WebsiteAngular#356). Four functions were used: - isArray, isNumber: Array.isArray and typeof === 'number' (what lodash's do). - memoize: util/memoize.ts, keyed on the first argument or a resolver, with a Map as `cache` (callers clear it). memoize.spec.ts runs the same checks against lodash's and ours. - throttle: util/throttle.ts, a port of lodash's algorithm (debounce with leading, trailing, maxWait = wait). throttle.spec.ts compares the two call for call over fixed and seeded irregular timings; a simpler fixed-window version failed it ("a call just after a window": lodash runs at 1001 and 1200, it ran at 1000 and 1500), which is why it is a port. lodash is no longer a peer dependency of ngx-reactome-cytoscape-style. ngx-reactome-diagram still uses it and keeps its own dependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Review (subagent, adversarial): no defects. The throttle port matches lodash 4.18.1's debounce/throttle branch for branch (first call, maxWait branch, shouldInvoke incl. sinceCall < 0, remainingWait, trailing edge, re-entrancy), and memoize matches lodash's keying (SameValueZero, object identity, cache.has so undefined results are remembered). The specs were broken four ways on purpose and caught each. One gap closed in the latest commit: the spec now also covers the clock going backwards (shown failing with the sinceCall < 0 check removed) and fn calling the throttled function again. Noted, not changed here: CROSS is keyed only on size and never cleared, so after a theme change the cross keeps its old colours -- as it did with lodash. |
This was referenced Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ngx-reactome-cytoscape-styleimported four functions from lodash. lodash is CommonJS, so those named imports carried the whole library (about 73 KB) into every app bundle that uses this one. That includes WebsiteAngular's embeddable diagram, which is over its size target (reactome/WebsiteAngular#356).isArray,isNumberArray.isArray,typeof x === 'number'. This is what lodash's versions do.memoizeutil/memoize.ts. It keys on the first argument or on a resolver, with aMapascache, sincestyle.tsandclearDrawersCacheclear it.throttleutil/throttle.ts, a port of lodash's algorithm: debounce with leading, trailing andmaxWait = wait.Held to lodash's behaviour.
memoize.spec.tsandthrottle.spec.tsrun the same checks against lodash's functions and ours. The throttle spec compares the two call for call: five hand-picked call sequences and four seeded irregular ones, the way render events arrive.lodash is no longer a peer dependency of this library.
ngx-reactome-diagramstill uses it and keeps its own dependency. The builtfesm2022bundle has no lodash import.Checks: tests 29/29, and preflight passes (lockfile, format, libraries, lint, dead code, tests, demo build, pack).
🤖 Generated with Claude Code