react-redux-cache 0.21.0 → 0.22.1

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,79 +1,40 @@
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
- }
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); }); }
11
3
  return new (P || (P = Promise))(function (resolve, reject) {
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
-
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';
37
13
  export const useMutation = (cache, actions, selectors, options, abortControllers) => {
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
- }
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
+ };
@@ -1,122 +1,55 @@
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
- }
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); }); }
11
3
  return new (P || (P = Promise))(function (resolve, reject) {
12
- function fulfilled(value) {
13
- try {
14
- step(generator.next(value))
15
- } catch (e) {
16
- reject(e)
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;
17
38
  }
18
- }
19
- function rejected(value) {
20
- try {
21
- step(generator['throw'](value))
22
- } catch (e) {
23
- reject(e)
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;
24
49
  }
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'])
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']);
@@ -1,179 +1,157 @@
1
- export const PACKAGE_SHORT_NAME = 'rrc'
2
-
1
+ export const PACKAGE_SHORT_NAME = 'rrc';
3
2
  export const optionalUtils = {
4
- deepEqual: undefined,
5
- }
6
-
3
+ deepEqual: undefined,
4
+ };
7
5
  export const logDebug = (tag, data) => {
8
- console.debug(`@${PACKAGE_SHORT_NAME} [${tag}]`, data)
9
- }
10
-
6
+ console.debug(`@${PACKAGE_SHORT_NAME} [${tag}]`, data);
7
+ };
11
8
  export const logWarn = (tag, data) => {
12
- console.warn(`@${PACKAGE_SHORT_NAME} [${tag}]`, data)
13
- }
14
-
9
+ console.warn(`@${PACKAGE_SHORT_NAME} [${tag}]`, data);
10
+ };
15
11
  try {
16
- optionalUtils.deepEqual = require('fast-deep-equal/es6')
17
- } catch (_a) {
18
- logDebug('deepEqual', 'fast-deep-equal optional dependency was not installed')
12
+ optionalUtils.deepEqual = require('fast-deep-equal/es6');
13
+ }
14
+ catch (_a) {
15
+ logDebug('deepEqual', 'fast-deep-equal optional dependency was not installed');
19
16
  }
20
-
21
17
  export const IS_DEV = (() => {
22
- try {
23
- return __DEV__
24
- } catch (e) {
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
-
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 = () => { };
35
28
  export const defaultGetCacheKey = (params) => {
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
-
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
+ };
47
39
  export const applyEntityChanges = (entities, changes, options) => {
48
- var _a, _b, _c, _d
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 deepEqual = options.deepComparisonEnabled ? optionalUtils.deepEqual : undefined
57
- let result
58
- const objectWithAllTypenames = Object.assign(
59
- Object.assign(Object.assign({}, changes.merge), changes.remove),
60
- changes.replace
61
- )
62
- for (const typename in objectWithAllTypenames) {
63
- const entitiesToMerge = merge === null || merge === void 0 ? void 0 : merge[typename]
64
- const entitiesToReplace = replace === null || replace === void 0 ? void 0 : replace[typename]
65
- const entitiesToRemove = remove === null || remove === void 0 ? void 0 : remove[typename]
66
- if (
67
- !entitiesToMerge &&
68
- !entitiesToReplace &&
69
- !(entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.length)
70
- ) {
71
- continue
40
+ var _a, _b, _c;
41
+ if (changes.merge && changes.entities) {
42
+ logWarn('applyEntityChanges', 'merge and entities should not be both set');
72
43
  }
73
- if (options.additionalValidation) {
74
- const mergeIds = entitiesToMerge && Object.keys(entitiesToMerge)
75
- const replaceIds = entitiesToReplace && Object.keys(entitiesToReplace)
76
- const idsSet = new Set(mergeIds)
77
- replaceIds === null || replaceIds === void 0 ? void 0 : replaceIds.forEach((id) => idsSet.add(id))
78
- entitiesToRemove === null || entitiesToRemove === void 0
79
- ? void 0
80
- : entitiesToRemove.forEach((id) => idsSet.add(String(id)))
81
- const totalKeysInResponse =
82
- ((_a = mergeIds === null || mergeIds === void 0 ? void 0 : mergeIds.length) !== null && _a !== void 0
83
- ? _a
84
- : 0) +
85
- ((_b = replaceIds === null || replaceIds === void 0 ? void 0 : replaceIds.length) !== null &&
86
- _b !== void 0
87
- ? _b
88
- : 0) +
89
- ((_c =
90
- entitiesToRemove === null || entitiesToRemove === void 0 ? void 0 : entitiesToRemove.length) !==
91
- null && _c !== void 0
92
- ? _c
93
- : 0)
94
- if (totalKeysInResponse !== 0 && idsSet.size !== totalKeysInResponse) {
95
- logWarn('applyEntityChanges', 'merge, replace and remove changes have intersections for: ' + typename)
96
- }
44
+ const { merge = changes.entities, replace, remove } = changes;
45
+ if (!merge && !replace && !remove) {
46
+ return undefined;
97
47
  }
98
- const oldEntities = (_d = entities[typename]) !== null && _d !== void 0 ? _d : EMPTY_OBJECT
99
- let newEntities
100
- entitiesToRemove === null || entitiesToRemove === void 0
101
- ? void 0
102
- : entitiesToRemove.forEach((id) => {
103
- if (oldEntities[id]) {
104
- newEntities !== null && newEntities !== void 0
105
- ? newEntities
106
- : (newEntities = Object.assign({}, oldEntities))
107
- delete newEntities[id]
108
- }
109
- })
110
- if (entitiesToReplace) {
111
- for (const id in entitiesToReplace) {
112
- const newEntity = entitiesToReplace[id]
113
- if (!(deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldEntities[id], newEntity))) {
114
- newEntities !== null && newEntities !== void 0
115
- ? newEntities
116
- : (newEntities = Object.assign({}, oldEntities))
117
- newEntities[id] = newEntity
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;
118
58
  }
119
- }
120
- }
121
- if (entitiesToMerge) {
122
- for (const id in entitiesToMerge) {
123
- const oldEntity = oldEntities[id]
124
- const newEntity = Object.assign(Object.assign({}, oldEntity), entitiesToMerge[id])
125
- if (!(deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldEntity, newEntity))) {
126
- newEntities !== null && newEntities !== void 0
127
- ? newEntities
128
- : (newEntities = Object.assign({}, oldEntities))
129
- newEntities[id] = newEntity
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;
130
99
  }
131
- }
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));
109
+ }
110
+ result[typename] = newEntities;
132
111
  }
133
- if (!newEntities) {
134
- continue
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;
135
124
  }
136
- result !== null && result !== void 0 ? result : (result = Object.assign({}, entities))
137
- result[typename] = newEntities
138
- }
139
- options.logsEnabled &&
140
- logDebug('applyEntityChanges', {
141
- entities,
142
- changes,
143
- options,
144
- result,
145
- })
146
- return result
147
- }
148
-
149
- export const isEmptyObject = (o) => {
150
- for (const _ in o) {
151
- return false
152
- }
153
- return true
154
- }
155
-
125
+ return true;
126
+ };
156
127
  export const createStateComparer = (fields) => {
157
- return (x, y) => {
158
- if (x === y) {
159
- return true
160
- }
161
- if (x === undefined || y === undefined) {
162
- return false
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;
163
153
  }
164
- for (let i = 0; i < fields.length; i += 1) {
165
- const key = fields[i]
166
- if (x[key] !== y[key]) {
167
- return false
168
- }
154
+ else {
155
+ mutable._changeKey += 1;
169
156
  }
170
- return true
171
- }
172
- }
173
-
174
- export const FetchPolicy = {
175
- NoCacheOrExpired: (expired, _params, state) => {
176
- return expired || state.result === undefined
177
- },
178
- Always: () => true,
179
- }
157
+ };