I have a question about reusing Discourse “core” Ember components in plugins. More particularly, I ran into trouble today trying to put a “signup” d-button into a plugin template.
Moreover, in order to get this modal to pop up in my component, do I need to fundamentally change the structure of my files? I don’t think my file structure is necessarily correct either.
It worked like a charm. It gave me a “Sign Up” button that displayed the account creation modal. Note that this works when the template is specific to the plugin and not through a connector.
That said, if I do the same thing in a handlebars template that is using a plugin-outlet through a connector, it fails. Makes me think the connector templates aren’t inheriting actions from above. @eviltrout, is there any truth to that? That would be good to know. Even templates that have the action availableand a plugin-outlet fail when the connector is used.
On another note, try inserting {{signup-cta}} in your handlebars file. See if that’s something you’re interested in.
As of Ember 2.10 we can’t just inherit the exact same context as the parent template, so outlets only have access to things that are explicitly passed into them, including actions.
We’ve tried to pass in all the data an outlet would need, but if you find a case where an action is needed in an outlet and it can’t call it, we can accept a PR to handle htat.
No unfortunately the contract between the parent template and the outlet has to be explicit.
It is a little more limiting, but on the other hand it means we know exactly what objects / actions outlets can be using which helps us not break things in the future.
I spent a little time digging through the Ember pieces of plugin-outlets and came up short. I didn’t see where the actions passed are explicitly defined. Are they passed through the component in buildArgs?
I did a quick search through our codebase and I couldn’t find an action being passed in either which is quite interesting, which tells me that most plugins just operate on the objects they are working on!
I tried altering a handful of plugin-outlets and managed to get the same error each time:
Assertion Failed: No application initializer named 'inject-discourse-objects'
The outlets don’t like it when I give them an action of any kind. I’m specifically looking at the static.hbs template since the action is already called there. That way I know it’s available.
I can’t say that I can think of an instance where I’ve tried to do this in any way. I’ve always used my own actions. But I could see the benefit of using them in the future. I just can’t think of an example right now.
Edit: Robin! That whole rm -rf tmp thing still gets me sometimes. I still get an error but it’s not the same:
Assertion Failed: <(subclass of Ember.Component):ember1016> had no action handler for: showCreateAccount
Oh I see, the error is trying to attach it! The error is because showCreateAccount doesn’t belong to the application controller, it’s part of the application route itself. Instead you can pass it the same way site-header does:
Ah, the static controller doesn’t have the appRouteAction helper that the application controller does. This is a bit of a complicated situation I promise, because it involves sending an action to something that is present on every page of the site
Your best bet would be to create a new action in the static controller that simply calls this.send('showCreateAccount') and then bind that to the plugin outlet.
Ok. I added it to the static controller and now I can see it in the Ember inspector on the controller. The trick is how to trigger that action from a d-button action within a connector. Wouldn’t I need another controller for that?