Playing with ES7 Object.observe
I’m really not a JavaScript expert but today I wanted to try the new Object.observe API that will be part of ECMAScript 7 and that is already supported in Chrome.
In my example I want to observe an array of user names, and update an HTML list according to the events occurring on this array (add, delete or update). To achieve this, the appropriate function is Array.observe.
Model to View
This is very simple and handy, even for a backend developper like me, to automatically udpate the view from the model.
View to Model
Of course, it is also possible to have 2 ways databinding, for example we can add an element in the array using an input field. Then the list will be automatically updated, thanks to the array observer.
We can also delete elements in the HTML list :
See this JsFiddle for the full example