From 2252dfda6a20bd256a9e985fb5481a0c06755812 Mon Sep 17 00:00:00 2001 From: David Elcheikh <98789781+campiondelcheikh@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:06:37 +1000 Subject: [PATCH] Added: Succes pipe and code cleanup (#11) --- .github/workflows/npm-publish.yml | 2 +- .gitignore | 1 + ngrx-http-tracking/.gitignore | 3 ++- .../function/http-tracking-actions.factory.ts | 4 ++-- .../src/lib/function/map-action-typ-to-id.ts | 4 ++-- .../src/lib/function/tracking-success-pipe.ts | 19 +++++++++++++++++++ .../ngrx-http-tracking/src/public-api.ts | 4 +--- 7 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/tracking-success-pipe.ts diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 7f07fcf..12a1a19 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -1,4 +1,4 @@ -name: Utils publish on tag +name: npm publish on tag on: push: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/ngrx-http-tracking/.gitignore b/ngrx-http-tracking/.gitignore index 69db5e0..5022850 100644 --- a/ngrx-http-tracking/.gitignore +++ b/ngrx-http-tracking/.gitignore @@ -13,7 +13,7 @@ chrome-profiler-events*.json # IDEs and editors -/.idea +.idea .project .classpath .c9/ @@ -43,3 +43,4 @@ testem.log # System Files .DS_Store Thumbs.db + diff --git a/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/http-tracking-actions.factory.ts b/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/http-tracking-actions.factory.ts index f60ad3e..6f7f61b 100644 --- a/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/http-tracking-actions.factory.ts +++ b/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/http-tracking-actions.factory.ts @@ -162,14 +162,14 @@ export const createTrackingActions = ( props<{ request: TRequest }>() ), loaded: createTrackingAction( - `[${namespace}] ${actionName}Success`, + `[${namespace}] ${actionName} Success`, hasGlobalTag, tags, LoadingState.LOADED, props<{ payload: TPayload }>() ), failure: createTrackingFailureAction( - `[${namespace}] ${actionName}Failure`, + `[${namespace}] ${actionName} Failure`, hasGlobalTag, tags, convertResponseToError diff --git a/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/map-action-typ-to-id.ts b/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/map-action-typ-to-id.ts index e83c9a8..a12c1be 100644 --- a/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/map-action-typ-to-id.ts +++ b/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/map-action-typ-to-id.ts @@ -1,7 +1,7 @@ export const mapActionTypeToId = (actionType: string) => actionType .toLowerCase() - .replace(/success/g, '') - .replace(/failure/g, '') + .replace(/ success/g, '') + .replace(/ failure/g, '') .trim() .replace(/ /g, '-'); diff --git a/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/tracking-success-pipe.ts b/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/tracking-success-pipe.ts new file mode 100644 index 0000000..5b589f6 --- /dev/null +++ b/ngrx-http-tracking/projects/ngrx-http-tracking/src/lib/function/tracking-success-pipe.ts @@ -0,0 +1,19 @@ +import {Observable} from "rxjs"; +import {HttpTrackingResult} from "../+state/http-tracking.facade"; +export function httpTrackingSuccessFilter(source: Observable>): Observable { + return new Observable(subscriber => { + source.subscribe({ + next(value) { + if (value.success) { + return subscriber.next(true); + } + }, + error(error) { + subscriber.error(error); + }, + complete() { + subscriber.complete(); + }, + }); + }); +} diff --git a/ngrx-http-tracking/projects/ngrx-http-tracking/src/public-api.ts b/ngrx-http-tracking/projects/ngrx-http-tracking/src/public-api.ts index 3a9115f..df2e21c 100644 --- a/ngrx-http-tracking/projects/ngrx-http-tracking/src/public-api.ts +++ b/ngrx-http-tracking/projects/ngrx-http-tracking/src/public-api.ts @@ -1,8 +1,6 @@ -/* - * Public API Surface of http-tracking - */ export * from './lib/+state/http-tracking-facade.stub'; export * from './lib/+state/http-tracking.facade'; export * from './lib/function/http-tracking-actions.factory'; export * from './lib/http-tracking.module'; export * from './lib/model/http-tracking-entity'; +export * from './lib/function/tracking-success-pipe';