1.0.3 • Published 12 months ago

modilitejs v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

ModiLiteJS

ModiLiteJS is a typescript library for writing modular code with components and dependency injection. It simplifies the development process by allowing you to easily define and manage modules, components, and services, enabling a clean and organized codebase.

Installation

You can install the library using npm:

npm install modilitejs

Usage

Below is a basic example of how to use the library:

Decorators

The library provides three main decorators:

Component

Defines a class as a component.

@Component()
export class MyComponent {
  constructor(private readonly myService: MyService) {
    this.myService.greet();
  }
}

Injectable

Defines a class as an injectable service.

@Injectable()
export class MyService {
  public greet() {
    console.log('Hello, I am a service');
  }
}

Module

Defines a module that can group components, services, and other modules.

@Module({
  components: [MyComponent],
  providers: [MyService],
  imports: [AnotherModule]
})
export class MyModule {}

Libraries

AppFactory

Creates the application instance from a root module.

function bootstrap() {
  AppFactory.create(MyModule).catch((err: Error) => {
    console.error(`[App] Error:`, err.message);
  });
}

bootstrap();

Complete Example

import { Component, Injectable, Module, AppFactory } from 'app-factory';

@Injectable()
export class AppService {
  public greeting() {
    console.log('Hello, I am a service');
  }
}

@Component()
export class AppComponent {
  constructor(private readonly service: AppService) {
    this.service.greeting();
  }
}

@Module({
  components: [
    AppComponent
  ],
  providers: [
    AppService
  ]
})
export class AppModule {}

function bootstrap() {
  AppFactory.create(AppModule).catch((err: Error) => {
    console.error(`[App] Error:`, err.message);
  });
}

bootstrap();

Contributions

Contributions are welcome. Please open an issue or submit a pull request.

License

This library is licensed under the MIT License. You can see more details in the LICENSE file.

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago