Aurelia Model Class Naming

In Aurelia, when does the class name of the exported view model matter? Html and JS files are linked by name, but the class name inside does not matter.

By default, the loader seems to capture the first exported class as a view model regardless of the class name. It recognizes the suffix "ValueConverter", but with the exception that it won first class.

Is this by agreement?

+4
source share
1 answer

Naming does not matter for view models. However, the presentation model should be the only export from the module that does not use the convention or does not provide metadata. This is usually the only export, but you can have others if they provide metadata or use a conditional name.

Export names only for view resources: user elements, attached behaviors, template controllers, and value converters. When you import a resource into a view, the compiler needs to know what type of resource it is. You can provide this information with metadata, or you can rely on naming conventions. So, if the class is called FooCustomElement, it will know that this export is CustomElement. The same goes for AttachedBehavior, TemplateController and ValueConverter.

, , , .

+10

All Articles