wilmoore / selectn.js

Curried property accessor function that resolves deeply-nested object properties via dot/bracket-notation string path while mitigating TypeErrors via friendly and composable API.
https://www.npmjs.com/package/selectn
MIT License
196 stars 16 forks source link

No way to return function as a value #83

Open brianjmiller opened 6 years ago

brianjmiller commented 6 years ago

Was finally looking to upgrade dependencies in an existing project from 0.9.6 (I know, I'm sorry) to latest, and it seems there is no way to return a function as a value. We were using the ability to look up into a deep object structure knowing that the leaf might be a function, but we need the ability to pass arguments to the invocation of that function. Would this ever be considered as an option or should we look at an alternative module? Have I just missed something obvious in the 1.x interface?

wilmoore commented 6 years ago

We were using the ability to look up into a deep object structure knowing that the leaf might be a function

The current functionality; while "cute" is not so helpful for your particular use-case; thought it did fit my use-case perfectly at the time I implemented it.

... but we need the ability to pass arguments to the invocation of that function.

Bad news: This is currently impossible as implemented.

Good news: I'm going to drop the automatic function invocation in v2.

If you want this now, you might consider: https://lodash.com/docs#invoke

Would this ever be considered as an option or should we look at an alternative module? Have I just missed something obvious in the 1.x interface?

See ☝️

brianjmiller commented 6 years ago

Thanks for the reply, no worries. We've since switched to Hoek.reach we were already using Joi anyways, and it works for our simple use case. Thanks for selectn I'll keep it mind for the future.

maranac0d3r commented 5 years ago

@brianjmiller Please check this Repo for returning functions as not executed one.