Model.all() returns LodashWrapper instead of Array.
Is this intended? I need to call .value() on the result to get the Array.
@nrempel Yes it is a lodash wrapper to make operations like map, sort, filter easier.
Ok, that makes sense.
Do you think it would be cleaner to return simply an array since es6 has all of those features now too?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
The only reason I would want a plain Array is because LodashWrapper doesn't contain basic properties like length.
@nrempel I don't see any downsides of using lodash collections, as you can find them handy in many situations.
For length you can make use the method called size(). https://lodash.com/docs#size
Ok, sounds good. Thanks!
If anyone came here trying to figure out why a lodash method would be returning a LodashWrapper, make sure your import statement is like import { filter } from 'lodash' rather than import filter from 'lodash' (I just wasted 45 minutes on this one!)
@andyford Model.all() doesn't return a lodash wrapper anymore, it has been changed in 4.0. Please read the docs here.
@thetutlage my comment was about forgetting the brackets on an import. When I mistakenly left them out (for .filter and for .without), I got the wrapper. I ended up on this page googling for LodashWrapper.
@andyford yup I was stuck for about a minute ~11 days ago too
If anyone came here trying to figure out why a lodash method would be returning a LodashWrapper, make sure your import statement is like
import { filter } from 'lodash'rather thanimport filter from 'lodash'(I just wasted 45 minutes on this one!)
@andyford Thank you very much! I completely forgot the mustaches lol
Most helpful comment
If anyone came here trying to figure out why a lodash method would be returning a LodashWrapper, make sure your import statement is like
import { filter } from 'lodash'rather thanimport filter from 'lodash'(I just wasted 45 minutes on this one!)