3 ms·
Posting for the author of Bifocals: It's definitely not the easiest library to explain. This does not explicitly use threads, but it will take advantage of an
by jasonmoo 14y ago
Posting for the author of Bifocals:
It's definitely not the easiest library to explain.
This does not explicitly use threads, but it will take advantage of any asynchronous systems you want to use.
http://bifocalsjs.com/#why-do-i-need-this-library http://bifocalsjs.com/#why-do-i-need-this-library is a more concrete example that might shed some light on the issue.
This allows you to run two database queries in parallel, and render immediately when the longest of the two queries is complete.
Most standard template systems have one large pool of data they provide to a template. You have to locate this data before you render a template, even if it is used by a partial.
Most partial systems simply combine two templates into a bigger template, that takes this large pool of data.
What bifocals does is give each partial it's own, isolated pool of data and render them separately and asynchronously from each other. This allows you to delay each partials rendering until it is ready, without waiting for the other partials to be ready.
Each function that creates Bifocals objects then can be isolated from the rest, with one sole responsibility. Render this template.
Your object might have parent objects, it might have children. Your function doesn't care, it just pumps data into a Bifocals object and marks it as ready. Bifocals then tracks your whole hierarchy, and sends it to the user when every last section is ready.