-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/web-mzima-client/src/app/core/services/event-tracker.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Injectable, OnInit } from '@angular/core'; | ||
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; | ||
import { EventBusService, EventType } from './event-bus.service'; | ||
|
||
@UntilDestroy() | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class EventTrackerService implements OnInit { | ||
public action: EventType; | ||
public response: any; | ||
public updateById: boolean | undefined; | ||
constructor(private eventBusService: EventBusService) {} | ||
|
||
// eslint-disable-next-line @angular-eslint/contextual-lifecycle | ||
ngOnInit() { | ||
console.log('OnInit: Let my people go...'); | ||
// this.emit({ payload }) | ||
// this.trigger({ action: this.action, updateById: this.updateById }); | ||
} | ||
|
||
// setTrigger({ action, updateById }: { action: EventType; updateById?: boolean }) { | ||
|
||
// } | ||
|
||
public trigger({ action, updateById }: { action: EventType; updateById?: boolean }) { | ||
this.action = action; | ||
this.updateById = updateById; | ||
|
||
this.eventBusService | ||
.on(this.action) | ||
.pipe(untilDestroyed(this)) | ||
.subscribe({ | ||
next: (response) => { | ||
console.log(response); | ||
console.log(this.action); | ||
this.action = action; | ||
this.response = response; | ||
this.updateById = updateById; | ||
const setResponse = () => (this.response = response); | ||
if (updateById) { | ||
if (this.response.id === response.id) setResponse(); | ||
} else { | ||
setResponse(); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
public emit({ payload }: { payload: any }) { | ||
console.log(this.action, payload); | ||
this.eventBusService.next({ | ||
type: this.action, | ||
payload, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters