Skip to content

Commit 0e1cee1

Browse files
authored
v1.35.8 (#319)
2 parents 0a93a1f + 742159f commit 0e1cee1

File tree

6 files changed

+95
-32
lines changed

6 files changed

+95
-32
lines changed

dist/index.cjs.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ function pluginMutations (userState) {
404404
PATCH_DOC: function (state, patches) {
405405
var _this = this;
406406
// Get the state prop ref
407-
var ref = state._conf.statePropName
408-
? state[state._conf.statePropName]
409-
: state;
407+
var ref = state._conf.statePropName ? state[state._conf.statePropName] : state;
410408
if (state._conf.firestoreRefType.toLowerCase() === 'collection') {
411409
ref = ref[patches.id];
412410
}
@@ -439,17 +437,15 @@ function pluginMutations (userState) {
439437
}
440438
},
441439
DELETE_PROP: function (state, path) {
442-
var searchTarget = state._conf.statePropName
443-
? state[state._conf.statePropName]
444-
: state;
440+
var searchTarget = state._conf.statePropName ? state[state._conf.statePropName] : state;
445441
var propArr = path.split('.');
446442
var target = propArr.pop();
447443
if (!propArr.length) {
448444
return this._vm.$delete(searchTarget, target);
449445
}
450446
var ref = vuexEasyAccess.getDeepRef(searchTarget, propArr.join('.'));
451447
return this._vm.$delete(ref, target);
452-
}
448+
},
453449
};
454450
}
455451

@@ -1462,7 +1458,7 @@ function pluginActions (Firebase) {
14621458
});
14631459
};
14641460
var unsubscribe = dbRef.onSnapshot({ includeMetadataChanges: includeMetadataChanges }, function (querySnapshot) { return __awaiter(_this, void 0, void 0, function () {
1465-
var message, error_1;
1461+
var docChanges, message, error_1;
14661462
return __generator(this, function (_a) {
14671463
switch (_a.label) {
14681464
case 0:
@@ -1486,6 +1482,26 @@ function pluginActions (Firebase) {
14861482
}
14871483
gotFirstLocalResponse = true;
14881484
}
1485+
else if (gotFirstLocalResponse) {
1486+
// it's not the first call and it's a change from cache
1487+
// normally we only need to listen to the server changes, but there's an edge case here:
1488+
// case: "a permission is removed server side, and instead of this being notified
1489+
// by firestore from the _server side_, it only notifies this from the cache...
1490+
if (getters.collectionMode) {
1491+
docChanges = querySnapshot.docChanges();
1492+
docChanges.forEach(function (change) {
1493+
// only do stuff on "removed" !!
1494+
if (change.type === 'removed') {
1495+
var doc = getters.cleanUpRetrievedDoc(change.doc.data(), change.doc.id);
1496+
dispatch('applyHooksAndUpdateState', {
1497+
change: change.type,
1498+
id: change.doc.id,
1499+
doc: doc,
1500+
});
1501+
}
1502+
});
1503+
}
1504+
}
14891505
return [3 /*break*/, 13];
14901506
case 1:
14911507
if (!querySnapshot.metadata.hasPendingWrites) return [3 /*break*/, 2];

dist/index.esm.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,7 @@ function pluginMutations (userState) {
398398
PATCH_DOC: function (state, patches) {
399399
var _this = this;
400400
// Get the state prop ref
401-
var ref = state._conf.statePropName
402-
? state[state._conf.statePropName]
403-
: state;
401+
var ref = state._conf.statePropName ? state[state._conf.statePropName] : state;
404402
if (state._conf.firestoreRefType.toLowerCase() === 'collection') {
405403
ref = ref[patches.id];
406404
}
@@ -433,17 +431,15 @@ function pluginMutations (userState) {
433431
}
434432
},
435433
DELETE_PROP: function (state, path) {
436-
var searchTarget = state._conf.statePropName
437-
? state[state._conf.statePropName]
438-
: state;
434+
var searchTarget = state._conf.statePropName ? state[state._conf.statePropName] : state;
439435
var propArr = path.split('.');
440436
var target = propArr.pop();
441437
if (!propArr.length) {
442438
return this._vm.$delete(searchTarget, target);
443439
}
444440
var ref = getDeepRef(searchTarget, propArr.join('.'));
445441
return this._vm.$delete(ref, target);
446-
}
442+
},
447443
};
448444
}
449445

@@ -1456,7 +1452,7 @@ function pluginActions (Firebase) {
14561452
});
14571453
};
14581454
var unsubscribe = dbRef.onSnapshot({ includeMetadataChanges: includeMetadataChanges }, function (querySnapshot) { return __awaiter(_this, void 0, void 0, function () {
1459-
var message, error_1;
1455+
var docChanges, message, error_1;
14601456
return __generator(this, function (_a) {
14611457
switch (_a.label) {
14621458
case 0:
@@ -1480,6 +1476,26 @@ function pluginActions (Firebase) {
14801476
}
14811477
gotFirstLocalResponse = true;
14821478
}
1479+
else if (gotFirstLocalResponse) {
1480+
// it's not the first call and it's a change from cache
1481+
// normally we only need to listen to the server changes, but there's an edge case here:
1482+
// case: "a permission is removed server side, and instead of this being notified
1483+
// by firestore from the _server side_, it only notifies this from the cache...
1484+
if (getters.collectionMode) {
1485+
docChanges = querySnapshot.docChanges();
1486+
docChanges.forEach(function (change) {
1487+
// only do stuff on "removed" !!
1488+
if (change.type === 'removed') {
1489+
var doc = getters.cleanUpRetrievedDoc(change.doc.data(), change.doc.id);
1490+
dispatch('applyHooksAndUpdateState', {
1491+
change: change.type,
1492+
id: change.doc.id,
1493+
doc: doc,
1494+
});
1495+
}
1496+
});
1497+
}
1498+
}
14831499
return [3 /*break*/, 13];
14841500
case 1:
14851501
if (!querySnapshot.metadata.hasPendingWrites) return [3 /*break*/, 2];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuex-easy-firestore",
3-
"version": "1.35.7",
3+
"version": "1.35.8",
44
"description": "Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.esm.js",

src/module/actions.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,25 @@ export default function (Firebase: any): AnyObject {
698698
streamingStart()
699699
}
700700
gotFirstLocalResponse = true
701+
} else if (gotFirstLocalResponse) {
702+
// it's not the first call and it's a change from cache
703+
// normally we only need to listen to the server changes, but there's an edge case here:
704+
// case: "a permission is removed server side, and instead of this being notified
705+
// by firestore from the _server side_, it only notifies this from the cache...
706+
if (getters.collectionMode) {
707+
const docChanges = querySnapshot.docChanges()
708+
docChanges.forEach(function (change) {
709+
// only do stuff on "removed" !!
710+
if (change.type === 'removed') {
711+
const doc = getters.cleanUpRetrievedDoc(change.doc.data(), change.doc.id)
712+
dispatch('applyHooksAndUpdateState', {
713+
change: change.type,
714+
id: change.doc.id,
715+
doc: doc,
716+
})
717+
}
718+
})
719+
}
701720
}
702721
}
703722
// if data comes from server... BUT REALLY NOT: the data comes from local change

src/module/mutations.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ export default function (userState: object): AnyObject {
7474
},
7575
PATCH_DOC (state, patches) {
7676
// Get the state prop ref
77-
let ref = state._conf.statePropName
78-
? state[state._conf.statePropName]
79-
: state
77+
let ref = state._conf.statePropName ? state[state._conf.statePropName] : state
8078
if (state._conf.firestoreRefType.toLowerCase() === 'collection') {
8179
ref = ref[patches.id]
8280
}
@@ -106,16 +104,14 @@ export default function (userState: object): AnyObject {
106104
}
107105
},
108106
DELETE_PROP (state, path) {
109-
const searchTarget = state._conf.statePropName
110-
? state[state._conf.statePropName]
111-
: state
107+
const searchTarget = state._conf.statePropName ? state[state._conf.statePropName] : state
112108
const propArr = path.split('.')
113109
const target = propArr.pop()
114110
if (!propArr.length) {
115111
return this._vm.$delete(searchTarget, target)
116112
}
117113
const ref = getDeepRef(searchTarget, propArr.join('.'))
118114
return this._vm.$delete(ref, target)
119-
}
115+
},
120116
}
121117
}

test/helpers/index.cjs.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,7 @@ function pluginMutations (userState) {
923923
PATCH_DOC: function (state, patches) {
924924
var _this = this;
925925
// Get the state prop ref
926-
var ref = state._conf.statePropName
927-
? state[state._conf.statePropName]
928-
: state;
926+
var ref = state._conf.statePropName ? state[state._conf.statePropName] : state;
929927
if (state._conf.firestoreRefType.toLowerCase() === 'collection') {
930928
ref = ref[patches.id];
931929
}
@@ -958,17 +956,15 @@ function pluginMutations (userState) {
958956
}
959957
},
960958
DELETE_PROP: function (state, path) {
961-
var searchTarget = state._conf.statePropName
962-
? state[state._conf.statePropName]
963-
: state;
959+
var searchTarget = state._conf.statePropName ? state[state._conf.statePropName] : state;
964960
var propArr = path.split('.');
965961
var target = propArr.pop();
966962
if (!propArr.length) {
967963
return this._vm.$delete(searchTarget, target);
968964
}
969965
var ref = createEasyAccess.getDeepRef(searchTarget, propArr.join('.'));
970966
return this._vm.$delete(ref, target);
971-
}
967+
},
972968
};
973969
}
974970

@@ -1981,7 +1977,7 @@ function pluginActions (Firebase) {
19811977
});
19821978
};
19831979
var unsubscribe = dbRef.onSnapshot({ includeMetadataChanges: includeMetadataChanges }, function (querySnapshot) { return __awaiter(_this, void 0, void 0, function () {
1984-
var message, error_1;
1980+
var docChanges, message, error_1;
19851981
return __generator(this, function (_a) {
19861982
switch (_a.label) {
19871983
case 0:
@@ -2005,6 +2001,26 @@ function pluginActions (Firebase) {
20052001
}
20062002
gotFirstLocalResponse = true;
20072003
}
2004+
else if (gotFirstLocalResponse) {
2005+
// it's not the first call and it's a change from cache
2006+
// normally we only need to listen to the server changes, but there's an edge case here:
2007+
// case: "a permission is removed server side, and instead of this being notified
2008+
// by firestore from the _server side_, it only notifies this from the cache...
2009+
if (getters.collectionMode) {
2010+
docChanges = querySnapshot.docChanges();
2011+
docChanges.forEach(function (change) {
2012+
// only do stuff on "removed" !!
2013+
if (change.type === 'removed') {
2014+
var doc = getters.cleanUpRetrievedDoc(change.doc.data(), change.doc.id);
2015+
dispatch('applyHooksAndUpdateState', {
2016+
change: change.type,
2017+
id: change.doc.id,
2018+
doc: doc,
2019+
});
2020+
}
2021+
});
2022+
}
2023+
}
20082024
return [3 /*break*/, 13];
20092025
case 1:
20102026
if (!querySnapshot.metadata.hasPendingWrites) return [3 /*break*/, 2];

0 commit comments

Comments
 (0)