When working with Ember views / controllers / routes, if a sent event bubbles all the way and doesn’t get handled, we get a warning. I understand Ember components are designed to be completely isolated from the rest of the application, so no bubbling occurs, but this also means we don’t get a warning for an unhandled event.
Is there / should we have a development mode flag to raise warnings when when nothing handles a component event? This could be useful for catching typos and other mistakes; e.g., when inside a component, send("myACtion") will silently do nothing if your actual action is named "myAction"
In a project I work on which is built on top of Components I have many actions per component that by default are not set to any value as the user doesn’t necessarily requires to register them, in case of raising warning per such action it will spawn too many warnings and won’t be useful, even for development.
@asaf000 To be clear, I’m not talking about actions sent by sendAction; instead, I’m talking about actions that are supposed to be internal within the component. For instance, for some of my more complicated components, I have internal view/controller hierarchies, and I use send actions that are never meant to be seen outside of the component. However, if I make a typo in the event name, these calls fail silently.
In any case, my suggestion is for a flag to enable action logging (by default, it could be off) – so you could just leave it off.
You do raise a good point though – I haven’t taken a look at the source yet, but if sendAction in components operates through the same path way as plain old send then it may not be possible to log unhandled events for one but not the other.
I agree with @sherwinyu and I think it would more developer friendly if actions defined in the component’s template would throw an error if the component does not define them. This results in a bug that is hard to find. Now, there is probably a design concern behind it not doing so, and I would like to understand what that is.
sendAction, which is the component’s way of talking to its context, is another matter and will, in fact, throw an error if nothing handles it.