Today in angular service land, I needed a way to extract the values out of a dictionary.
The dictionary in question keeps track of paged data that has been returned from the backend. The service I’m writing will first check this dictionary to see if data for the required pages already exists (has already been fetched) and if so, will just fetch it from the dictionary instead of making another request to the server.
The service can be polled to return multiple pages of data, and if so, I wanted to be able to extract the appropriate pages out of the dictionary (dictionary is indexed by page number) and concatenate the values together into an array that is returned to the caller. This is a fairly simple task, but I wanted to make sure I wasn’t re-implementing something that has, I’m sure, been implemented countless times before.
After some digging through the docs, I found a method that did exactly what I wanted:
This made my day!
It was so easy, and just required looking through the underscore docs to see what was available.
I’ll definitely be leveraging more underscore methods in the future.