Bug in gojs-angular library?

Hi,

I ran into an issue that I tracked down to a bug(?) in gojs-angular.js library.

static mergeChanges(component, kvchanges, str) {
        // helper function
        /**
         * @param {?} obj1
         * @param {?} obj2
         * @return {?}
         */
        function compareObjs(obj1, obj2) {
            // Loop through properties in object 1
            for (const p in obj1) {
                // Check property exists on both objects
                if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p))
                    return false;
                switch (typeof (obj1[p])) {
                    // Deep compare objects
                    case 'object':
                        if (!compareObjs(obj1[p], obj2[p]))
                            return false;
                        break;
                    // Compare values
                    default:
                        if (obj1[p] !== obj2[p])
                            return false;
                }
            }
            // Check object 2 for any extra properties
            for (const p in obj2) {
                if (typeof (obj1[p]) === 'undefined')
                    return false;
            }
            return true;
        }

....
}

In the above code the line

if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p))

fails if obj2 is null or undefined.

it should be a valid compare, no? Basically what it means is that a nested object was deleted or created (become null or not null)

Thanks,
Nuno

We’re working on this. We’re looking to see if there might be any other subtle problems that we didn’t consider.

Hmm, I’ve looked into this a bit and I’m don’t think you should ever be seeing this. If you’re removing an entry in, say, diagramNodeData, you should not be setting that entry to null, you should be removing it entirely. And if you do that, compareObjs will never be called, since it is handled in mergeChanges, when the kvchanges.forEachRemovedItem loop happens.

compareObjs should only ever happen when an entry in node / link / model data is replaced with another object, not when an entry is added or removed.

If you have a simple example of code that’s still following these paradigms and giving you this issue, please let me see it

Hi ryanj,

I don’t set diagramNodeData entries to null. The objects that are set to null are child objects of diagramNodeDatas. Quick example:

diagramNodeData = [
 {
    key: '1',
    text: 'some text',
    childObject: {
         someProperty: 123
    }
 },
];

which then gets updated to:

diagramNodeData = [
 {
    key: '1',
    text: 'some text',
    childObject: null
 },
];

Or the reverse - a child object is null and then becomes not null.

This was of the top of my head but you should be able to repro it with this, if not, let me know and I’ll try to get you a simple code example with the issue. thanks

Ah, I see, thank you. I just published gojs-angular 1.0.17, which should address this issue. Let me know if you run into more problems.

Perfect, that worked great! :)

Thanks ryanj