Registering ember classes in a theme

(David Taylor) #1

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):

    function registerClass(resolverName, definition) {
        const alreadyRegistered = Discourse.hasRegistration(resolverName)
        if (alreadyRegistered) {
            console.warn(`"${resolverName}" is already registered`);
        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 :slight_smile:

(Sam Saffron) #2

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

(Robin Ward) #3

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?