substantial/updeep

updeep does not keep result of `object instanceof MyClass`

ZeHiro opened this issue · 4 comments

When updating the property of an object with updeep, the 'type' of objects created with classes is not kept. This then raises errors with React, when checking props with React prop validator.

Hi @ZeHiro, thanks for reporting.

Do you have a failing test case? I wasn't aware of the __proto__ property. From my brief reading it seems like it's not something that is meant to be used nowadays. Though maybe its' the actual backing for getPrototyepOf

Any way, updeep was primarily designed to work w/ regular objects. I'm guessing that __proto__ is not enumerable and so therefore would not come over when we create a new object. I'm not sure if it's worth adding a special case for __proto__ or not. You're welcome to submit a pull request and we can see what would be necessary. Thanks!

@aaronjensen

In fact, what I observed is:

Thanks @ZeHiro for the explanation.

At this point I'd say this is as designed/expected. Updeep is intended to work on basic data structures (objects, arrays) and not class instances. One could easily argue that using updeep to mutate class instance properties is an anti-pattern given the fact that classes are generally meant to encapsulate their state.

I'm going to close this as wontfix for now.

I don't know exactly how you're using classes in the classes or why you're wanting to use updeep to mutate them, but one suggestion may be to have class functions that use updeep to update class properties and return a new instance of the class like: new MyClass(u({...}, this)).

Thanks for you're answer. That's whzt i thought after rethinking of that issue.