react-redux-cache 0.22.1 → 0.22.2

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.
@@ -1,40 +1,79 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1
+ var __awaiter =
2
+ (this && this.__awaiter) ||
3
+ function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P
6
+ ? value
7
+ : new P(function (resolve) {
8
+ resolve(value)
9
+ })
10
+ }
3
11
  return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { useMemo } from 'react';
11
- import { mutate as mutateImpl } from './mutate';
12
- import { EMPTY_OBJECT, logDebug } from './utilsAndConstants';
12
+ function fulfilled(value) {
13
+ try {
14
+ step(generator.next(value))
15
+ } catch (e) {
16
+ reject(e)
17
+ }
18
+ }
19
+ function rejected(value) {
20
+ try {
21
+ step(generator['throw'](value))
22
+ } catch (e) {
23
+ reject(e)
24
+ }
25
+ }
26
+ function step(result) {
27
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
28
+ }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next())
30
+ })
31
+ }
32
+ import {useMemo} from 'react'
33
+
34
+ import {mutate as mutateImpl} from './mutate'
35
+ import {EMPTY_OBJECT, logDebug} from './utilsAndConstants'
36
+
13
37
  export const useMutation = (cache, actions, selectors, options, abortControllers) => {
14
- var _a;
15
- const { selectMutationState } = selectors;
16
- const { updateMutationStateAndEntities } = actions;
17
- const { mutation: mutationKey, onCompleted, onSuccess, onError } = options;
18
- const store = cache.storeHooks.useStore();
19
- const [mutationStateSelector, mutate, abort] = useMemo(() => {
20
- return [
21
- (state) => selectMutationState(state, mutationKey),
22
- (params) => __awaiter(void 0, void 0, void 0, function* () {
23
- return yield mutateImpl('useMutation.mutate', store, cache, actions, selectors, mutationKey, params, abortControllers, onCompleted, onSuccess, onError);
24
- }),
25
- () => {
26
- var _a;
27
- const abortController = (_a = abortControllers.get(store)) === null || _a === void 0 ? void 0 : _a[mutationKey];
28
- if (abortController === undefined || abortController.signal.aborted) {
29
- return false;
30
- }
31
- abortController.abort();
32
- store.dispatch(updateMutationStateAndEntities(mutationKey, { loading: undefined }));
33
- return true;
34
- },
35
- ];
36
- }, [mutationKey, store]);
37
- const mutationState = (_a = cache.storeHooks.useSelector(mutationStateSelector)) !== null && _a !== void 0 ? _a : EMPTY_OBJECT;
38
- cache.options.logsEnabled && logDebug('useMutation', { options, mutationState });
39
- return [mutate, mutationState, abort];
40
- };
38
+ var _a
39
+ const {selectMutationState} = selectors
40
+ const {updateMutationStateAndEntities} = actions
41
+ const {mutation: mutationKey, onCompleted, onSuccess, onError} = options
42
+ const store = cache.storeHooks.useStore()
43
+ const [mutationStateSelector, mutate, abort] = useMemo(() => {
44
+ return [
45
+ (state) => selectMutationState(state, mutationKey),
46
+ (params) =>
47
+ __awaiter(void 0, void 0, void 0, function* () {
48
+ return yield mutateImpl(
49
+ 'useMutation.mutate',
50
+ store,
51
+ cache,
52
+ actions,
53
+ selectors,
54
+ mutationKey,
55
+ params,
56
+ abortControllers,
57
+ onCompleted,
58
+ onSuccess,
59
+ onError,
60
+ )
61
+ }),
62
+ () => {
63
+ var _a
64
+ const abortController =
65
+ (_a = abortControllers.get(store)) === null || _a === void 0 ? void 0 : _a[mutationKey]
66
+ if (abortController === undefined || abortController.signal.aborted) {
67
+ return false
68
+ }
69
+ abortController.abort()
70
+ store.dispatch(updateMutationStateAndEntities(mutationKey, {loading: undefined}))
71
+ return true
72
+ },
73
+ ]
74
+ }, [mutationKey, store])
75
+ const mutationState =
76
+ (_a = cache.storeHooks.useSelector(mutationStateSelector)) !== null && _a !== void 0 ? _a : EMPTY_OBJECT
77
+ cache.options.logsEnabled && logDebug('useMutation', {options, mutationState})
78
+ return [mutate, mutationState, abort]
79
+ }
@@ -1,55 +1,122 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1
+ var __awaiter =
2
+ (this && this.__awaiter) ||
3
+ function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P
6
+ ? value
7
+ : new P(function (resolve) {
8
+ resolve(value)
9
+ })
10
+ }
3
11
  return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { useCallback, useEffect } from 'react';
11
- import { query as queryImpl } from './query';
12
- import { createStateComparer, defaultGetCacheKey, EMPTY_OBJECT, logDebug } from './utilsAndConstants';
13
- export const useQuery = (cache, actions, selectors, options) => {
14
- var _a, _b, _c, _d, _e;
15
- const { query: queryKey, skipFetch = false, params, secondsToLive, selectorComparer, fetchPolicy = (_a = cache.queries[queryKey].fetchPolicy) !== null && _a !== void 0 ? _a : cache.globals.queries.fetchPolicy, mergeResults, onCompleted, onSuccess, onError, } = options;
16
- const { selectQueryState } = selectors;
17
- const queryInfo = cache.queries[queryKey];
18
- const logsEnabled = cache.options.logsEnabled;
19
- const getCacheKey = (_b = queryInfo.getCacheKey) !== null && _b !== void 0 ? _b : (defaultGetCacheKey);
20
- const comparer = selectorComparer === undefined
21
- ? ((_d = (_c = queryInfo.selectorComparer) !== null && _c !== void 0 ? _c : cache.globals.queries.selectorComparer) !== null && _d !== void 0 ? _d : defaultStateComparer)
22
- : typeof selectorComparer === 'function'
23
- ? selectorComparer
24
- : createStateComparer(selectorComparer);
25
- const store = cache.storeHooks.useStore();
26
- const cacheKey = getCacheKey(params);
27
- const performFetch = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
28
- const paramsPassed = options && 'params' in options;
29
- return yield queryImpl('useQuery.fetch', store, cache, actions, selectors, queryKey, paramsPassed ? getCacheKey(options.params) : cacheKey, paramsPassed ? options.params : params, secondsToLive, options === null || options === void 0 ? void 0 : options.onlyIfExpired, false, mergeResults, onCompleted, onSuccess, onError);
30
- }), [store, queryKey, cacheKey]);
31
- const queryState = (_e = cache.storeHooks.useSelector((state) => {
32
- return selectQueryState(state, queryKey, cacheKey);
33
- }, comparer)) !== null && _e !== void 0 ? _e : EMPTY_OBJECT;
34
- useEffect(() => {
35
- if (skipFetch) {
36
- logsEnabled && logDebug('useQuery.useEffect skip fetch', { skipFetch, queryKey, cacheKey });
37
- return;
12
+ function fulfilled(value) {
13
+ try {
14
+ step(generator.next(value))
15
+ } catch (e) {
16
+ reject(e)
38
17
  }
39
- const expired = queryState.expiresAt != null && queryState.expiresAt <= Date.now();
40
- if (!fetchPolicy(expired, params, queryState, store, selectors)) {
41
- logsEnabled &&
42
- logDebug('useQuery.useEffect skip fetch due to fetch policy', {
43
- queryState,
44
- expired,
45
- queryKey,
46
- cacheKey,
47
- });
48
- return;
18
+ }
19
+ function rejected(value) {
20
+ try {
21
+ step(generator['throw'](value))
22
+ } catch (e) {
23
+ reject(e)
49
24
  }
50
- performFetch();
51
- }, [cacheKey, skipFetch]);
52
- logsEnabled && logDebug('useQuery', { cacheKey, options, queryState });
53
- return [queryState, performFetch];
54
- };
55
- const defaultStateComparer = createStateComparer(['result', 'loading', 'params', 'error']);
25
+ }
26
+ function step(result) {
27
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
28
+ }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next())
30
+ })
31
+ }
32
+ import {useCallback, useEffect} from 'react'
33
+
34
+ import {query as queryImpl} from './query'
35
+ import {createStateComparer, defaultGetCacheKey, EMPTY_OBJECT, logDebug} from './utilsAndConstants'
36
+
37
+ export const useQuery = (cache, actions, selectors, options) => {
38
+ var _a, _b, _c, _d, _e
39
+ const {
40
+ query: queryKey,
41
+ skipFetch = false,
42
+ params,
43
+ secondsToLive,
44
+ selectorComparer,
45
+ fetchPolicy = (_a = cache.queries[queryKey].fetchPolicy) !== null && _a !== void 0
46
+ ? _a
47
+ : cache.globals.queries.fetchPolicy,
48
+ mergeResults,
49
+ onCompleted,
50
+ onSuccess,
51
+ onError,
52
+ } = options
53
+ const {selectQueryState} = selectors
54
+ const queryInfo = cache.queries[queryKey]
55
+ const logsEnabled = cache.options.logsEnabled
56
+ const getCacheKey = (_b = queryInfo.getCacheKey) !== null && _b !== void 0 ? _b : defaultGetCacheKey
57
+ const comparer =
58
+ selectorComparer === undefined
59
+ ? (_d =
60
+ (_c = queryInfo.selectorComparer) !== null && _c !== void 0
61
+ ? _c
62
+ : cache.globals.queries.selectorComparer) !== null && _d !== void 0
63
+ ? _d
64
+ : defaultStateComparer
65
+ : typeof selectorComparer === 'function'
66
+ ? selectorComparer
67
+ : createStateComparer(selectorComparer)
68
+ const store = cache.storeHooks.useStore()
69
+ const cacheKey = getCacheKey(params)
70
+ const performFetch = useCallback(
71
+ (options) =>
72
+ __awaiter(void 0, void 0, void 0, function* () {
73
+ const paramsPassed = options && 'params' in options
74
+ return yield queryImpl(
75
+ 'useQuery.fetch',
76
+ store,
77
+ cache,
78
+ actions,
79
+ selectors,
80
+ queryKey,
81
+ paramsPassed ? getCacheKey(options.params) : cacheKey,
82
+ paramsPassed ? options.params : params,
83
+ secondsToLive,
84
+ options === null || options === void 0 ? void 0 : options.onlyIfExpired,
85
+ false,
86
+ mergeResults,
87
+ onCompleted,
88
+ onSuccess,
89
+ onError,
90
+ )
91
+ }),
92
+ [store, queryKey, cacheKey],
93
+ )
94
+ const queryState =
95
+ (_e = cache.storeHooks.useSelector((state) => {
96
+ return selectQueryState(state, queryKey, cacheKey)
97
+ }, comparer)) !== null && _e !== void 0
98
+ ? _e
99
+ : EMPTY_OBJECT
100
+ useEffect(() => {
101
+ if (skipFetch) {
102
+ logsEnabled && logDebug('useQuery.useEffect skip fetch', {skipFetch, queryKey, cacheKey})
103
+ return
104
+ }
105
+ const expired = queryState.expiresAt != null && queryState.expiresAt <= Date.now()
106
+ if (!fetchPolicy(expired, params, queryState, store, selectors)) {
107
+ logsEnabled &&
108
+ logDebug('useQuery.useEffect skip fetch due to fetch policy', {
109
+ queryState,
110
+ expired,
111
+ queryKey,
112
+ cacheKey,
113
+ })
114
+ return
115
+ }
116
+ performFetch()
117
+ }, [cacheKey, skipFetch])
118
+ logsEnabled && logDebug('useQuery', {cacheKey, options, queryState})
119
+ return [queryState, performFetch]
120
+ }
121
+
122
+ const defaultStateComparer = createStateComparer(['result', 'loading', 'params', 'error'])
@@ -1,157 +1,207 @@
1
- export const PACKAGE_SHORT_NAME = 'rrc';
1
+ export const PACKAGE_SHORT_NAME = 'rrc'
2
+
2
3
  export const optionalUtils = {
3
- deepEqual: undefined,
4
- };
4
+ deepEqual: undefined,
5
+ }
6
+
5
7
  export const logDebug = (tag, data) => {
6
- console.debug(`@${PACKAGE_SHORT_NAME} [${tag}]`, data);
7
- };
8
+ console.debug(`@${PACKAGE_SHORT_NAME} [${tag}]`, data)
9
+ }
10
+
8
11
  export const logWarn = (tag, data) => {
9
- console.warn(`@${PACKAGE_SHORT_NAME} [${tag}]`, data);
10
- };
11
- try {
12
- optionalUtils.deepEqual = require('fast-deep-equal/es6');
12
+ console.warn(`@${PACKAGE_SHORT_NAME} [${tag}]`, data)
13
13
  }
14
- catch (_a) {
15
- logDebug('deepEqual', 'fast-deep-equal optional dependency was not installed');
14
+
15
+ try {
16
+ optionalUtils.deepEqual = require('fast-deep-equal/es6')
17
+ } catch (_a) {
18
+ logDebug('deepEqual', 'fast-deep-equal optional dependency was not installed')
16
19
  }
20
+
17
21
  export const IS_DEV = (() => {
18
- try {
19
- return __DEV__;
20
- }
21
- catch (_a) {
22
- return process.env.NODE_ENV === 'development';
23
- }
24
- })();
25
- export const EMPTY_OBJECT = Object.freeze({});
26
- export const EMPTY_ARRAY = Object.freeze([]);
27
- export const noop = () => { };
22
+ try {
23
+ return __DEV__
24
+ } catch (_a) {
25
+ return process.env.NODE_ENV === 'development'
26
+ }
27
+ })()
28
+
29
+ export const EMPTY_OBJECT = Object.freeze({})
30
+
31
+ export const EMPTY_ARRAY = Object.freeze([])
32
+
33
+ export const noop = () => {}
34
+
28
35
  export const defaultGetCacheKey = (params) => {
29
- switch (typeof params) {
30
- case 'string':
31
- case 'symbol':
32
- return params;
33
- case 'object':
34
- return JSON.stringify(params);
35
- default:
36
- return String(params);
37
- }
38
- };
36
+ switch (typeof params) {
37
+ case 'string':
38
+ case 'symbol':
39
+ return params
40
+ case 'object':
41
+ return JSON.stringify(params)
42
+ default:
43
+ return String(params)
44
+ }
45
+ }
46
+
39
47
  export const applyEntityChanges = (entities, changes, options) => {
40
- var _a, _b, _c;
41
- if (changes.merge && changes.entities) {
42
- logWarn('applyEntityChanges', 'merge and entities should not be both set');
48
+ var _a, _b, _c
49
+ if (changes.merge && changes.entities) {
50
+ logWarn('applyEntityChanges', 'merge and entities should not be both set')
51
+ }
52
+ const {merge = changes.entities, replace, remove} = changes
53
+ if (!merge && !replace && !remove) {
54
+ return undefined
55
+ }
56
+ const mutable = options.mutableCollections
57
+ const deepEqual = options.deepComparisonEnabled ? optionalUtils.deepEqual : undefined
58
+ let result
59
+ const objectWithAllTypenames = Object.assign(
60
+ Object.assign(Object.assign({}, changes.merge), changes.remove),
61
+ changes.replace,
62
+ )
63
+ for (const typename in objectWithAllTypenames) {
64
+ const entitiesToMerge = merge === null || merge === void 0 ? void 0 : merge[typename]
65
+ const entitiesToReplace = replace === null || replace === void 0 ? void 0 : replace[typename]
66
+ const entitiesToRemove = remove === null || remove === void 0 ? void 0 : remove[typename]
67
+ if (
68
+ !entitiesToMerge &&
69
+ !entitiesToReplace &&
70
+ !(entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.length)
71
+ ) {
72
+ continue
43
73
  }
44
- const { merge = changes.entities, replace, remove } = changes;
45
- if (!merge && !replace && !remove) {
46
- return undefined;
74
+ if (options.additionalValidation) {
75
+ const mergeIds = entitiesToMerge && Object.keys(entitiesToMerge)
76
+ const replaceIds = entitiesToReplace && Object.keys(entitiesToReplace)
77
+ const idsSet = new Set(mergeIds)
78
+ replaceIds === null || replaceIds === void 0 ? void 0 : replaceIds.forEach((id) => idsSet.add(id))
79
+ entitiesToRemove === null || entitiesToRemove === void 0
80
+ ? void 0
81
+ : entitiesToRemove.forEach((id) => idsSet.add(String(id)))
82
+ const totalKeysInResponse =
83
+ ((_a = mergeIds === null || mergeIds === void 0 ? void 0 : mergeIds.length) !== null && _a !== void 0
84
+ ? _a
85
+ : 0) +
86
+ ((_b = replaceIds === null || replaceIds === void 0 ? void 0 : replaceIds.length) !== null &&
87
+ _b !== void 0
88
+ ? _b
89
+ : 0) +
90
+ ((_c =
91
+ entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.length) !==
92
+ null && _c !== void 0
93
+ ? _c
94
+ : 0)
95
+ if (totalKeysInResponse !== 0 && idsSet.size !== totalKeysInResponse) {
96
+ logWarn('applyEntityChanges', 'merge, replace and remove changes have intersections for: ' + typename)
97
+ }
47
98
  }
48
- const mutable = options.mutableCollections;
49
- const deepEqual = options.deepComparisonEnabled ? optionalUtils.deepEqual : undefined;
50
- let result;
51
- const objectWithAllTypenames = Object.assign(Object.assign(Object.assign({}, changes.merge), changes.remove), changes.replace);
52
- for (const typename in objectWithAllTypenames) {
53
- const entitiesToMerge = merge === null || merge === void 0 ? void 0 : merge[typename];
54
- const entitiesToReplace = replace === null || replace === void 0 ? void 0 : replace[typename];
55
- const entitiesToRemove = remove === null || remove === void 0 ? void 0 : remove[typename];
56
- if (!entitiesToMerge && !entitiesToReplace && !(entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.length)) {
57
- continue;
99
+ const oldEntities = entities[typename]
100
+ let newEntities
101
+ entitiesToRemove === null || entitiesToRemove === void 0
102
+ ? void 0
103
+ : entitiesToRemove.forEach((id) => {
104
+ if (oldEntities === null || oldEntities === void 0 ? void 0 : oldEntities[id]) {
105
+ newEntities !== null && newEntities !== void 0
106
+ ? newEntities
107
+ : (newEntities = mutable ? oldEntities : Object.assign({}, oldEntities))
108
+ delete newEntities[id]
109
+ }
110
+ })
111
+ if (entitiesToReplace) {
112
+ for (const id in entitiesToReplace) {
113
+ const newEntity = entitiesToReplace[id]
114
+ if (
115
+ oldEntities === undefined ||
116
+ !(deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldEntities[id], newEntity))
117
+ ) {
118
+ newEntities !== null && newEntities !== void 0
119
+ ? newEntities
120
+ : (newEntities = mutable
121
+ ? oldEntities !== null && oldEntities !== void 0
122
+ ? oldEntities
123
+ : {}
124
+ : Object.assign({}, oldEntities))
125
+ newEntities[id] = newEntity
58
126
  }
59
- if (options.additionalValidation) {
60
- const mergeIds = entitiesToMerge && Object.keys(entitiesToMerge);
61
- const replaceIds = entitiesToReplace && Object.keys(entitiesToReplace);
62
- const idsSet = new Set(mergeIds);
63
- replaceIds === null || replaceIds === void 0 ? void 0 : replaceIds.forEach((id) => idsSet.add(id));
64
- entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.forEach((id) => idsSet.add(String(id)));
65
- const totalKeysInResponse = ((_a = mergeIds === null || mergeIds === void 0 ? void 0 : mergeIds.length) !== null && _a !== void 0 ? _a : 0) + ((_b = replaceIds === null || replaceIds === void 0 ? void 0 : replaceIds.length) !== null && _b !== void 0 ? _b : 0) + ((_c = entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.length) !== null && _c !== void 0 ? _c : 0);
66
- if (totalKeysInResponse !== 0 && idsSet.size !== totalKeysInResponse) {
67
- logWarn('applyEntityChanges', 'merge, replace and remove changes have intersections for: ' + typename);
68
- }
69
- }
70
- const oldEntities = entities[typename];
71
- let newEntities;
72
- entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.forEach((id) => {
73
- if (oldEntities === null || oldEntities === void 0 ? void 0 : oldEntities[id]) {
74
- newEntities !== null && newEntities !== void 0 ? newEntities : (newEntities = mutable ? oldEntities : Object.assign({}, oldEntities));
75
- delete newEntities[id];
76
- }
77
- });
78
- if (entitiesToReplace) {
79
- for (const id in entitiesToReplace) {
80
- const newEntity = entitiesToReplace[id];
81
- if (oldEntities === undefined || !(deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldEntities[id], newEntity))) {
82
- newEntities !== null && newEntities !== void 0 ? newEntities : (newEntities = mutable ? (oldEntities !== null && oldEntities !== void 0 ? oldEntities : {}) : Object.assign({}, oldEntities));
83
- newEntities[id] = newEntity;
84
- }
85
- }
86
- }
87
- if (entitiesToMerge) {
88
- for (const id in entitiesToMerge) {
89
- const oldEntity = oldEntities === null || oldEntities === void 0 ? void 0 : oldEntities[id];
90
- const newEntity = Object.assign(Object.assign({}, oldEntity), entitiesToMerge[id]);
91
- if (!(deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldEntity, newEntity))) {
92
- newEntities !== null && newEntities !== void 0 ? newEntities : (newEntities = mutable ? (oldEntities !== null && oldEntities !== void 0 ? oldEntities : {}) : Object.assign({}, oldEntities));
93
- newEntities[id] = newEntity;
94
- }
95
- }
96
- }
97
- if (!newEntities) {
98
- continue;
99
- }
100
- if (mutable) {
101
- incrementChangeKey(newEntities);
102
- if (result === undefined) {
103
- incrementChangeKey(entities);
104
- result = entities;
105
- }
106
- }
107
- else {
108
- result !== null && result !== void 0 ? result : (result = Object.assign({}, entities));
127
+ }
128
+ }
129
+ if (entitiesToMerge) {
130
+ for (const id in entitiesToMerge) {
131
+ const oldEntity = oldEntities === null || oldEntities === void 0 ? void 0 : oldEntities[id]
132
+ const newEntity = Object.assign(Object.assign({}, oldEntity), entitiesToMerge[id])
133
+ if (!(deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldEntity, newEntity))) {
134
+ newEntities !== null && newEntities !== void 0
135
+ ? newEntities
136
+ : (newEntities = mutable
137
+ ? oldEntities !== null && oldEntities !== void 0
138
+ ? oldEntities
139
+ : {}
140
+ : Object.assign({}, oldEntities))
141
+ newEntities[id] = newEntity
109
142
  }
110
- result[typename] = newEntities;
143
+ }
111
144
  }
112
- options.logsEnabled &&
113
- logDebug('applyEntityChanges', {
114
- entities,
115
- changes,
116
- options,
117
- result,
118
- });
119
- return result;
120
- };
121
- export const isEmptyObject = (obj) => {
122
- for (const _ in obj) {
123
- return false;
145
+ if (!newEntities) {
146
+ continue
124
147
  }
125
- return true;
126
- };
148
+ if (mutable) {
149
+ incrementChangeKey(newEntities)
150
+ if (result === undefined) {
151
+ incrementChangeKey(entities)
152
+ result = entities
153
+ }
154
+ } else {
155
+ result !== null && result !== void 0 ? result : (result = Object.assign({}, entities))
156
+ }
157
+ result[typename] = newEntities
158
+ }
159
+ options.logsEnabled &&
160
+ logDebug('applyEntityChanges', {
161
+ entities,
162
+ changes,
163
+ options,
164
+ result,
165
+ })
166
+ return result
167
+ }
168
+
169
+ export const isEmptyObject = (obj) => {
170
+ for (const _ in obj) {
171
+ return false
172
+ }
173
+ return true
174
+ }
175
+
127
176
  export const createStateComparer = (fields) => {
128
- return (x, y) => {
129
- if (x === y) {
130
- return true;
131
- }
132
- if (x === undefined || y === undefined) {
133
- return false;
134
- }
135
- for (let i = 0; i < fields.length; i += 1) {
136
- const key = fields[i];
137
- if (x[key] !== y[key]) {
138
- return false;
139
- }
140
- }
141
- return true;
142
- };
143
- };
144
- export const FetchPolicy = {
145
- NoCacheOrExpired: (expired, _params, state) => {
146
- return expired || state.result === undefined;
147
- },
148
- Always: () => true,
149
- };
150
- export const incrementChangeKey = (mutable) => {
151
- if (mutable._changeKey === undefined) {
152
- mutable._changeKey = 0;
177
+ return (x, y) => {
178
+ if (x === y) {
179
+ return true
180
+ }
181
+ if (x === undefined || y === undefined) {
182
+ return false
153
183
  }
154
- else {
155
- mutable._changeKey += 1;
184
+ for (let i = 0; i < fields.length; i += 1) {
185
+ const key = fields[i]
186
+ if (x[key] !== y[key]) {
187
+ return false
188
+ }
156
189
  }
157
- };
190
+ return true
191
+ }
192
+ }
193
+
194
+ export const FetchPolicy = {
195
+ NoCacheOrExpired: (expired, _params, state) => {
196
+ return expired || state.result === undefined
197
+ },
198
+ Always: () => true,
199
+ }
200
+
201
+ export const incrementChangeKey = (mutable) => {
202
+ if (mutable._changeKey === undefined) {
203
+ mutable._changeKey = 0
204
+ } else {
205
+ mutable._changeKey += 1
206
+ }
207
+ }