box/t3js

Replacing services with ES modules

andreyvolokitin opened this issue · 1 comments

My project is bundled with webpack so I tried to replace services with regular ES modules. I found few reasons to use actual services but one of them was crucial:

  1. Services has access to application, which is required way for communicating with it (as opposed to Box.Application). For that I created dumb service returning application which I can use in regular ES modules.
  2. The lifecycle of services is synchronized with application, so the global config works there just fine. But in regular ES modules it breaks, because they executed early while Box.Application.init(config) is still not executed so the global config is empty there.

So I guess in current t3js state it is better to just use services?

P.S.: also I found this repo, but it looks abandoned

j3tan commented

ES6 modules replace most of the functionality that a service/module registry system, such as t3js, provides. For us at Box, we've opted to move wholly towards ES6 modules and webpack and have stopped active use of t3js to avoid the complexities that you are encountering.

I recommend avoiding trying to use the Box.application outside of framework components/services due to the synchronization and underlying assumptions that services are built on. The only attach point external modules should be utilizing is the event system.

So yes, in this case, continue to use t3js services. You can still use webpack to help bundle your application but code splitting will be more complex without modules.