Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed merge function to work with getter/setter props #268

Merged
merged 1 commit into from
Mar 6, 2018
Merged

fixed merge function to work with getter/setter props #268

merged 1 commit into from
Mar 6, 2018

Conversation

p3root
Copy link
Contributor

@p3root p3root commented Mar 6, 2018

The current version of the merge function does not determine getter/setter properties. Therefore I check if the given property is not void 0 to check if the obj2 has a field with that given name. The name/functionality for the .hasOwnProperty function sucks in this case.

fixed merge function to work with getter/setter props
@tiberiuzuld tiberiuzuld merged commit 1094490 into tiberiuzuld:master Mar 6, 2018
@p3root p3root deleted the master-up branch March 6, 2018 12:17
@tomazk8
Copy link

tomazk8 commented Sep 14, 2021

In the latest 12.1.0 version the problem is still present. The fix doesn't work because because merge uses for (const p in obj2) which doesn't list the properties with getter and setter.

@tomazk8
Copy link

tomazk8 commented Sep 14, 2021

I temporary modified the merge method like this and it works now:

static merge(obj1, obj2, properties) {
    /*for (const p in obj2) {
        if (obj2[p] !== void 0 && properties.hasOwnProperty(p)) {
            if (typeof obj2[p] === 'object') {
                obj1[p] = GridsterUtils.merge(obj1[p], obj2[p], properties[p]);
            }
            else {
                obj1[p] = obj2[p];
            }
        }
    }*/

    Object.keys(properties).forEach(p => {
        if (typeof obj2[p] === 'object') {
            obj1[p] = GridsterUtils.merge(obj1[p], obj2[p], properties[p]);
        }
        else {
            if (!!obj2[p])
                obj1[p] = obj2[p];
        }
    });
    return obj1;
}

Note that I am mainly not a web or angular developer so my solution may be wrong. Please give me some feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants