sylvainpolletvillard / ObjectModel

Strong Dynamically Typed Object Modeling for JavaScript
http://objectmodel.js.org
MIT License
467 stars 30 forks source link

API update() function #90

Closed gotjoshua closed 6 years ago

gotjoshua commented 6 years ago

Feature Request: We have a wish for a function that can do basically the same as ObjectModel({initObject}) with an {updateObject}, without destroying the initial instance/reference.

Wished Pseudo-Code Ex:

mInstance = ObjectModel({id:Number,info:String})({id:1,info:'init'});
mInstance.update({info:'newString'};

any chance you could save us some for looping with such a function?

sylvainpolletvillard commented 6 years ago

What would be the difference with Object.assign(mInstance, { info: "newstring" }) ?

sylvainpolletvillard commented 6 years ago

Regarding new API proposals, something to keep in mind is that models aimed to be transparent wrappers around any kind of value/object. So we can't really modify instance prototypes, we can only act on the model layer. Such an addition would break every existing code using an object with an update property, so it is likely to cause damage.

gotjoshua commented 6 years ago

Yeah, good call... sometimes i seem to overlook the obvious, in my enthusiasm for the library...

Object assign should work anyway, as OM will check everything. Thanks again (for yet another basic js lesson : - / )

sylvainpolletvillard commented 6 years ago

Haha no problem, I'm glad you propose new ideas for the library. I love to know how everyone uses my work and how can we improve it further.