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

Merge does not work with class instances #253

Open
GHMT opened this issue Jun 22, 2018 · 0 comments
Open

Merge does not work with class instances #253

GHMT opened this issue Jun 22, 2018 · 0 comments

Comments

@GHMT
Copy link

GHMT commented Jun 22, 2018

Problem:

  • I have following class:
    `class Category {
    static ObjectMapToCategory(id: number, display: string, name: string): Category {
    return new Category(id, display, name);
    }

    constructor(private id: number, private display: string, private name: string) {
    }

    get Id(): number {
    return this.id;
    }

    get Display(): string {
    return this.display;
    }

    get Name(): string {
    return this.name;
    }
    };`

  • I am using React with Redux and I am trying to merge like this (being "state", an Immutable object):
    state.merge({ isFetchingCategories: false, categoriesErrorMessage: null, categories }

  • Where categories is of type Category[]. The problem is in seamless-immutable.development.js line 659:
    for (var key in obj) { if (Object.getOwnPropertyDescriptor(obj, key)) { clone[key] = Immutable(obj[key], undefined, stackRemaining); } }

  • When obj is one of the elements of categories, the "Object.getOwnPropertyDescriptor(obj, key)" will be undefined for Category class' getters (Id, Display, Name), the rest of the private properties are taken into consideration. So, the problem is that I end up with a cloned element ("clone" variable in the code) which do not correspond to the class, since the getters are not there...

How can I fix this? How can we merge classes instances?

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

No branches or pull requests

1 participant