I am creating a web application based on data using javascript. This data is stored as a js object and is constantly being updated using AJAX. The object has some methods to reorganize the data, such as sorting and filtering, as well as a method called render() which uses js templating to update the html to represent the data.
What I want is that every time the data object changes it automatically calls the render method to update the view. I know this can be done by just calling render() inside all my methods that modify the data, but I am looking for a cleaner way to do it.
I have read something about the observer pattern however I am not familiar with it and I don’t know if I can use that to achieve this. Also I know about the Object.watch() method but that is not supported by all browsers so I can’t use it.
Do you have any suggestions or examples about how can I do this?
Thanks.
Often, the flow is something like this:
That gives you one render ( ) call for each Ajax update, which is likely what you want.
HTH