Skip to content

Commit

Permalink
Merge pull request #41 from cristiammercado/develop
Browse files Browse the repository at this point in the history
Improvements and updates
  • Loading branch information
cristiammercado authored Dec 17, 2023
2 parents 25e1458 + 4dd8e06 commit 8337619
Show file tree
Hide file tree
Showing 57 changed files with 6,019 additions and 4,000 deletions.
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2.1

orbs:
node: circleci/node@5.1.0
browser-tools: circleci/browser-tools@1.4.1
node: circleci/node@5.1.1
browser-tools: circleci/browser-tools@1.4.6

jobs:
build:
Expand All @@ -23,17 +23,17 @@ jobs:
- save_cache:
key: v1-npm-deps-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- node_modules
- run:
name: Build
command: npm run build
- run:
name: Test
command: npm run test
- store_test_results:
path: ./coverage/junit-report.xml
path: coverage/ng-event-bus/junit
- store_artifacts:
path: ./coverage/html-report
- run:
name: Build
command: npm run build
path: coverage/ng-event-bus/html-report

workflows:
test-and-build:
Expand Down
4 changes: 4 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["angular.ng-template"]
}
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: test",
"url": "http://localhost:9876/debug.html"
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
},
{
"type": "npm",
"script": "test",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
}
]
}
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ RxJS-based message/event bus service for Angular apps inspired by [NgRadio](http

`npm install --save ng-event-bus`

## Angular Compatibility Table

| Angular version | ng-event-bus version |
|-----------------|----------------------|
| 17.x | 6.0.x |
| 16.x | 5.1.x |
| 15.x | 5.0.x |
| 15.x | 5.0.x |
| 14.x | 4.x.x |
| 13.x | 4.x.x |
| 12.x | 3.x.x |
| 11.x | 2.x.x |

## Usage

First, import it:
Expand Down Expand Up @@ -41,12 +54,12 @@ Since you have `NgEventBus` instance in your app, you can use these methods for

Where:

- `key` must be a string and must not be empty, otherwise it will throw an exception.
- `data` is optional and can be any type of object.
- `pattern` must be a string and must not be empty.
- `key` must be a string and must not be empty, otherwise it will throw an exception.
- `data` is optional and can be any type of object.
- `pattern` must be a string and must not be empty.

### Patterns

Patterns may contain multiple segments split by `:`. Use this feature to create namespaces for messages you cast. You can use `*` in `pattern` to subscribe to any matching segment, or use `**` to subscribe to all segments, starting from particular position.

For example, you can use `on('error:*')` and subscribe to all errors, including something like `error:http` or `error:internal` and so on:
Expand Down Expand Up @@ -78,15 +91,15 @@ this.eventBus.on('**').subscribe((meta: MetaData) => {
```

### MetaData (Breaking change in v2.x.x)
### MetaData

When you subscribe to the observable, you can optionally get an instance of `MetaData` class. This instance contains information related to the emission of the event through the bus. The properties of this instance are:

- `id`: A unique identifier of the message sent through the events bus.
- `key`: Original key associated to the message.
- `data`: Data associated to message. It's optional.
- `timestamp`: Time in milliseconds in which the message was generated.
- `id`: A unique identifier of the message sent through the events bus.
- `key`: Original key associated to the message.
- `data`: Data associated to message. It's optional.
- `timestamp`: Time in milliseconds in which the message was generated.

```
this.eventBus.cast('app:start', 'started');
Expand Down Expand Up @@ -115,25 +128,25 @@ this.eventBus.on('**').subscribe((meta: MetaData) => {

These strings will match:

- `on('**' ).suscribe` can subscribe to any message with any segments count
- `on('**' ).suscribe` can subscribe to any message with any segments count

- `on('a' ).suscribe` can subscribe to `cast('a', ...)`
- `on('a' ).suscribe` can subscribe to `cast('a', ...)`

- `on('a:b' ).suscribe` can subscribe to `cast('a:b', ...)`
- `on('a:b' ).suscribe` can subscribe to `cast('a:b', ...)`

- `on('a:b:c' ).suscribe` can subscribe to `cast('a:b:c', ...)`
- `on('a:b:c' ).suscribe` can subscribe to `cast('a:b:c', ...)`

- `on('a:**' ).suscribe` can subscribe to `cast('a:b:c', ...)`, `cast('a:b:c:d:e:f', ...)`
- `on('a:**' ).suscribe` can subscribe to `cast('a:b:c', ...)`, `cast('a:b:c:d:e:f', ...)`

- `on('a:*:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`, `cast('a:f:g', ...)`, `cast('a:n:m', ...)`
- `on('a:*:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`, `cast('a:f:g', ...)`, `cast('a:n:m', ...)`

- `on('a:b:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`, `cast('a:b:d', ...)`, but not `cast('a:b', ...)`
- `on('a:b:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`, `cast('a:b:d', ...)`, but not `cast('a:b', ...)`

- `on('a:b:**').suscribe` can subscribe to `cast('a:b:c',. ..)`
- `on('a:b:**').suscribe` can subscribe to `cast('a:b:c',. ..)`

- `on('*:b:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`
- `on('*:b:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`

- `on('a:*:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`
- `on('a:*:*' ).suscribe` can subscribe to `cast('a:b:c', ...)`

### Need to unsubscribe (observable)?

Expand Down
29 changes: 13 additions & 16 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
"projects": {
"ng-event-bus": {
"projectType": "library",
"root": "./",
"sourceRoot": "./src",
"root": "projects/ng-event-bus",
"sourceRoot": "projects/ng-event-bus/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"project": "./ng-package.json"
"project": "projects/ng-event-bus/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "./tsconfig.lib.prod.json"
"tsConfig": "projects/ng-event-bus/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "./tsconfig.lib.json"
"tsConfig": "projects/ng-event-bus/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"tsConfig": "./tsconfig.spec.json",
"karmaConfig": "./karma.conf.js",
"tsConfig": "projects/ng-event-bus/tsconfig.spec.json",
"karmaConfig": "projects/ng-event-bus/karma.conf.js",
"polyfills": [
"zone.js",
"zone.js/testing"
Expand All @@ -49,11 +49,11 @@
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/demo",
"index": "projects/demo/src/index.html",
"main": "projects/demo/src/main.ts",
"browser": "projects/demo/src/main.ts",
"polyfills": [
"zone.js"
],
Expand Down Expand Up @@ -85,12 +85,9 @@
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
"sourceMap": true
}
},
"defaultConfiguration": "production"
Expand All @@ -99,18 +96,18 @@
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "demo:build:production"
"buildTarget": "demo:build:production"
},
"development": {
"browserTarget": "demo:build:development"
"buildTarget": "demo:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "demo:build"
"buildTarget": "demo:build"
}
}
}
Expand Down
21 changes: 0 additions & 21 deletions dist/LICENSE

This file was deleted.

6 changes: 0 additions & 6 deletions dist/esm2020/index.mjs

This file was deleted.

2 changes: 0 additions & 2 deletions dist/esm2020/lib/i-event-bus-message.mjs

This file was deleted.

60 changes: 0 additions & 60 deletions dist/esm2020/lib/meta-data.mjs

This file was deleted.

Loading

0 comments on commit 8337619

Please sign in to comment.