This is a specific problem but I believe the pattern here may be general enough to be useful to the audience here.
I'm working on an offline JS application. In my JS application, I would like to run programmatically generated reports. No problem. I can render to canvas and then convert to pdf (oh the wonders of JS libraries these days). But there's one nagging problem: image rendering.
I do not know (and in some cases, cannot know) the images necessary to load until the report is being generated. I have access to the images encoded in Base 64, so they are not remote and are more or less guaranteed to load. However, loading an image is not guaranteed to be synchronous - even for an already in-memory string. Additionally, it is not possible to say "I'll just draw the picture once loaded" because painting order matters. Right now I'm resorting to pre-loading my whole image library (yuck!), but about the only other method I can see to make this work is a refactor to have a "gather resources" pre-step per report instance and some very not fun callback work. I can't load resources upfront (other than my current method) because resources aren't known at startup time, which seems to partially rule out the usual AMD approach.
Sigh - I wish in-memory resources loaded synchronously. So do I just need to buckle down and make the refactor or is there a better way?