moleculer icon indicating copy to clipboard operation
moleculer copied to clipboard

Remove usage of _.compact

Open MrAndrewKirillov opened this issue 2 years ago • 3 comments

:memo: Description

:dart: Relevant issues

issue:747

:gem: Type of change

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

:checkered_flag: Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] New and existing unit tests pass locally with my changes
  • [ ] I have commented my code, particularly in hard-to-understand areas

MrAndrewKirillov avatar May 12 '23 09:05 MrAndrewKirillov

@icebob I think creating method for compact is overhead, cause function too small and we haven't to use lodash style. May you describe your point of it, it's easy to add method, but I realy don't understend point of it.

MrDroid1 avatar May 16 '23 19:05 MrDroid1

The lodash compact as the input is not array, or null or undefined. So when I'm using I don't care to check the parameter before add it to function because it will handle and always returns an array. The current solution doesn't handle it, but in a utils function we can do this check as well.

image

icebob avatar May 21 '23 16:05 icebob

The lodash compact as the input is not array, or null or undefined.

Yeah, but this behavior not expected and lodash documentation says you have to use array as a parameter to remove falsy values. I think we should not rely on the behavior of the method, but should proceed from the needs, that is, the method should remove falsy values from the array. fillter(Boolean) do that, remove falsy values from array.

So when I'm using I don't care to check the parameter before add it to function because it will handle and always returns an array

In my opinion, it's a bad idea to rely on a single method and the best solution would be to use monosemantic values and methods using monosemantic values and responses.

MrDroid1 avatar May 23 '23 11:05 MrDroid1