In Aurelia, when does the exported view-model class name matter? Html and JS files are linked by the name but the name of the class inside doesn't seem to matter.
By default, loader seems to grab first exported class as the view-model no matter the name of the class. It does to recognize 'ValueConverter' suffix but other than that first class exported wins.
Is this by convention?
Naming doesn't matter at all for view-models. However, a view-model should be the only export from a module that doesn't use a convention or provide metadata. Usually, it's the only export at all, but you can have others, provided they provide the metadata or use a conventional name.
Export names only matter with respect to view resources: custom elements, attached behaviors, template controllers and value converters. When you import a resource into a view, the compiler needs to know what type of a resource it is. You can provide this information with metadata or you can rely on naming conventions. So, if a class is named FooCustomElement it will know that that export is a CustomElement. Same for AttachedBehavior, TemplateController and ValueConverter.
Also, if a view resource provides no metadata and does not follow a naming convention, the compiler will assume it is a custom element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With