Integrating Dojo 2 into an existing application

First, I am immensely grateful to all Dojo 2 contributors for bringing this to fruition. Your thoughtfulness and ingenuity have kept me a Dojo supporter and user for many years.

I mostly use Dojo 1 within PHP based applications and I am trying to figure out the migration path for my team to Dojo 2.

In Dojo 1:

  • I can instantiate any module either declaratively (using the parser and data-dojo-type attribute) or imperatively (requiring it in another module or directly on the page and using it).
  • Modules are all loaded lazily by default and I can bundle them into builds as appropriate

I know Dojo 2 is still in beta and documentation is still in progress, but from what I gather:

  • there is no parser, the Dojo 2 approach is to generate custom elements
  • modules are bundled by default and lazy loading requires explicit declaration

Other implications:

  • A non-widget module can no longer be loaded declaratively
  • To use a custom element imperatively, one should simply generate a DOM node of the correct type

Questions that arise:

  • I presume I would then need to use the webcomponents.org polyfill?
  • If I have one module that generates a custom element that is used inside of another module which is not a custom element (attached via the projector), then the dependency between the two is not managed?
  • These things, combined with concerns that web components aren’t ready yet lead me to think I would prefer to use the projector method if I can. However, I would probably need to use it with multiple roots and consequently I would basically need to re-implement something like the Dojo 1 parser. Am I missing something?

If anyone has any guidance that would help me sort out these issues, I would greatly appreciate it. If the answer is that time and documentation will answer these questions, that’s fine too. I just want to make sure I’m prepared for the transition.

Thanks for the questions and feedback!

“there is no parser, the Dojo 2 approach is to generate custom elements”

This is correct, though you don’t have to use custom elements. You could just use widgets in a programmatic approach if you don’t want to use custom elements.

“modules are bundled by default and lazy loading requires explicit declaration”

There are ways to create separate bundles, but some of those workflows are still being defined. That said, the lazy loading is facilitated by the registry in widget-core.

“A non-widget module can no longer be loaded declaratively” This is correct. This was probably a bad idea in Dojo 1.x in hindsight.

“To use a custom element imperatively, one should simply generate a DOM node of the correct type” yes

“I presume I would then need to use the webcomponents.org2 polyfill?” This is what we recommend by default, though if you don’t need to support browsers without native custom element support (e.g. IE11) then it is not needed.

“If I have one module that generates a custom element that is used inside of another module which is not a custom element (attached via the projector), then the dependency between the two is not managed?” We are working on a tutorial and demo to do something like put a Dojo 2 widget as a custom element inside a Dojo 1 Dijit, which should help with such scenarios. We’ll have that available sometime in January hopefully. You may follow the progress at https://github.com/dojo/dojo.io/pull/345.

“These things, combined with concerns that web components aren’t ready yet lead me to think I would prefer to use the projector method if I can. However, I would probably need to use it with multiple roots and consequently I would basically need to re-implement something like the Dojo 1 parser. Am I missing something?” You can use multiple projectors per page, but I’d need to see an example of what you’re doing to provide a bit more insight.

-Dylan

Hi,
I am not quite sure I understood but to ask differently: we won’t have a parser to store widgets as regular markup ? That’s too bad, that way I am unable to author dojo-2 tech with my Maqetta-clone (currently rewriting it). I guess I still can write a simple parser…won’t need the data/event stuff per-se.

thanks for the info !
g