Skip to content

Commit 2d8de81

Browse files
committed
revert: removed debugs for a separate PR
This reverts commit 4377ca2.
1 parent 11fc158 commit 2d8de81

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/reducers/cacheReducer.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import produce, { createDraft, finishDraft } from 'immer';
2+
import debug from 'debug';
23
import {
34
set,
45
unset,
@@ -23,6 +24,8 @@ import { actionTypes } from '../constants';
2324
import { getBaseQueryName } from '../utils/query';
2425
import mark from '../utils/profiling';
2526

27+
const info = debug('rrf:cache');
28+
2629
/**
2730
* @typedef {object & Object.<string, RRFQuery>} CacheState
2831
* Cache state is a synchronous, in-memory fragment of Firestore. The primary
@@ -360,6 +363,16 @@ function reprocessQuerires(draft, path) {
360363
set(draft, [key, 'ordered'], ordered);
361364
});
362365

366+
if (info.enabled) {
367+
/* istanbul ignore next */
368+
const overrides = JSON.parse(JSON.stringify(draft.databaseOverrides || {}));
369+
/* istanbul ignore next */
370+
info(
371+
`reprocess ${path} (${queries.length} queries) with overrides`,
372+
overrides,
373+
);
374+
}
375+
363376
done();
364377
}
365378

@@ -645,6 +658,8 @@ const failure = (state, { action, key, path }) =>
645658
(results, { writes }) => [
646659
...results,
647660
...writes.map(({ collection, path: _path, doc, id }) => {
661+
info('remove override', `${collection}/${doc}`);
662+
648663
// don't send data to ensure document override is deleted
649664
cleanOverride(draft, { path: _path || collection, id: id || doc });
650665

@@ -740,6 +755,7 @@ const mutation = (state, { action, key, path }) =>
740755
translateMutationToOverrides(action, draft.database) || [];
741756

742757
optimisiticUpdates.forEach(({ collection, doc, data }) => {
758+
info('overriding', `${collection}/${doc}`, data);
743759
setWith(draft, ['databaseOverrides', collection, doc], data, Object);
744760
});
745761

src/reducers/dataReducer.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { get } from 'lodash';
22
import { setWith } from 'lodash/fp';
33
import { actionTypes } from '../constants';
44
import { pathFromMeta, preserveValuesFromState } from '../utils/reducers';
5+
import debug from 'debug';
56

67
const {
78
CLEAR_DATA,
@@ -14,6 +15,7 @@ const {
1415
DOCUMENT_REMOVED,
1516
} = actionTypes;
1617

18+
const info = debug('rrf:data');
1719
/**
1820
* Reducer for data state.
1921
* @param {object} [state={}] - Current data redux state
@@ -60,6 +62,7 @@ export default function dataReducer(state = {}, action) {
6062
);
6163
}
6264
const alias = meta.storeAs ? [meta.storeAs] : pathFromMeta(meta);
65+
info('LISTENER_RESPONSE', alias, data);
6366
// Set data to state (with merge) immutabily (lodash/fp's setWith creates copy)
6467
return setWith(Object, alias, data, state);
6568

@@ -86,13 +89,16 @@ export default function dataReducer(state = {}, action) {
8689
case CLEAR_DATA:
8790
// support keeping data when logging out - #125 of react-redux-firebase
8891
if (action.preserve && action.preserve.data) {
92+
info('log out and preserve', action.preserve.data);
8993
return preserveValuesFromState(state, action.preserve.data, {});
9094
}
9195
return {};
9296
case LISTENER_ERROR:
97+
info('listener error');
9398
// Set data to state immutabily (lodash/fp's setWith creates copy)
9499
const nextState = setWith(Object, pathFromMeta(action.meta), null, state);
95100
if (action.preserve && action.preserve.data) {
101+
info('error and preserve', action.preserve.data);
96102
return preserveValuesFromState(state, action.preserve.data, nextState);
97103
}
98104
const existingState = get(state, pathFromMeta(action.meta));

src/reducers/orderedReducer.js

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
preserveValuesFromState,
88
pathToArr,
99
} from '../utils/reducers';
10+
import debug from 'debug';
1011

1112
const {
1213
DOCUMENT_ADDED,
@@ -18,6 +19,8 @@ const {
1819
DOCUMENT_MODIFIED,
1920
} = actionTypes;
2021

22+
const info = debug('rrf:ordered');
23+
2124
/**
2225
* Create a new copy of an array with the provided item in a new array index
2326
*
@@ -57,6 +60,7 @@ function newArrayWithItemMoved(collectionState, meta, ordered, newValue) {
5760
function modifyDoc(collectionState, action) {
5861
// Support moving a doc within an array
5962
if (action.payload.ordered) {
63+
info('DOCUMENT_MODIFIED new order:', action.payload.ordered);
6064
const { newIndex, oldIndex } = action.payload.ordered;
6165
// newIndex/oldIndex values exist, item isn't being removed or added, and the index has changed
6266
if (

src/utils/mutate.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { chunk, cloneDeep, flatten, mapValues } from 'lodash';
2+
import debug from 'debug';
23
import { firestoreRef } from './query';
34
import mark from './profiling';
45

6+
const info = debug('rrf:mutate');
7+
58
/**
69
* @param {object} firestore
710
* @param {string} collection
@@ -126,13 +129,15 @@ function write(firebase, operation = {}, writer = null) {
126129

127130
if (writer) {
128131
const writeType = writer.commit ? 'Batching' : 'Transaction.set';
132+
info(writeType, { id: ref.id, path: ref.parent.path, ...changes });
129133
if (requiresUpdate) {
130134
writer.update(ref, changes);
131135
} else {
132136
writer.set(ref, changes, { merge: true });
133137
}
134138
return { id: ref.id, path: ref.parent.path, ...changes };
135139
}
140+
info('Writing', { id: ref.id, path: ref.parent.path, ...changes });
136141
if (requiresUpdate) {
137142
return ref.update(changes);
138143
}
@@ -188,6 +193,7 @@ async function writeInTransaction(firebase, operations) {
188193
? null
189194
: { ...doc.data(), id: doc.ref.id, path: doc.ref.parent.path };
190195
const getter = (ref) => {
196+
info('Transaction.get ', { id: ref.id, path: ref.parent.path });
191197
return transaction.get(ref);
192198
};
193199

0 commit comments

Comments
 (0)