S
S
Sergey Sokolov2017-06-16 09:54:19
JavaScript
Sergey Sokolov, 2017-06-16 09:54:19

What is the pattern for updating items in a collection?

The application is similar in appearance to TodoList: the user adds items to the list, everything is stored on my server.
Difference from TodoMVC: list items represent objects from the Third Service ("TS"), where their full names come from. I only store id.
When downloading from my server, a list of id comes to the client. Immediately, you need to send requests to the vehicle in order to get their names by these id and show not “id12345”, but “Long name” in the list.
The TS has its own restrictions on the frequency of requests per second M and the ability to group requests into batches, no more than N. When initially loading a list of 100 elements, I cannot send 100 parallel ajax requests to the service, but only 1 and I will try to break 100 into packs of 25 and send, noticing the time, no more than 3 requests per second.
I'm using Backbone.JS. Implemented, it seems to me, quite cycling. The list element model, if it does not yet have a full name , sends its id and its callback to a certain general dispatcher, which groups and queues bundles of requests, and monitors the time of requests to the TS, slowing down if necessary. The same dispatcher acts as a cache, storing all available pairs (id: name) if they are needed again in other places of the application.
I used to do something similar to React + Baobab. The essence is the same: a branch in Baobab stores a “dictionary” for all loaded ones, and a certain object is engaged in a queue / batching of tasks.
It seems that for such a situation there should be some more beautiful and clear pattern - tell me?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question