Echo JS 0.11.0

<~>

tracker1 1032 days ago. link 2 points
I'm not sure singleton is really useful for modern JS/TS.  I tend to just have a module with a declared export or set of exports for this use case.

An example is normalizing values either injected by the server or set via a request from the api or config server. As the first script.

ex: <script src="https://config-server/base.js"></script>

Then in-code, I use a module that normalizes the global variables the base.js sets. `global.__BASE__` which will include language strings, feature flags/toggles and any service urls.  I use feature/base.js from my code, that exposes the globals in a normalized patter... such as the current language and extra interfaces.

---

On observers, I tend to favor the simpler model that a node-style event emitter has.  For the DOM, you can subscribe and trigger non-standard events, though TS makes this difficult.

---

Factories are rarely needed in JS/TS, I tend to bucket them in with IoC and DI,

--- 

It's good to know the pattern, but the JS/TS platforms, language and tooling allows for simpler solutions in JS.  This is just my own opinion.