Uh oh!
There was an error while loading. Please reload this page.
⚛️Add idx in babel-preset - #1874
Conversation
Idx is the existential function see https://facebook.github.io/react-native/blog/2017/03/13/idx-the-existential-function.html for more informations about it.
facebook-github-bot
commented
Mar 21, 2017
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions. |
facebook-github-bot
commented
Mar 21, 2017
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
gaearon
commented
Mar 21, 2017
Let's do it. |
gaearon
commented
Mar 21, 2017
Hmm. Actually I'm concerned that Babel plugin doesn't verify Can you please raise an issue about this in |
pierr
commented
Mar 21, 2017
Ok i will do this. Thanks for your quick reply. |
This will allow the use of the preset.
@gaearon If fact there is no ambiguity, as importidxfrom'idx'constprops={user: {friends :[{friends: 1}]}}idx(props,_=>_.user.friends[0].friends)
And i have been able to use [1,2,4].map((a,idx)=>console.log('idx',idx)) |
gaearon
commented
Mar 22, 2017
What happens if the user writes functionidx(){// my own code}vara=idx();Isn't Babel plugin going to change the function meaning? |
pierr
commented
Mar 22, 2017
Isn't it redundant for those who already use Lodash? varprops={user: {friends: [{friends: ['yo']}]}}_.has(props,'user.friends[0].friends')// true_.get(props,'user.friends[0].friends')// ['yo']varprops={user: {friends: []}}_.has(props,'user.friends[0].friends')// false_.get(props,'user.friends[0].friends')// undefined |
viankakrisna
commented
Apr 6, 2017
@ggregoire thanks for the lodash trick! been using it everywhere now :) I think the use case for idx babel plugin is to transform the function calls to nested ternary checks https://facebook.github.io/react-native/blog/2017/03/13/idx-the-existential-function.html not really sure why we need this though (will it make the bundle larger for deeply nested property access?) |
I'd love to have this functionality! I'm writing a very long list of ternary functions on my own and it is tedious and bug prone! This helps greatly when dealing with asynchronously loaded data from APIs you don't control/own. |
wtgtybhertgeghgtwtg
commented
Jan 13, 2018
Correct me if I'm wrong, but shouldn't the optional chaining syntax available with |
gaearon
commented
Jan 13, 2018
We won't enable that proposal unless it advances to 3rd or 4th stages. |
Maybe we shouldn't merge this given the Optional Chaining Operator exists? |
Timer
commented
Jan 13, 2018
I'll close this because there hasn't been much support around it and there's a syntax proposal in the works. Thanks @pierr! |
gaearon
commented
Jan 13, 2018
I think Optional Chaining was somewhat controversial and wouldn't count on it progressing quickly. However, this feature seems like a good fit for babel-plugin-macros support we just merged. |
kentcdodds
commented
Jan 14, 2018
Hey guess what! There's already a macro for it! https://github.com/dralletje/idx.macro Woo! |
Timer
commented
Jan 14, 2018
That's seriously awesome @kentcdodds |
That said, it does need to upgrade to |


Idx is the existential function, it seems to me that it would be a benefit for almost all project using react and data in a graph.
I concidered using eject to add this feature but maybe this be a good add for the community.