@zeniai/client-epic-state 4.10.10 → 4.10.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ export declare const isAllFetchCompleted: (fetchStateList: FetchStateAndError[])
16
16
  * @param fetchStateList list of fetch states
17
17
  * @returns true if any fetch state is erroed out.
18
18
  */
19
- export declare const isAnyFetchErredOut: (fetchStateList: FetchStateAndError[]) => boolean;
19
+ export declare const isAnyFetchErroredOut: (fetchStateList: FetchStateAndError[]) => boolean;
20
20
  /**
21
21
  * Reduces list of fetch state to single fetchState
22
22
  * @param fetchStateList list of fetch states
@@ -40,7 +40,7 @@ export declare const isAnyFetchCompleted: (fetchStateList: FetchStateAndError[])
40
40
  * @param fetchStateList list of fetch states
41
41
  * @returns true if all fetch states are errored out.
42
42
  */
43
- export declare const isAllFetchErredOut: (fetchStateList: FetchStateAndError[]) => boolean;
43
+ export declare const isAllFetchErroredOut: (fetchStateList: FetchStateAndError[]) => boolean;
44
44
  /**
45
45
  * Reduces list of fetch state to single fetchState
46
46
  * @param fetchStateList list of fetch states
@@ -53,3 +53,9 @@ export declare const reduceAnyFetchState: (fetchStateList: FetchStateAndError[])
53
53
  * @returns If all fetch states are completed, then the fetch state comes back as completed, if all of them are errored out, then state comes as error.
54
54
  */
55
55
  export declare const reduceAllFetchState: (fetchStateList: FetchStateAndError[]) => FetchStateAndError;
56
+ /**
57
+ * Reduces list of fetch state to single fetchState
58
+ * @param fetchStateList list of fetch states
59
+ * @returns If any fetch state is completed, then the fetch state comes back as completed, if any of them is errored out, then state comes as error.
60
+ */
61
+ export declare const reduceAnyCompletedFetchState: (fetchStateList: FetchStateAndError[]) => FetchStateAndError;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reduceAllFetchState = exports.reduceAnyFetchState = exports.isAllFetchErredOut = exports.isAnyFetchCompleted = exports.isAnyFetchInProgress = exports.reduceFetchState = exports.isAnyFetchErredOut = exports.isAllFetchCompleted = exports.isAllFetchInProgress = void 0;
3
+ exports.reduceAnyCompletedFetchState = exports.reduceAllFetchState = exports.reduceAnyFetchState = exports.isAllFetchErroredOut = exports.isAnyFetchCompleted = exports.isAnyFetchInProgress = exports.reduceFetchState = exports.isAnyFetchErroredOut = exports.isAllFetchCompleted = exports.isAllFetchInProgress = void 0;
4
4
  /**
5
5
  * Reduces list of fetch state to boolean
6
6
  * @param fetchStateList list of fetch states
@@ -24,10 +24,10 @@ exports.isAllFetchCompleted = isAllFetchCompleted;
24
24
  * @param fetchStateList list of fetch states
25
25
  * @returns true if any fetch state is erroed out.
26
26
  */
27
- const isAnyFetchErredOut = (fetchStateList) => fetchStateList.reduce((prevValue, currentValue) => {
27
+ const isAnyFetchErroredOut = (fetchStateList) => fetchStateList.reduce((prevValue, currentValue) => {
28
28
  return prevValue === true || currentValue.fetchState === 'Error';
29
29
  }, false);
30
- exports.isAnyFetchErredOut = isAnyFetchErredOut;
30
+ exports.isAnyFetchErroredOut = isAnyFetchErroredOut;
31
31
  const reduceError = (fetchStateList) => fetchStateList.reduce((prevValue, currentValue) => {
32
32
  return prevValue !== null && prevValue !== void 0 ? prevValue : currentValue.error;
33
33
  }, undefined);
@@ -39,7 +39,7 @@ const reduceError = (fetchStateList) => fetchStateList.reduce((prevValue, curren
39
39
  function reduceFetchState(fetchStateList) {
40
40
  const isAllInProgress = (0, exports.isAllFetchInProgress)(fetchStateList);
41
41
  const isAllCompleted = (0, exports.isAllFetchCompleted)(fetchStateList);
42
- const isAnyError = (0, exports.isAnyFetchErredOut)(fetchStateList);
42
+ const isAnyError = (0, exports.isAnyFetchErroredOut)(fetchStateList);
43
43
  const error = reduceError(fetchStateList);
44
44
  let fetchState = 'Not-Started';
45
45
  if (isAllInProgress) {
@@ -80,10 +80,10 @@ exports.isAnyFetchCompleted = isAnyFetchCompleted;
80
80
  * @param fetchStateList list of fetch states
81
81
  * @returns true if all fetch states are errored out.
82
82
  */
83
- const isAllFetchErredOut = (fetchStateList) => fetchStateList.reduce((prevValue, currentValue) => {
83
+ const isAllFetchErroredOut = (fetchStateList) => fetchStateList.reduce((prevValue, currentValue) => {
84
84
  return prevValue === true && currentValue.fetchState === 'Error';
85
85
  }, true);
86
- exports.isAllFetchErredOut = isAllFetchErredOut;
86
+ exports.isAllFetchErroredOut = isAllFetchErroredOut;
87
87
  /**
88
88
  * Reduces list of fetch state to single fetchState
89
89
  * @param fetchStateList list of fetch states
@@ -92,7 +92,7 @@ exports.isAllFetchErredOut = isAllFetchErredOut;
92
92
  // TODO - Better name for other variants
93
93
  const reduceAnyFetchState = (fetchStateList) => {
94
94
  let fetchState = 'Not-Started';
95
- if ((0, exports.isAnyFetchErredOut)(fetchStateList)) {
95
+ if ((0, exports.isAnyFetchErroredOut)(fetchStateList)) {
96
96
  fetchState = 'Error';
97
97
  }
98
98
  else if ((0, exports.isAllFetchCompleted)(fetchStateList)) {
@@ -127,7 +127,7 @@ const reduceAllFetchState = (fetchStateList) => {
127
127
  else if ((0, exports.isAllFetchCompleted)(fetchStateList)) {
128
128
  fetchState = 'Completed';
129
129
  }
130
- else if ((0, exports.isAllFetchErredOut)(fetchStateList)) {
130
+ else if ((0, exports.isAllFetchErroredOut)(fetchStateList)) {
131
131
  fetchState = 'Error';
132
132
  }
133
133
  return {
@@ -136,3 +136,34 @@ const reduceAllFetchState = (fetchStateList) => {
136
136
  };
137
137
  };
138
138
  exports.reduceAllFetchState = reduceAllFetchState;
139
+ /**
140
+ * Reduces list of fetch state to single fetchState
141
+ * @param fetchStateList list of fetch states
142
+ * @returns If any fetch state is completed, then the fetch state comes back as completed, if any of them is errored out, then state comes as error.
143
+ */
144
+ const reduceAnyCompletedFetchState = (fetchStateList) => {
145
+ let fetchState = 'Not-Started';
146
+ const error = reduceError(fetchStateList);
147
+ if (fetchStateList.length === 0) {
148
+ return {
149
+ fetchState,
150
+ error,
151
+ };
152
+ }
153
+ if ((0, exports.isAllFetchInProgress)(fetchStateList)) {
154
+ fetchState = 'In-Progress';
155
+ }
156
+ else if ((0, exports.isAnyFetchCompleted)(fetchStateList)) {
157
+ // This scenario is useful where we have two independnet apis and want to rely/react as soon as one api returns valid response
158
+ fetchState = 'Completed';
159
+ }
160
+ else if ((0, exports.isAnyFetchErroredOut)(fetchStateList)) {
161
+ // So we are not bothered much about `error` scenario before any completed state
162
+ fetchState = 'Error';
163
+ }
164
+ return {
165
+ fetchState,
166
+ error,
167
+ };
168
+ };
169
+ exports.reduceAnyCompletedFetchState = reduceAnyCompletedFetchState;
@@ -326,7 +326,7 @@ const notificationView = (0, toolkit_1.createSlice)({
326
326
  updateNotificationViewTabState: {
327
327
  reducer(draft, action) {
328
328
  const { notificationTabState, tab } = action.payload;
329
- const { allNotificationsIds, selectedNotificationIds, fetchCountState, markAsReadState, markAsAllReadState, } = notificationTabState;
329
+ const { allNotificationsIds, selectedNotificationIds, fetchCountState, markAsReadState, markAsAllReadState, fetchState, error, } = notificationTabState;
330
330
  if (allNotificationsIds != null) {
331
331
  draft.stateByTab[tab].allNotificationsIds = allNotificationsIds;
332
332
  }
@@ -334,6 +334,12 @@ const notificationView = (0, toolkit_1.createSlice)({
334
334
  draft.stateByTab[tab].selectedNotificationIds =
335
335
  selectedNotificationIds;
336
336
  }
337
+ if (fetchState != null) {
338
+ draft.stateByTab[tab].fetchState = fetchState;
339
+ }
340
+ if (error != null) {
341
+ draft.stateByTab[tab].error = error;
342
+ }
337
343
  if (fetchCountState != null) {
338
344
  draft.stateByTab[tab].fetchCountState = fetchCountState;
339
345
  }
@@ -11,7 +11,7 @@ exports.getNotificationView = (0, toolkit_1.createSelector)((state) => state.not
11
11
  tasks: Object.assign(Object.assign({}, stateByTab.tasks), { allNotificationsIdsForSubTab: [], selectedNotificationIdsForSubTab: [] }),
12
12
  comments: Object.assign(Object.assign({}, stateByTab.comments), { allNotificationsIdsForSubTab: [], selectedNotificationIdsForSubTab: [] }),
13
13
  };
14
- const reducedFetchCountState = (0, reduceFetchState_1.reduceAllFetchState)(Object.values(stateByTab).map((tabDetails) => tabDetails.fetchCountState));
14
+ const reducedFetchCountState = (0, reduceFetchState_1.reduceAnyCompletedFetchState)(Object.values(stateByTab).map((tabDetails) => tabDetails.fetchCountState));
15
15
  const { selectedNotificationIds } = notificationDetails[currentTab];
16
16
  const notificationsForCurrentTabAndSubTab = [];
17
17
  const externalNotificationsForCurrentTabAndSubTab = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "4.10.10",
3
+ "version": "4.10.11",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",