0.0.79 • Published 6 years ago

@softwarepioniere/ngrx-manager v0.0.79

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

HOW TO USE

Installation

Run

npm i @angular/common@^6.0.0-rc.0 || ^6.0.0 --save
npm i @angular/core@^6.0.0-rc.0 || ^6.0.0 --save
npm i @ngrx/effects@7.4.0 --save
npm i @ngrx/store@7.4.0 --save
npm i @ngrx/store-devtools@7.4.0 --save
npm i moment@2.24.0 --save
npm i ngrx-store-localstorage@7.0.0 --save
npm i ngx-moment@3.4.0 --save
npm i rxjs@6.5.2 --save
npm i @ngx-translate/core@11.0.1 --save
npm i @ngx-translate/http-loader@4.0.0 --save
npm i typescript@3.2.4 --save
npm i @softwarepioniere/language@^0.0.8 --save

Configuration

app.module.ts

imports: [
    ...
    NgrxManagerModule.forRoot(),
    ...

Sample implementation

The following code are available on github.

First you must add the ngrxManager to your actions like...

(anyActions).actions.ts

import {Action} from '@ngrx/store';
import {NgrxManagerConfig} from '@softwarepioniere/ngrx-manager/lib/model';
import {Post} from '../../data-api';

export const RESET_ACTION = '[ActionList] App reset';

export const GET_POSTS_ACTION = '[ActionList] Load posts';
export const GET_POSTS_SUCCESS_ACTION = '[ActionList] Loading posts succeeded';
export const GET_POSTS_FAILED_ACTION = '[ActionList] Loading posts failed';

export const POST_INSERT_POST_ACTION = '[ActionList] Insert Post';
export const POST_INSERT_POST_SUCCESS_ACTION = '[ActionList] Insert Post succeeded';
export const POST_INSERT_POST_FAILED_ACTION = '[ActionList] Insert Post failed';


export class ResetAction implements Action {
    readonly type = RESET_ACTION;

    constructor() {
    }
}

// GET POSTS
export class GetPostsAction implements Action {
    readonly type = GET_POSTS_ACTION;

    constructor(public optPayload: any = null, public ngrxManager: NgrxManagerConfig = null) {
    }
}


export class GetPostsSuccessAction implements Action {
    readonly type = GET_POSTS_SUCCESS_ACTION;

    constructor(public payload: any, public optPayload: any = null, public ngrxManager: NgrxManagerConfig = null) {
    }
}


export class GetPostsFailedAction implements Action {
    readonly type = GET_POSTS_FAILED_ACTION;

    constructor(public payload: any, public optPayload: any = null, public ngrxManager: NgrxManagerConfig = null) {
    }
}

// POST INSERT POST
export class PostInsertPostAction implements Action {
    readonly type = POST_INSERT_POST_ACTION;

    constructor(public post: Post, public optPayload: any = null, public ngrxManager: NgrxManagerConfig = null) {
    }
}


export class PostInsertPostSuccessAction implements Action {
    readonly type = POST_INSERT_POST_SUCCESS_ACTION;

    constructor(public payload: any, public optPayload: any = null, public ngrxManager: NgrxManagerConfig = null) {
    }
}


export class PostInsertPostFailedAction implements Action {
    readonly type = POST_INSERT_POST_FAILED_ACTION;

    constructor(public payload: any, public optPayload: any = null, public ngrxManager: NgrxManagerConfig = null) {
    }
}

export type Actions =
    GetPostsAction
    | GetPostsSuccessAction
    | GetPostsFailedAction
    | PostInsertPostAction
    | PostInsertPostSuccessAction
    | PostInsertPostFailedAction
    | ResetAction
    ;

First you must change your query and post effects, so that each call use the ngrxManager to check if call can execute or must be wait.

(anyQuery).effects.ts

@Effect()
    getPosts$: Observable<Action> = this.actions$.pipe(
        ofType(ac.GET_POSTS_ACTION),
        map((x: ac.GetPostsAction) => {
            return this.ngrxManagerService.checkRequestCall(ac.GET_POSTS_ACTION, x, RequestMethod.QUERY, RequestType.Anfrage);
        }),
        filter(x => typeof x !== 'boolean'),
        flatMap((x: ac.GetPostsAction) => {
            const optPayload = (x !== undefined && x !== null && x.optPayload !== undefined) ? x.optPayload : null;
            return this._dataService.getPosts()
                .map((result: any) => {
                    const nextAction = new ac.GetPostsSuccessAction(result, optPayload);
                    this.ngrxManagerService.checkRequestResult(ac.GET_POSTS_ACTION, x, RequestMethod.QUERY, RequestType.Erfolgreich, nextAction);
                    return nextAction;
                })
                .catch((error: any) => {
                    const nextAction = new ac.GetPostsFailedAction(error, optPayload);
                    this.ngrxManagerService.checkRequestResult(ac.GET_POSTS_ACTION, x, RequestMethod.QUERY, RequestType.Fehler, nextAction, error);
                    return of(nextAction);
                });
        })
    );

(anyPost).effects.ts

 @Effect()
    insertPost$: Observable<Action> = this.actions$.pipe(
        ofType(ac.POST_INSERT_POST_ACTION),
        map((x: ac.GetPostsAction) => {
            return this.ngrxManagerService.checkRequestCall(ac.POST_INSERT_POST_ACTION, x, RequestMethod.COMMAND, RequestType.Anfrage);
        }),
        filter(x => typeof x !== 'boolean'),
        flatMap((x: ac.PostInsertPostAction) => {
            const optPayload = (x !== undefined && x !== null && x.optPayload !== undefined) ? x.optPayload : null;
            return this._dataService.postInsertPost()
                .map((result: any) => {
                    const nextAction = new ac.PostInsertPostSuccessAction(result, optPayload);
                    this.ngrxManagerService.checkRequestResult(ac.POST_INSERT_POST_ACTION, x, RequestMethod.COMMAND, RequestType.Erfolgreich, nextAction);
                    return nextAction;
                })
                .catch((error: any) => {
                    const nextAction = new ac.PostInsertPostFailedAction(error, optPayload);
                    this.ngrxManagerService.checkRequestResult(ac.POST_INSERT_POST_ACTION, x, RequestMethod.COMMAND, RequestType.Fehler, nextAction, error);
                    return of(nextAction);
                });
        })
    );

Application Insight

To track track executed, non executed, failed or succeeded query, the ngrxManager send this actions:

export const INSIGHTS_QUERY_NOT_EXECUTED = '[SopiNgrxManager] Insights :: Query execution';
export const INSIGHTS_QUERY_EXECUTE = '[SopiNgrxManager] Insights :: Query execution';
export const INSIGHTS_QUERY_SUCCESS = '[SopiNgrxManager] Insights :: Query success';
export const INSIGHTS_QUERY_FAILED = '[SopiNgrxManager] Insights :: Query failed';
export const INSIGHTS_QUERY_FAILED_BAD_REQUEST = '[SopiNgrxManager] Insights :: Query failed with bad request';

export const INSIGHTS_COMMAND_NOT_EXECUTED = '[SopiNgrxManager] Insights :: Command execution';
export const INSIGHTS_COMMAND_EXECUTE = '[SopiNgrxManager] Insights :: Command execution';
export const INSIGHTS_COMMAND_SUCCESS = '[SopiNgrxManager] Insights :: Command success';
export const INSIGHTS_COMMAND_FAILED = '[SopiNgrxManager] Insights :: Command failed';
export const INSIGHTS_COMMAND_FAILED_BAD_REQUEST = '[SopiNgrxManager] Insights :: Command failed with bad request';
0.0.79

6 years ago

0.0.78

6 years ago

0.0.77

6 years ago

0.0.76

6 years ago

0.0.75

6 years ago

0.0.74

6 years ago

0.0.72

6 years ago

0.0.71

6 years ago

0.0.70

6 years ago

0.0.69

6 years ago

0.0.68

6 years ago

0.0.67

6 years ago

0.0.66

6 years ago

0.0.65

6 years ago

0.0.63

6 years ago

0.0.62

6 years ago

0.0.61

6 years ago

0.0.59

6 years ago

0.0.58

6 years ago

0.0.57

6 years ago

0.0.55

6 years ago

0.0.54

6 years ago

0.0.53

6 years ago

0.0.49

6 years ago

0.0.48

6 years ago

0.0.47

6 years ago

0.0.46

6 years ago

0.0.45

6 years ago

0.0.44

6 years ago

0.0.43

6 years ago

0.0.42

6 years ago

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.38

6 years ago

0.0.37

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.32

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.1

6 years ago