4 ms·
Was any of these concerns allayed?
by hayd 7y ago
Was any of these concerns allayed?
- w56rjrtyu6ru 7y agoJust stick to a sane functional style and you should be OK. I would mostly consider stateful modules an antipattern in any long-running piece of software such as a Web app (server or client). Normally you'd like to use some sort of explicit state store (Redux, database, etc) in an app like that. Stateful modules (whether sync or async) make testing harder - suddenly you're exposed to the "wonderful" world of dep injection, monkey patching and mock libraries. Isolating different features of your program for testing should be as easy as passing a different set of arguments to the entry point of that code path. On the other hand, when working on some sort of "run-once" script, it's perfectly fine to use modules as a unit of encapsulation of state. That's where async imports can really shine - suddenly you don't need to alienate readers of your program with callback hell, .then() chains or IIFEs, which are in effect just a bunch of redundant punctuation that gives JavaScript a bad name.