Skip to content

Commit 61a4857

Browse files
committed
Fixing collection store init errors in stats (#586)
1 parent 4967191 commit 61a4857

File tree

1 file changed

+24
-2
lines changed
  • src/internal-packages/collection-stats/lib/store

1 file changed

+24
-2
lines changed

src/internal-packages/collection-stats/lib/store/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const CollectionStatsStore = Reflux.createStore({
2020
*/
2121
init: function() {
2222
this.listenTo(NamespaceStore, this.loadCollectionStats);
23-
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
2423
},
2524

2625
/**
@@ -30,7 +29,7 @@ const CollectionStatsStore = Reflux.createStore({
3029
*/
3130
loadCollectionStats: function(ns) {
3231
if (toNS(ns || '').collection) {
33-
if (this.CollectionStore.isReadonly()) {
32+
if (this._isCollectionReadonly()) {
3433
this.trigger();
3534
} else {
3635
app.dataService.collection(ns, { readPreference: READ }, (err, result) => {
@@ -42,6 +41,29 @@ const CollectionStatsStore = Reflux.createStore({
4241
}
4342
},
4443

44+
/**
45+
* Determine if the collection is readonly.
46+
*
47+
* @note Durran: The wacky logic here is because the ampersand app is not
48+
* loaded in the unit test environment and the validation tests fail since
49+
* not app registry is found. Once we get rid of the ampersand app we can
50+
* put the store set back into the init once we've sorted out the proper
51+
* test strategy.
52+
*
53+
* @returns {Boolean} If the collection is readonly.
54+
*/
55+
_isCollectionReadonly() {
56+
if (this.CollectionStore) {
57+
return this.CollectionStore.isReadonly();
58+
}
59+
const registry = app.appRegistry;
60+
if (registry) {
61+
this.CollectionStore = registry.getStore('App.CollectionStore');
62+
return this.CollectionStore.isReadonly();
63+
}
64+
return false;
65+
},
66+
4567
_parseCollectionDetails(result) {
4668
return {
4769
documentCount: this._format(result.document_count),

0 commit comments

Comments
 (0)