Skip to content

Commit f064060

Browse files
authored
Rt message handler decorator (#1)
* adding handler * added decorators * refactory * refactory pubsub * update readme * for feature added * refact: fixing * updated code * updated angular * updated readme * updated readme * updated readme * fixing feature module * refact: fixing code * updated example app * added examples * fix: test
1 parent e1d1b20 commit f064060

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1502
-784
lines changed

README.md

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
[![Actions Status](https://github.com/rupeshtiwari/fsms-angular-pubsub/workflows/.github/workflows/main.yml/badge.svg)](https://github.com/rupeshtiwari/fsms-angular-pubsub/actions)
21

3-
# Angular Pub/Sub Framework for Angular versions
42

5-
Angular publish subscribe framework written by using `RxJS` only.
3+
# Angular PubSub
64

7-
## Installing Package
5+
Angular 11.x implementation of the [publish subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) Pattern.
86

9-
- Run below to install
7+
![GitHub package.json dependency version (subfolder of monorepo)](https://img.shields.io/github/package-json/dependency-version/fullstackmaster1/fsms-angular-pubsub/@angular/core) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/fullstackmaster1/fsms-angular-pubsub/CI%20and%20CD/main?style=flat) ![npm](https://img.shields.io/npm/dw/@fsms/angular-pubsub?style=flat) [![npm version](https://badge.fury.io/js/%40fsms%2Fangular-pubsub.svg)](https://badge.fury.io/js/%40fsms%2Fangular-pubsub) ![GitHub repo size](https://img.shields.io/github/repo-size/fullstackmaster1/FSMS-ANGULAR-PUBSUB) ![GitHub pull requests](https://img.shields.io/github/issues-pr/fullstackmaster1/fsms-angular-pubsub) ![GitHub last commit](https://img.shields.io/github/last-commit/fullstackmaster1/fsms-angular-pubsub) [![dependencies Status](https://status.david-dm.org/gh/FullStackMaster1/fsms-angular-pubsub.svg)](https://david-dm.org/FullStackMaster1/fsms-angular-pubsub) ![GitHub User's stars](https://img.shields.io/github/stars/fullstackmaster1?style=social) ![GitHub Sponsors](https://img.shields.io/github/sponsors/fullstackmaster1?style=social)
108

11-
```
9+
## Installing
10+
11+
**npm installation**
12+
13+
```shell
1214
npm i -S @fsms/angular-pubsub
1315
```
14-
## Using Pub Sub
16+
## Using PubSub For Inline Style
1517

16-
1. Importing Module
18+
1. **Importing PubsubModule in application module**.
1719

1820
Initialize module for root in your angular root module
1921

@@ -39,64 +41,72 @@ bootstrap: [RootComponent]
3941

4042
```
4143

42-
2. Subscribing to Message
44+
2. **Injecting `PubsubService` as dependency in component**
4345

4446
Go to desired component and subscribe to a message.
4547

4648
```ts
4749
import { Component } from '@angular/core';
48-
import { PubSubService } from '@fsms/angular-pubsub';
49-
import { PlaceOrder, PlaceOrderType } from './placeorder-message';
50+
import { PubsubService } from '@fsms/angular-pubsub';// <= HERE
5051

5152
@Component({
5253
selector: 'app-root',
5354
templateUrl: './app.component.html',
5455
styleUrls: ['./app.component.css'],
5556
})
5657
export class AppComponent {
57-
constructor(private messageService: PubSubService) {
58-
this.messageService.subscribe({ // <= HERE
59-
messageType: PlaceOrderType,
60-
callback: (msg) => console.log('received', msg),
61-
});
62-
}
58+
constructor(
59+
private pubsubService: PubsubService/* <= HERE */) {}
6360
}
6461
```
65-
3. Publishing Message
62+
3. **Subscribing to message**
63+
64+
In `ngOnInit` method of angular, you can subscribe to the events that you want to react upon.
6665

67-
Now on a button click, I want to publish a message with some payload.
66+
```ts
67+
ngOnInit(): void {
68+
this.pubsubService.subscribe({ // <= HERE
69+
messageType: PlaceOrderType,
70+
callback: (msg) => console.log('received', msg),
71+
});
72+
}
73+
```
74+
4. **Publishing Message**
75+
The `publish` method takes one argument where it expect the `message` object.
76+
77+
Example: Now on a button click, I want to publish a message with some payload.
6878

6979
```ts
7080
import { Component } from '@angular/core';
71-
import { PubSubService } from '@fsms/angular-pubsub';
72-
import { PlaceOrder, PlaceOrderType } from './placeorder-message';
81+
import { OrderPlaced } from './messages/placeorder-message';
82+
import { PubsubService } from '@fsms/angular-pubsub';// <= HERE
7383

7484
@Component({
7585
selector: 'app-root',
7686
templateUrl: './app.component.html',
7787
styleUrls: ['./app.component.css'],
7888
})
7989
export class AppComponent {
80-
constructor(private messageService: PubSubService) {
81-
this.messageService.subscribe({
82-
messageType: PlaceOrderType,
83-
callback: (msg) => console.log('received', msg),
84-
});
85-
}
90+
constructor(
91+
private pubsubService: PubsubService/* <= HERE */) {}
8692

87-
sendMessage($event: KeyboardEvent) {
93+
orderPlaced($event: KeyboardEvent) {
8894
$event.preventDefault();
89-
this.messageService.publish(new PlaceOrder('20 Apples'));// <= HERE
95+
96+
this.pubsubService.publish(new OrderPlaced('20 Apples'));// <= HERE
9097
}
9198
}
9299
```
100+
5. **Unsubscribing Messages**
101+
93102

103+
---
94104

95-
### Thank You!
105+
**Thank You!**
96106

97-
**💖 Say 👋 to me!**
98-
Rupesh Tiwari <br/>
99-
<a href="https://www.rupeshtiwari.com"> www.rupeshtiwari.com</a> <br/>
100-
✉️ <a href="mailto:fullstackmaster1@gmail.com?subject=Hi"> Email Rupesh</a><br/>
107+
💖 Say 👋 to me!
108+
Rupesh Tiwari
109+
<a href="https://www.rupeshtiwari.com"> www.rupeshtiwari.com</a>
110+
✉️ <a href="mailto:fullstackmaster1@gmail.com?subject=Hi"> Email Rupesh</a>
101111
Founder of <a href="https://www.fullstackmaster.net"> Fullstack Master</a>
102112

0 commit comments

Comments
 (0)