diff --git a/dist/index.cjs.js b/dist/index.cjs.js index 612ec54a..fe5db1fc 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -116,7 +116,7 @@ var initialState = { propDeletions: [], debounceTimer: null }, - fetched: [], + fetched: {}, stopPatchingTimeout: null } }; @@ -660,7 +660,7 @@ var actions = { // We're already done fetching everything: if (fRequest.done) { console.log('done fetching'); - return resolve('fetchedAll'); + return resolve({ done: true }); } // attach fetch filters var fRef = state._sync.fetched[identifier].ref; @@ -671,7 +671,7 @@ var actions = { fRef = fRef.limit(state._conf.fetch.docLimit); // Stop if all records already fetched if (fRequest.retrievedFetchRefs.includes(fRef)) { - console.log('Already retrieved this part.'); + console.error('Already retrieved this part.'); return resolve(); } // make fetch request @@ -725,9 +725,11 @@ var actions = { dispatch = _ref15.dispatch; var store = this; + var userId = null; if (Firebase$1.auth().currentUser) { state._sync.signedIn = true; - state._sync.userId = Firebase$1.auth().currentUser.uid; + userId = Firebase$1.auth().currentUser.uid; + state._sync.userId = userId; } var dbRef = getters.dbRef; // apply where filters and orderBy @@ -735,6 +737,7 @@ var actions = { state._conf.sync.where.forEach(function (paramsArr) { var _dbRef; + if (paramsArr[2] === '{userId}') paramsArr[2] = userId; dbRef = (_dbRef = dbRef).where.apply(_dbRef, toConsumableArray(paramsArr)); }); if (state._conf.sync.orderBy.length) { diff --git a/dist/index.es.js b/dist/index.es.js index 4431517e..b7be3612 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -110,7 +110,7 @@ var initialState = { propDeletions: [], debounceTimer: null }, - fetched: [], + fetched: {}, stopPatchingTimeout: null } }; @@ -654,7 +654,7 @@ var actions = { // We're already done fetching everything: if (fRequest.done) { console.log('done fetching'); - return resolve('fetchedAll'); + return resolve({ done: true }); } // attach fetch filters var fRef = state._sync.fetched[identifier].ref; @@ -665,7 +665,7 @@ var actions = { fRef = fRef.limit(state._conf.fetch.docLimit); // Stop if all records already fetched if (fRequest.retrievedFetchRefs.includes(fRef)) { - console.log('Already retrieved this part.'); + console.error('Already retrieved this part.'); return resolve(); } // make fetch request @@ -719,9 +719,11 @@ var actions = { dispatch = _ref15.dispatch; var store = this; + var userId = null; if (Firebase$1.auth().currentUser) { state._sync.signedIn = true; - state._sync.userId = Firebase$1.auth().currentUser.uid; + userId = Firebase$1.auth().currentUser.uid; + state._sync.userId = userId; } var dbRef = getters.dbRef; // apply where filters and orderBy @@ -729,6 +731,7 @@ var actions = { state._conf.sync.where.forEach(function (paramsArr) { var _dbRef; + if (paramsArr[2] === '{userId}') paramsArr[2] = userId; dbRef = (_dbRef = dbRef).where.apply(_dbRef, toConsumableArray(paramsArr)); }); if (state._conf.sync.orderBy.length) { diff --git a/package.json b/package.json index 1b491fc8..144260e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuex-easy-firestore", - "version": "1.6.0", + "version": "1.7.0", "description": "Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!", "main": "dist/index.cjs.js", "module": "dist/index.es.js", diff --git a/src/module/actions.js b/src/module/actions.js index 753f3c33..96a00be4 100644 --- a/src/module/actions.js +++ b/src/module/actions.js @@ -165,7 +165,7 @@ const actions = { // We're already done fetching everything: if (fRequest.done) { console.log('done fetching') - return resolve('fetchedAll') + return resolve({done: true}) } // attach fetch filters let fRef = state._sync.fetched[identifier].ref @@ -176,7 +176,7 @@ const actions = { fRef = fRef.limit(state._conf.fetch.docLimit) // Stop if all records already fetched if (fRequest.retrievedFetchRefs.includes(fRef)) { - console.log('Already retrieved this part.') + console.error('Already retrieved this part.') return resolve() } // make fetch request @@ -219,14 +219,17 @@ const actions = { }, openDBChannel ({getters, state, commit, dispatch}) { const store = this + let userId = null if (Firebase.auth().currentUser) { state._sync.signedIn = true - state._sync.userId = Firebase.auth().currentUser.uid + userId = Firebase.auth().currentUser.uid + state._sync.userId = userId } let dbRef = getters.dbRef // apply where filters and orderBy if (getters.collectionMode) { state._conf.sync.where.forEach(paramsArr => { + if (paramsArr[2] === '{userId}') paramsArr[2] = userId dbRef = dbRef.where(...paramsArr) }) if (state._conf.sync.orderBy.length) { diff --git a/src/module/state.js b/src/module/state.js index dd0d456f..a07c3ac5 100644 --- a/src/module/state.js +++ b/src/module/state.js @@ -11,7 +11,7 @@ export default { propDeletions: [], debounceTimer: null, }, - fetched: [], + fetched: {}, stopPatchingTimeout: null } } diff --git a/test/helpers/index.cjs.js b/test/helpers/index.cjs.js index 64e3b1e9..b542858b 100644 --- a/test/helpers/index.cjs.js +++ b/test/helpers/index.cjs.js @@ -199,7 +199,7 @@ var initialState$2 = { propDeletions: [], debounceTimer: null }, - fetched: [], + fetched: {}, stopPatchingTimeout: null } }; @@ -743,7 +743,7 @@ var actions = { // We're already done fetching everything: if (fRequest.done) { console.log('done fetching'); - return resolve('fetchedAll'); + return resolve({ done: true }); } // attach fetch filters var fRef = state._sync.fetched[identifier].ref; @@ -754,7 +754,7 @@ var actions = { fRef = fRef.limit(state._conf.fetch.docLimit); // Stop if all records already fetched if (fRequest.retrievedFetchRefs.includes(fRef)) { - console.log('Already retrieved this part.'); + console.error('Already retrieved this part.'); return resolve(); } // make fetch request @@ -808,9 +808,11 @@ var actions = { dispatch = _ref15.dispatch; var store = this; + var userId = null; if (Firebase$1.auth().currentUser) { state._sync.signedIn = true; - state._sync.userId = Firebase$1.auth().currentUser.uid; + userId = Firebase$1.auth().currentUser.uid; + state._sync.userId = userId; } var dbRef = getters.dbRef; // apply where filters and orderBy @@ -818,6 +820,7 @@ var actions = { state._conf.sync.where.forEach(function (paramsArr) { var _dbRef; + if (paramsArr[2] === '{userId}') paramsArr[2] = userId; dbRef = (_dbRef = dbRef).where.apply(_dbRef, toConsumableArray(paramsArr)); }); if (state._conf.sync.orderBy.length) {