top | item 6947265

(no title)

GowGuy47 | 12 years ago

This seems like a cool idea. What was your need for this solution if you don't mind me asking? Developing a library?

discuss

order

teleclimber|12 years ago

I am not the developer but it is quite useful if you have Javascript objects that handle your app's data (the "M" in MVC), and the Views request data objects from these models.

If you just pass a reference then the View could accidentally alter the data object which would corrupt all other view's data objects and the Model's copy as well. Yikes.

My current solution is to create a deep-clone of the data object and pass that back to each view that asks for it. That way if a View changes the data object, it doesn't affect the other copies of the data.

The solution presented here also prevents the View from modifying its own copy (which should help reduce bugs within the View), and it keeps copies of the object up to date, which is a neat trick.