https://github.com/foblex/f-ng-infra
ngMediator is a mediator library for Angular that facilitates a clean architecture with a better command-query separation. It helps in orchestrating the handling of commands and queries in a simple, extendable, and maintainable manner.
https://github.com/foblex/f-ng-infra
Last synced: over 1 year ago
JSON representation
ngMediator is a mediator library for Angular that facilitates a clean architecture with a better command-query separation. It helps in orchestrating the handling of commands and queries in a simple, extendable, and maintainable manner.
- Host: GitHub
- URL: https://github.com/foblex/f-ng-infra
- Owner: Foblex
- License: mit
- Created: 2024-02-26T22:42:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-23T12:18:23.000Z (over 2 years ago)
- Last Synced: 2025-04-09T20:12:04.381Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 129 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ngMediator Library
ngMediator is a mediator library for Angular that facilitates a clean architecture with a better command-query separation. It helps in orchestrating the handling of commands and queries in a simple, extendable, and maintainable manner.
## Installation
Install the ngMediator library via npm:
```bash
npm install @foblex/ng-mediator
```
## Usage
ngMediator simplifies the handling of commands and queries within your Angular applications, ensuring a clean and maintainable architecture. Below are the steps on how to utilize ngMediator in your project:
1. **Define Requests, Validators, and Handlers**:
Define your requests, validators, and handlers using the provided decorators and interfaces from the ngMediator library.
Example:
```typescript
import { IRequest, FValidatorBase, FCommandBase, FQueryBase } from '@foblex/ng-mediator';
// Define your Request
class MyRequest implements IRequest { }
// Define your Response
class MyResponse {
// fields...
}
// Define your Validator
@Injectable()
class MyValidator extends FValidatorBase {
validate(request: MyRequest): Observable {
// validation logic...
}
}
// Define your Handler
@Injectable()
class MyHandler extends FCommandBase {
handle(request: MyRequest): Observable {
// handling logic...
}
}
// or
@Injectable()
class MyHandler extends FQueryBase {
handle(request: MyRequest): Observable {
// handling logic...
}
}
@NgModule({
imports: [
FMediatorModule.forFeature(MyRequest, MyValidator, MyHandler),
]
})
export class Module { }
```
2. **Send Requests**:
Utilize the FMediator service to send your requests. The service will ensure that your requests are validated and handled by the appropriate handlers.
Example:
```typescript
import { FMediator } from '@foblex/ng-mediator';
fMediator.send(new MyRequest()).subscribe(response => {
console.log(response);
});
```
# ngClarc Library
ngClarc is infrastructure library for Angular that provides a robust set of utilities and interfaces designed to simplify and enhance various projects.
## Installation
Install the ngClarc library via npm:
```bash
npm install @foblex/ng-clarc
```