# Wat bepaalt de uitvoeringsvolgorde voor de j/s van Theme-componenten?

**URL:** https://meta.discourse.org/t/what-controls-the-order-of-execution-for-theme-components-j-s/190410
**Category:** Development
**Created:** [14 mei 2021 om 12:17 UTC](https://meta.discourse.org/t/what-controls-the-order-of-execution-for-theme-components-j-s/190410 "2021-05-14T12:17:05Z")
**Posts on this page:** 1
**Showing post:** 14

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [27 december 2021 om 18:32 UTC](https://meta.discourse.org/t/what-controls-the-order-of-execution-for-theme-components-j-s/190410/14 "2021-12-27T18:32:02Z")

</div>

The Name doesn’t affect execution order. @merefield the line you linked affects how they’re displayed in the admin UI, but isn’t used for the actual execution.

This is the relevant line for execution order:

> <https://github.com/discourse/discourse/blob/3ca1b17589f22c7ad3ae0e1e30df5d9fa4033d7b/app/models/theme.rb#L231-L231>

So they are executed in ascending order of ‘id’ in the database.

The only guarantee that’s portable across Discourse instances is that **theme** code is always executed before theme **component** code.

As @Johani mentioned above, if you have need to run code after some other component has loaded, the best bet is probably to use an Ember initializer, which [supports ordering](https://guides.emberjs.com/release/applications/initializers/#toc_specifying-initializer-order). Unfortunately that won’t be possible straight away in this case, since it doesn’t look like DiscoTOC is using Ember initializers. Updating DiscoTOC to use [multi-file javascript](https://meta.discourse.org/t/splitting-up-theme-javascript-into-multiple-files/119369) (and therefore ember initializers) would certainly be #pr-welcome

---

_[View the full topic](https://meta.discourse.org/t/what-controls-the-order-of-execution-for-theme-components-j-s/190410)._
