Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aurelia view-model class naming

Tags:

aurelia

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?

like image 532
Chi Row Avatar asked Dec 20 '22 05:12

Chi Row


1 Answers

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.

like image 135
EisenbergEffect Avatar answered Mar 07 '23 19:03

EisenbergEffect