I’m confused at what the differences are between custom components and custom elements. When I use the CLI generator to make one of each, they’re each composed of an html view and a JS/TS view-model and look extremely similar to one another:
Custom Element:
<template>
<h1>${value}</h1>
</template>
////////////////////////////
import {bindable} from 'aurelia-framework';
export class MyCustomElement {
@bindable value;
valueChanged(newValue, oldValue) { }
}
Custom Component:
<template>
<h1>${message}</h1>
</template>
////////////////////////////
export class MyCustomComponent {
message: string;
constructor() {
this.message = 'Hello world';
}
}
I don’t understand the situations or contexts in which you would use one over the other (or, assuming they’re not comparable, in what circumstances you should use each).
I do completely understand the difference between them if custom elements had only a view component (i.e. html file) and were therefore just a way to essentially modularize repeating snippets of html that you’d want to populate with different data (like cards in a grid or rows in a table) that don’t require any logic. But if custom elements are also able to have a view model as well, and therefore their own logic, then wouldn’t that essentially just make them custom components at that point?
(Note that I asked the same question on Stack Overflow a while back here, but the one answer didn’t explain it well enough for me to understand.)