# Registering ember classes in a theme

**URL:** https://meta.discourse.org/t/registering-ember-classes-in-a-theme/81419
**Category:** Development
**Created:** [2월 24, 2018, 5:30오후 UTC](https://meta.discourse.org/t/registering-ember-classes-in-a-theme/81419 "2018-02-24T17:30:55Z")
**Posts on this page:** 3
**Page:** 1

<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: [2월 24, 2018, 5:30오후 UTC](https://meta.discourse.org/t/registering-ember-classes-in-a-theme/81419/1 "2018-02-24T17:30:55Z")

</div>

I’ve just ported an old plugin to a theme-component. It had both an Ember service, and a component. The current plugin API has a `modifyClass` function, but no way to register new classes (as far as I can tell).

I created this function, mimicking the existing `modifyClass` function (example use [here](https://github.com/davidtaylorhq/discourse-media-overlay-theme/blob/800a76d6327809d7620e0d6179b3955667215f6d/common/head_tag.html#L3-L15)):

```plaintext
    function registerClass(resolverName, definition) {
        const alreadyRegistered = Discourse.hasRegistration(resolverName)
    
        if (alreadyRegistered) {
            console.warn(`"${resolverName}" is already registered`);
            return;
        }
        
        Discourse.register(resolverName, definition)
    } 

```

Is this the correct approach to be taking? And if so, is this something that could be added to the plugin API?

If so I will submit a pull request 🙂

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2월 25, 2018, 11:46오후 UTC](https://meta.discourse.org/t/registering-ember-classes-in-a-theme/81419/2 "2018-02-25T23:46:45Z")

</div>

I think it makes sense to add this to the API, @eviltrout should make the call.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [2월 26, 2018, 5:04오후 UTC](https://meta.discourse.org/t/registering-ember-classes-in-a-theme/81419/3 "2018-02-26T17:04:19Z")

</div>

The reason there’s no API to do this is classes are expected to be exported by files with their names.

`Discourse.register` might work most of the time, but I bet there’s code out there that expects files to exist in the `requirejs.entries` and other directories.

Is there no way for a theme to include named files @sam?
