Service

Services are classes that handle your application's business and logic. Service in React3L was inspired by the term with the same name in Angular framework. See https://angular.io/tutorial/toh-pt4.

  1. Single instance only

    Each service should have only 1 instance object and it should be initialized right after service class declaration inside the module file. For example:

     export class TestService {
       public static sum(a: number, b: numer): number {
         return a + b;
       }
          
       public useSum(a: number, b: numer): number {
         return React.memo(() => a + b, [a, b]);
       }
     }
        
     export const testService: TestService = new TestService();
    
  2. No dependency injection

    Hooks maintain their own states wherever they were called so service does not need DI mechanism.

  3. Domain driven design

    Each service should refer to one business domain of your app. For example: Product, Order, Customer, …