diff --git a/package.json b/package.json index 656973b8..fb278cb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redux-firestore", - "version": "1.1.2", + "version": "1.1.5", "description": "Redux bindings for Firestore.", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/reducers/cacheReducer.js b/src/reducers/cacheReducer.js index c6b8e5b0..877c3c69 100644 --- a/src/reducers/cacheReducer.js +++ b/src/reducers/cacheReducer.js @@ -105,6 +105,8 @@ const formatTimestamp = ({ seconds } = {}) => new Intl.DateTimeFormat('en-US', { dateStyle: 'short' }).format( new Date(seconds * 1000), ); +const isDocRead = ({ doc, id } = {}) => + typeof id === 'string' || typeof doc === 'string'; const PROCESSES = { '<': (a, b) => a < b, @@ -563,6 +565,23 @@ function translateMutationToOverrides({ payload }, db = {}, dbo = {}) { const collection = db[path] || {}; const overrides = dbo[path] || {}; + + if (!isDocRead(reads[key])) { + const pathIds = processOptimistic(reads[key], { + database: db, + databaseOverrides: dbo, + }); + return { + ...result, + [key]: pathIds.map(([path, id]) => ({ + id, + path, + ...collection[id], + ...(overrides[id] || {}), + })), + }; + } + return { ...result, [key]: { id, path, ...collection[id], ...(overrides[id] || {}) }, diff --git a/src/utils/mutate.js b/src/utils/mutate.js index 39d83089..58492502 100644 --- a/src/utils/mutate.js +++ b/src/utils/mutate.js @@ -187,7 +187,9 @@ async function writeInTransaction(firebase, operations) { const coll = firestoreRef(firebase, read); const snapshot = await coll.get(); if (hasNothing(snapshot) || snapshot.docs.length === 0) return []; - const unserializedDocs = await Promise.all(snapshot.docs.map(getter)); + const unserializedDocs = await Promise.all( + snapshot.docs.map(({ ref }) => getter(ref)), + ); return unserializedDocs.map(serialize); });