Specify memoized function name
raineorshine opened this issue · 6 comments
Unfortunately, function.name
is a read-only property, so I can't do much to customize it. Unless devtools supports a special property (like displayName
in React Devtools) not much that can be done.
Actually I did a little research, and it looks like I can set it via Object.defineProperty
since ES2015. I'll play with this, but if I can get it working it'll be something like memoized(ORIGINAL_FUNCTION_NAME)
.
I've created the above PR to add support for this, but I was hoping on some feedback prior to merging and publishing.
Right now the priority of possible names are:
- Original function name
profileName
, if provided- Generic "anonymous" ultimate fallback
I'm curious if profileName
should get priority over the original function name. I can see the argument that it is a unique identifier of the function, and since the primary purpose is to map in dev tools then it would naturally map to a different developer tools (profiling). Thoughts?
EDIT: and follow-up ... should displayName
on moized components also be considered in this priority list? To-date it is not, although it is when determining the moized component's own displayName
.
Awesome, thanks for looking into this! I'll take a look at the PR.
I believe displayName
has been deprecated and Object.defineProperty
to set name
is the recommended approach.
displayName
is specific to React components (still a common convention there).
Alright I have published this change in 6.1.0
. Let me know if you have any more issues!