When working with JavaScript and needing to replace existing data with new data, what is considered a good or "correct" practice?
I currently utilize Dojo's Memory and dGrid to showcase my data. The information is refreshed each time the user clicks the 'refresh' button.
The refresh button is not frequently clicked within the application's lifespan. Below is the code snippet for the grid:
data = {some JSON data};
store = new Memory({data: data});
grid = new OnDemandGrid({
selectionMode: 'single',
store: store
});
This block of code is executed during the application initialization process.
Additionally, there is another method called 'showGrid
' that determines the grid layout.
The store is updated when the application receives new data through a message.
My main concern is that Memory does not offer a method to clear its existing data. Consequently, I must loop through the store and insert the new data. It might be simpler or quicker if I were to create a new store instead of reusing the existing one.
Why not just generate a new store in the 'showGrid
' method and have it create a new store whenever the user hits refresh? Performance or memory usage isn't a big issue since the dataset isn't large.
Nevertheless, I want to adhere to best practices when it comes to achieving this functionality, considering the importance of creating new objects when they're reusable from my university days (although my experience was with Java Class and not JavaScript).
Thank you in advance :)