[Bug/Suggestion] `create-instance-plugin` Doesn't Fix Deep Properties with Same Level Lists
Suppose we have the following list:
<span style="color:#323232;">createInstance = {import:create-instance-plugin}
</span><span style="color:#323232;">
</span><span style="color:#323232;">person
</span><span style="color:#323232;"> name = [this.nameList]
</span><span style="color:#323232;"> nameList
</span><span style="color:#323232;"> Salman
</span><span style="color:#323232;"> Manny
</span><span style="color:#323232;"> Rhian
</span><span style="color:#323232;"> age = {31-49}
</span><span style="color:#323232;"> child = [this.child_obj]
</span><span style="color:#323232;"> child_obj
</span><span style="color:#323232;"> name = [this.nameList]
</span><span style="color:#323232;"> nameList
</span><span style="color:#323232;"> Anne
</span><span style="color:#323232;"> Arram
</span><span style="color:#323232;"> Amelia
</span><span style="color:#323232;"> age = {3-17}
</span>
If we output:
<span style="color:#323232;">[p = createInstance(person, "deep"), p.name] [p.age] [p.name] [p.age]
</span>
We can see that it has fixed the name
and the age
property on the instance. However, if we output:
<span style="color:#323232;">[p = createInstance(person, "deep"), p.child.name] [p.child.age] [p.child.name] [p.child.age]
</span>
It would throw undefined
. Now looking at similar list:
<span style="color:#323232;">person
</span><span style="color:#323232;"> name = {Salman|Manny|Rhian}
</span><span style="color:#323232;"> age = {31-49}
</span><span style="color:#323232;"> child = [this.child_obj]
</span><span style="color:#323232;"> child_obj
</span><span style="color:#323232;"> name = {Anne|Arram|Amelia}
</span><span style="color:#323232;"> age = {3-17}
</span><span style="color:#323232;">
</span><span style="color:#323232;">output
</span><span style="color:#323232;"> [p = createInstance(person, "deep"), p.child.name] [p.child.age] [p.child.name] [p.child.age]
</span>
This would have the values fixed and working.
Looking at the code of the create-instance-plugin
, it would only allow the ‘deep’ fixing of properties if there isn’t any items/lists in it. What that means is the following:
<span style="color:#323232;">child_obj
</span><span style="color:#323232;"> name = [this.nameList]
</span><span style="color:#323232;"> nameList
</span><span style="color:#323232;"> Anne
</span><span style="color:#323232;"> Arram
</span><span style="color:#323232;"> Amelia
</span><span style="color:#323232;"> age = {3-17}
</span>
This object/list, has a list ( nameList
) within it as well as properties (name
and age
), while:
<span style="color:#323232;">child_obj
</span><span style="color:#323232;"> name = {Anne|Arram|Amelia}
</span><span style="color:#323232;"> age = {3-17}
</span>
Only has properties. and based on Line 22
of the create-instance-plugin
:
<span style="font-weight:bold;color:#a71d5d;">...
</span><span style="color:#323232;">} </span><span style="font-weight:bold;color:#a71d5d;">else if</span><span style="color:#323232;">(propValue.getPropertyKeys </span><span style="font-weight:bold;color:#a71d5d;">&& </span><span style="color:#323232;">propValue.getPropertyKeys.length </span><span style="font-weight:bold;color:#a71d5d;">> </span><span style="color:#0086b3;">0 </span><span style="font-weight:bold;color:#a71d5d;">&& </span><span style="color:#323232;">propValue.getLength </span><span style="font-weight:bold;color:#a71d5d;">=== </span><span style="color:#0086b3;">0</span><span style="color:#323232;">) {
</span><span style="font-weight:bold;color:#a71d5d;">...
</span>
If the list to be fixed has a list within it other than the properties i.e. propValue.getLength
is not zero, then it wouldn’t fix the properties within it.
The first child_obj
has a nameList
with it, and upon calling propValue.getLength
it would have 1
while the second child_obj
will return a propValue.getLength
of 0
since it doesn’t have any lists.
Thus, the solution for the problem is just removing the propValue.getLength === 0
check OR create another check without it.
TLDR; propValue.getLength === 0
at Line 22
of the create-instance-plugin can be removed to allow properties that rely on same level lists to be fixed. Here is the demo of the problem with a ‘remixed’ create instance plugin with the fix.
Add comment