Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Merge does not work with class instances #253

@GHMT

Description

@GHMT

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions