Skip to content

Commit

Permalink
support userId in sync.where filter 🐯
Browse files Browse the repository at this point in the history
support userId in sync.where filter 🐯
  • Loading branch information
mesqueeb authored Aug 26, 2018
2 parents 98759ee + a56d04e commit 3499830
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
11 changes: 7 additions & 4 deletions dist/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var initialState = {
propDeletions: [],
debounceTimer: null
},
fetched: [],
fetched: {},
stopPatchingTimeout: null
}
};
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -725,16 +725,19 @@ 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
if (getters.collectionMode) {
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) {
Expand Down
11 changes: 7 additions & 4 deletions dist/index.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var initialState = {
propDeletions: [],
debounceTimer: null
},
fetched: [],
fetched: {},
stopPatchingTimeout: null
}
};
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -719,16 +719,19 @@ 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
if (getters.collectionMode) {
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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 6 additions & 3 deletions src/module/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/module/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
propDeletions: [],
debounceTimer: null,
},
fetched: [],
fetched: {},
stopPatchingTimeout: null
}
}
11 changes: 7 additions & 4 deletions test/helpers/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ var initialState$2 = {
propDeletions: [],
debounceTimer: null
},
fetched: [],
fetched: {},
stopPatchingTimeout: null
}
};
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -808,16 +808,19 @@ 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
if (getters.collectionMode) {
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) {
Expand Down

0 comments on commit 3499830

Please sign in to comment.