jedireza / mongo-models

:package: Map JavaScript classes to MongoDB collections
MIT License
67 stars 28 forks source link

[Question] Hoek dependency #37

Closed nosuchip closed 5 years ago

nosuchip commented 5 years ago

First of all thank you for mongo-models package, I like it how it slim and thin. I checked its code and found that it is actually don't need hoek dependency as only applyToDefauls used that can be easily replaced by Object.assign(...). Do you mind if I prepare PR that allows to reduce dependencies count by one?

jedireza commented 5 years ago

In most cases with simple objects that are not nested, Object.assign would be sufficient. Though Object.assign isn't great at deep cloning on its own. https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript

The goal of using hoek was to err on the side of safety. In the rare case a more complicated object was passed, we wouldn't want unexpected child nodes to be used by reference, possibly causing hard to debug errors.

Hoek docs: https://github.com/hapijs/hoek/blob/master/API.md#applytodefaultsdefaults-source-options

nosuchip commented 5 years ago

I see, thanks.