I have just created the first draft of this

this is the first draft of the Recursive Object Observe. more info on github https://github.com/valtido/Observe

 

This means if you had an object of a person (as json)

 

So the above is a simple JSON object, made of the name of the person and his/her age.
What does it do?

The above will simply bind the object and listen to any changes you may make from now on, things like  person.name = "Tom"  or  person.age = 20  or even create a new property of the object you are observing like person.location = "London".

Ok, that’s nice but what is  changes ? changes is a simple object with two parameters,   value  and  path where value is the value that it has changed to,  and path is the ancestor path in the object which has changed.

Why can’t we just use the  Object.observe  it’s native does the same thing you may say?

A; it’s not recursive, B; it opens doors to more code (front-end and back-end) as humans we say tell me what has changed and whom has changed so I can put it on my records.

 

Here is a deep observation which is also in the future (observing something that does not exist yet) e.g person.children does not exist just yet, so we can create this…

 Conclusion

This is a really useful tool when you would like to watch for changes to an object and take actions (such as update the DB on server-side) at a specific level.

This removes the need to send a full object to the server, all you need is the path of an object and it’s value which it should change to.

 

.