0.0.1 • Published 6 years ago
angular-cqrs v0.0.1
angular-cqrs
Provides CQRS functionality for Angular 2/4.
Usage
Import the Angular module
@NgModule({
imports: [
CQRSModule.forRoot({
eventDefinition: {
name: "event"
},
commandDefinition: {
name: "command"
}
})
],
...
})
export class AppModule {
...
Wire up events and commands
export class AppModule {
constructor(cqrsService: CQRSService, socket: SocketService) {
cqrsService.onCommand(cmd => {
socket.sendCommand(cmd);
});
socket.receive("event").subscribe(evt => {
cqrsService.eventReceived(evt);
});
}
}
This allows you to connect the CQRS service with the transportation to the backend - in this case a websocket.
Send a command
const cmd: {
command: "mycommand",
... // Any arbitrary data, for example aggregate infos, command payload, meta infos, ...
};
cqrsService.sendCommand(cmd);
React to events
cqrsService.$events.subscribe(evt => {
console.log("Received event: " + evt.event);
});
0.0.1
6 years ago