Messenger tool for typescript. It is inspired on Redux.
Registers a listener by id. Many supscriptors are allowed.
Sends the message to the subscriptions by id.
The null uuid value;
Generates a new uuid to avoid colisions in the store.
On a project generated with angular-cli
npm install https://github.com/MoNoApps/radio.gitRegister Radio provider (DI)
import { Component, OnInit } from '@angular/core';
import { Radio, Id } from '@monoapps/radio';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [Radio]
})
export class AppComponent implements OnInit {
title = 'app works!';
constructor(private radio: Radio) { }
ngOnInit() {
this.radio.subscribe(Id, this.print);
}
print(value) {
console.log(value);
}
}Import Radio from the registered module
import { Component, OnInit } from '@angular/core';
import { Radio, Id } from '@monoapps/radio';
export class SelectComponent implements OnInit {
constructor(private radio: Radio) { }
ngOnInit() {
this.radio.dispatch(Id, ['message']);
}
}