Exploring effects in my project, I am working on implementing a warning notification when a search operation fails. The actions related to search are defined like this:
export enum SearchActionTypes {
SearchActionSearch = '[Search] Action search',
SearchActionFulfilled = '[Search] Action search fulfilled',
SearchActionFailed = '[Search] Action search failed',
}
Incorporated within my application is a service capable of displaying notifications. My objective is to invoke this service when a 'SearchActionFailed' action is triggered. However, I am currently unsure how to construct the effect for this task. Presently, here is where I stand:
@Injectable()
export class NotificationEffects {
@Effect()
// Triggering error notification for invalid search inputs
searchFailEffect = this.actions$.pipe(
ofType(Search.SearchActionTypes.SearchActionFailed),
);
constructor(private actions$: Actions,
private notificationService: NotificationService) {}
}
The desired behavior is to utilize the notification service API upon detection of the specified action by the effect. The function call should follow this structure:
this.notificationService.createNotification('type', 'message'))
No specific data is required from the action payload; merely an invocation of the service upon detection of the failure action. Nevertheless, structuring this effect presents a challenge as it necessitates returning an observable, even though no data extraction is needed - just a signal to prompt the service in alerting the user about the erroneous input.