LearnNewsExamplesServices

Extending Classes

In theory, a Neo.mjs app could be defined in a single .mjs source file. But that would be very hard to maintain, and any reusable configs would have to be duplicated. Instead, each of your views and reusable widgets will be defined as its own class. The result is simpler views which are inherently reusable and easier to test.

Consider this code. It's a panel with a header and a table. The table has a store.

If you wanted, any of the configs can be refactored into their own class. Here, the button, store, and table have been refactored into their own classes, and the main view is using them. The main view is simpler and more abstract, and each class can be reused, tested, and maintained independently.

There are several use-cases for creating your own classes:

  • For reuse
  • To isolate complexity
  • To add events or methods to the new class
  • To test the component independently