# angular4-events

> Events is a publish-subscribe style event system based on sqlProvider/angular2-pubsub

Latest version **11.0.0** (published 2021-05-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install angular4-events
pnpm add angular4-events
yarn add angular4-events
bun add angular4-events
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 11.0.0 |
| Published | 2021-05-12 |
| First published | 2017-10-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 364.7 KB |
| Known vulnerabilities | 0 (+21 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Quentin Ligier |
| Maintainers | qligier |
| Keywords | Angular4, Angular5, Angular6, Angular8, Angular10, Angular11, pubsub, events, angular4-service |

## Links

- npm: https://www.npmjs.com/package/angular4-events
- Repository: https://github.com/qligier/angular4-events
- Homepage: https://github.com/qligier/angular4-events#readme
- Issues: https://github.com/qligier/angular4-events/issues
- npm.io page: https://npm.io/package/angular4-events

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) ~6.6.0
- [@angular/core](https://npm.io/package/@angular/core.md) ~11.2.13
- [@angular/common](https://npm.io/package/@angular/common.md) ~11.2.13
- [@angular/compiler](https://npm.io/package/@angular/compiler.md) ~11.2.13
- [@angular/platform-browser](https://npm.io/package/@angular/platform-browser.md) ~11.2.13

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 11.0.0 (latest) — 2021-05-12
- 10.0.1 — 2021-05-12
- 10.0.0 — 2021-02-26
- 8.0.0 — 2019-05-30
- 5.0.2 — 2019-05-30
- 5.0.1 — 2018-06-10
- 5.0.0 — 2018-01-23
- 4.0.1 — 2017-10-04
- 4.0.0 — 2017-10-04

## README

# Events Service for Angular

Events is a publish-subscribe style event system based on [sqlProvider/angular2-pubsub](https://github.com/sqlProvider/angular2-pubsub) and modified to be similar to ionic-angular/Events.

## Usage
 - Import service in your codes or download via npm.

   - Angular 4: `npm install --save angular4-events@4.0.1`
   - Angular 5: `npm install --save angular4-events@5.0.0`
   - Angular 6: `npm install --save angular4-events@5.0.2`
   - Angular 8: `npm install --save angular4-events@8.0.0`
   - Angular 10: `npm install --save angular4-events@10.0.1`
   - Angular 11: `npm install --save angular4-events@11.0.1`
   - :warning: Version 5.0.1 is incompatible with Angular 5 and should have been version 6.0.0.

 - Add module bundle to imports in your application.
```typescript
...

import { EventsModule } from 'angular4-events';

@NgModule({
	declarations: [
		...
	],
	imports: [
		...
		EventsModule.forRoot()
	]
})

...
```
 - And import service wherever you want

## Documentation

#### Class Overview

```typescript
declare class EventsService {
	private events: Object;
	publish(event: string, eventObject?: any): void;
	subscribe(): undefined;
	subscribe(event: string): Observable<any>;
	subscribe(event: string, callback: (value: any) => void): Subscription;
	subscribe(event: string, callback: (value: any) => void, error: (error: any) => void): Subscription;
	subscribe(event: string, callback: (value: any) => void, error: (error: any) => void, complete: () => void): Subscription;
}
```

#### EventsService.publish(event: string, eventObject?: any): void
	
Publish event to all subscriber.

etc.
```typescript
export class OverlayComponent implements OnInit, OnDestroy {
	constructor(private events: EventsService) { }

	anyFunc(){
		this.events.publish('pleaseCloseSidenav', 'helloIAmOverlay');
	}
}
```

#### EventsService.subscribe(event: string): Observable<any>

Subscribe to channel. 

etc.
```typescript
export class NavigationComponent implements OnInit, OnDestroy {
	sideanvSub: any;
	
	constructor(private pubsub: EventsService) { }

	ngOnInit() {
		// usage of subscribe(event: string): <Observable<any>>;
		this.closeSidenavSub = this.pubsub.subscribe('pleaseCloseSidenav').subscribe((from) => {
			this.sidenavOpened = false;
		});

		// usage of subscribe(event: string, callback: (value: any) => void, error?: (error: any) => void, complete?: () => void): Subscription;
		this.openSidenavSub = this.pubsub.subscribe('pleaseOpenSidenav', (from) => {
			this.sidenavOpened = true;
		});
	}
	ngOnDestroy() {
		this.closeSidenavSub.unsubscribe();
		this.openSidenavSub.unsubscribe();
	}
```


## Build the source

Follow the steps to run the tests and build the source code.
```sh
npm install
npm test
npm run build
```
Commands above will generate the ready to use bundles under the `./dist` folder.

---
_Source: https://npm.io/package/angular4-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
