Closed YuriGor closed 5 years ago
Due to lack of feedback I started discussion in this Lodash issue Welcome anybody, who have anything to say.
To mimic native js array methods predicates but still have it usable I decided to have this predicate signature:
(value, key|index, parentValue, context)
where context
is an object with fields:
path
- path to current valueparent
- object with the current parent's value
, key|index
, path
, parent
parents
- array with all parent objects from the current to the root. parent
object listed above is just the last element of this arrayobj
- source objectdepth
- current value's nested levelnext three fields are available if options.checkCircular
was true
, otherwise they will be undefined
isCircular
- true if the current value is a circular reference.circularParent
- parent object from parents
array referenced by current value or null if not isCircular
.circularParentIndex
- index of circularParent
in the parents array or -1
I received good feedback, I agree with. Iteratee should have less arguments, now it's hard to remember right order, also code looks unreadable when last argument needed.
value
,key
, may be sourcecollection
will be enough, same as in Lodash. Rest of arguments such aspath
,depth
,parent*
should be passed as fields of single objectcontext
orproperties
. It will be breaking change, so I need to think twice.