How to add a component's actions into a plugin-outlet?

I’ve been trying to reference an existing component in a plugin-outlet, but I keep getting errors. And the main issue seems to be the actions associated with the component. Is there a proper way to reference the actions of another component in a plugin outlet?

I would have thought that in a plugin-outlet, just referencing the component (ie, {{component-name action=(action "doSomething")...}}) would work to bring in all the relevant code of that component’s actions. But it seems like that is not the case–because I keep getting a variety of errors about certain things being undefined, improper definitions, and other stuff implying the javascript of the action is not being brought into the plugin outlet properly.


For example:

If in a template there is the following reference to the composer-action-title component, like this:
composer.hbs:

 {{composer-action-title
       model=model
        openComposer=(action "openComposer")
        closeComposer=(action "closeComposer")
        canWhisper=canWhisper
        tabindex=8
  }}

and I wanted to add a plugin outlet that–in that plugin outlet–had the same code, like:

connectors/cool-outlet/cool-outlet.hbs:

 {{composer-action-title
       model=model
        openComposer=(action "openComposer")
        closeComposer=(action "closeComposer")
        canWhisper=canWhisper
        tabindex=8
  }}

What do I need to do to allow my cool-outlet plugin outlet the ability to successfully reference the composer-action-title component, including the “openComposer” and “closeComposer” actions?

I think I’ve got the basic gist of this–though I’m happy to hear if anyone else has suggestions.

To pass along actions and other arguments to a plugin outlet, you can add them to the plugin outlet reference just like you can with a reference to a component.

But watch out that you are passing the right arguments–ie, the right variable references.

Using my example: Here’s a component reference that appears in the template composer.hbs:

{{composer-action-title
       model=model
       openComposer=(action "openComposer")
       closeComposer=(action "closeComposer")
       canWhisper=canWhisper
       tabindex=8
  }}

If you want to replace this reference with a reference to a plugin outlet (obviously being careful if you are editing a template file, given the increased difficulty of maintaining things as discourse changes), and you want the plugin outlet itself to reference the composer-action-title component, you could put this into composer.hbs:

{{plugin-outlet name="cool-outlet" args=(hash 
       model=model
       openComposer=(action "openComposer")
       closeComposer=(action "closeComposer")
       canWhisper=canWhisper
       tabindex=8
    )
}}

And then in connectors/cool-outlet/cool-outlet.hbs, this should work to refer to the composer-action-title component:

{{composer-action-title
       model=model
       openComposer=openComposer
       closeComposer=closeComposer
       canWhisper=canWhisper
       tabindex=8
  }}

Note the variables here, they are the variables set in the composer.hbs file.