• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

satanTime / ngrx-correlation-id / 248bcece-8bf8-4673-ae52-b1bb41c7d169

pending completion
248bcece-8bf8-4673-ae52-b1bb41c7d169

push

CircleCI

web-flow
Merge pull request #1474 from satanTime/dependabot/npm_and_yarn/e2e/a12/jszip-3.10.1

10 of 33 branches covered (30.3%)

Branch coverage included in aggregate %.

30 of 58 relevant lines covered (51.72%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.84
/projects/ngrx-correlation-id/src/lib/reducer.ts
1
import {createFeatureSelector} from '@ngrx/store';
2

3
import {CidActions, cidEnd, cidPayload, cidRemove, cidStart} from './actions';
4

5
export interface CidTask<T = any> {
6
  cid: string;
7
  inProgress: boolean;
8
  payload?: T;
9
}
10

11
export interface State<T = any> {
12
  tasks: Array<string>;
13
  payloads: {
14
    [taskId: string]: CidTask<T>['payload'];
15
  };
16
}
17

18
const initialState: State = {
1✔
19
  tasks: [],
20
  payloads: {},
21
};
22

23
export function cidReducer(state: State = initialState, action: CidActions): State {
×
24
  switch (action.type) {
1!
25
    case cidStart.type:
26
      return {
×
27
        ...state,
28
        tasks: [...state.tasks, action.cid],
29
      };
30

31
    case cidEnd.type:
32
      const index = state.tasks.indexOf(action.cid);
×
33
      if (index === -1) {
×
34
        return state;
×
35
      }
36
      return {
×
37
        ...state,
38
        tasks: state.tasks.filter((_, taskIndex) => taskIndex !== index),
×
39
      };
40

41
    case cidPayload.type:
42
      if (state.payloads[action.cid] === action.payload) {
×
43
        return state;
×
44
      }
45
      return {
×
46
        ...state,
47
        payloads: {
48
          ...state.payloads,
49
          [action.cid]: action.payload,
50
        },
51
      };
52

53
    case cidRemove.type:
54
      if (state.tasks.indexOf(action.cid) === -1 && state.payloads[action.cid] === undefined) {
1!
55
        return state;
×
56
      }
57
      return {
1✔
58
        ...state,
59
        tasks:
60
          state.tasks.indexOf(action.cid) === -1 ? state.tasks : state.tasks.filter(taskId => taskId !== action.cid),
×
61
        payloads:
62
          state.payloads[action.cid] === undefined
1!
63
            ? state.payloads
64
            : Object.keys(state.payloads).reduce<State['payloads']>((result, taskId) => {
65
                if (taskId !== action.cid && state.payloads[taskId] !== undefined) {
4✔
66
                  result[taskId] = state.payloads[taskId];
2✔
67
                }
68
                return result;
4✔
69
              }, {}),
70
      };
71
  }
72

73
  return state;
×
74
}
75

76
export const selectCidFeature: <T extends object>(state: T) => State = createFeatureSelector('ngrxCorrelationId');
1✔
77

78
const selectCidResult = new Map<string, CidTask>();
1✔
79
const selectCidInternal: any = (state: any, cid: string) => {
1✔
80
  const feature = selectCidFeature(state);
×
81
  const actual = {
×
82
    cid,
83
    inProgress: feature.tasks.indexOf(cid) !== -1,
84
    payload: feature.payloads[cid],
85
  };
86
  const old = selectCidResult.get(cid);
×
87
  // in progress shouldn't be affected by payload change
88
  if (old && old.inProgress && old.inProgress === actual.inProgress && old.cid === actual.cid) {
×
89
    return old;
×
90
  }
91
  if (old && old.inProgress === actual.inProgress && old.cid === actual.cid && old.payload === actual.payload) {
×
92
    return old;
×
93
  }
94
  selectCidResult.set(cid, actual);
×
95
  return actual;
×
96
};
97
selectCidInternal.release = () => {
1✔
98
  selectCidResult.clear();
×
99
};
100

101
export const selectCid: {
102
  <T = any>(state: any, cid: string): CidTask<T>;
103
  release(): void;
104
} = selectCidInternal;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc