H all,
I finally upgraded to the new version
Something strange happened, and I’m not sure it’s actually a bug.
I have a custom function that I use extensively.
It takes two objects and merges them, with support for deep recursion.
After updating to the new ZIM version, the function only worked partially.
With small objects, it overwrote everything without any issue, but with large objects it didn’t traverse all the internal values.
It’s worth noting that I was running it on a very large and complex object.
After I changed the loop to a forEach that iterates over the object’s keys, the function worked correctly.
Is it possible that something changed in the loop behavior?
Maybe there’s some limitation on how many times it can recurse or iterate inward?
Hi @racheli - what version was the loop working on for you and we can do a comparison. Also, any error in the console? The loop uses for loops in behind... so there is no limit. Also, can you paste the code in here so we can test. What kind of objects are you traversing? Let's figure this out.
We just did a comparison, and yes, there is a difference that could possibly affect the outcome. We did not test it very well, so perhaps we missed something:
// this test is the same in both versions
var type = typeof obj=="number"?"number":(Array.isArray(obj)?"array":(obj.constructor === {}.constructor?"object":(obj instanceof NodeList?"nodelist":(typeof obj == "string"?"string":(obj instanceof HTMLCollection?"htmlcollection":(obj.type&&obj.type=="Dictionary"?"Dictionary":"invalid"))))));
// This test was added in ZIM 019
if (type=="invalid" && obj.children && obj.children instanceof HTMLCollection) {
type="htmlcollection";
obj = obj.children;
}
// and this test added the Tile in ZIM 019
if ((obj.type == "Container" || obj.type == "Tile") && !obj.addChild) {
return undefined;
}
We have made a https://zimjs.org/cdn/019/zim_doc_racheli.js that has all of the ZIM 019 except we put the ZIM 018 tests back in at the top of the loop. Could you insert this file rather than the 019 file - it will mean that you need to go back to scripts rather than the ES6 module. If you need a hand, let us know.