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

ref(utils): convert memo from class to function #4283

Merged
merged 2 commits into from
Dec 14, 2021
Merged

Conversation

AbhiPrasad
Copy link
Member

Unnecessary class, we can just store the private state in a closure. It's only being used by one method, walk in @sentry/utils.

@AbhiPrasad AbhiPrasad added this to the Treeshaking / Bundle Size milestone Dec 14, 2021
@@ -303,7 +303,7 @@ export function walk(key: string, value: any, depth: number = +Infinity, memo: M
const acc = Array.isArray(value) ? [] : {};

// If we already walked that branch, bail out, as it's circular reference
if (memo.memoize(value)) {
if (memo[0](value)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

taking the reacts hook approach to being minification friendly (return a tuple) 😄

@github-actions
Copy link
Contributor

github-actions bot commented Dec 14, 2021

size-limit report

Path Base Size (f9fb1d6) Current Size Change
@sentry/browser - CDN Bundle (gzipped) 21.41 KB 21.39 KB -0.09% 🔽
@sentry/browser - CDN Bundle (minified) 70.06 KB 69.9 KB -0.24% 🔽
@sentry/browser - Webpack 23.2 KB 23.15 KB -0.22% 🔽
@sentry/browser - Webpack - gzip = false 81.27 KB 81.05 KB -0.28% 🔽
@sentry/react - Webpack 23.24 KB 23.19 KB -0.22% 🔽
@sentry/nextjs Client - Webpack 47.83 KB 47.78 KB -0.12% 🔽
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 29.73 KB 29.69 KB -0.14% 🔽

Copy link
Member

@mitsuhiko mitsuhiko left a comment

Choose a reason for hiding this comment

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

This looks good. Out of curiosity I wonder though what the impact of using {memoize, unmemoize}: MemoFunc = memoBuilder() would be instead of m[0] and m[1].

@AbhiPrasad
Copy link
Member Author

This looks good. Out of curiosity I wonder though what the impact of using {memoize, unmemoize}: MemoFunc = memoBuilder() would be instead of m[0] and m[1].

Goes to 81.08 KB from 81.05 KB.

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