[Kimchi-devel] [DOUBT] PCI devices companions on UI

Daniel Henrique Barboza danielhb at linux.vnet.ibm.com
Thu Jul 9 14:53:36 UTC 2015


In my opinion the code is using the string pciTitle, with initial value 
= i18n[....], to get
the link, address and link type to all device_types that are 'net' or 
'storage'.

The boolean haveCompanions is set to true if any of the devices are 
'net' or 'storage'. In the
last loop it checks if the boolean is true or false and, if true, it 
changes the infoData attrs
name, product and vendor to the string pciTitle it crreated in the 
previous loop.

Note that it haveCompanions is false it will not execute any of the 
three statements in the loop.
This is a javascript 'perk'*:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators

I am no JS expert but this is a very unorthodox code IMO. Feel free to 
re-factor it to something
simpler (KEEPING THE SAME BEHAVIOR!!).


Daniel


* I've tested it in the Javascript console of Chrome to see how it works:

  > expr1 = false;
< false
 > expr1 && console.log('PRINT ME!!');
< false
 > expr1 = true;
< true
 > expr1 && console.log('PRINT ME!!');
< PRINT ME!!
< undefined

On 07/08/2015 08:16 PM, Ramon Medeiros wrote:
> Hi guys,
>
> i was looking at the code that parses host pci devices and found a 
> loop, that i don't understand what it does. Looking at it, i see a 
> string being created but do not understood which variable will be used 
> on the code. Has someone experience with this part of the code?
>
> https://github.com/kimchi-project/kimchi/blob/master/ui/js/src/kimchi.guest_edit_main.js#L479-L505 
>
>




More information about the Kimchi-devel mailing list