|
@@ -8,6 +8,12 @@ import getGuidesContent from 'sentry/components/assistant/getGuidesContent';
|
|
|
import {Guide, GuidesContent, GuidesServerData} from 'sentry/components/assistant/types';
|
|
|
import ConfigStore from 'sentry/stores/configStore';
|
|
|
import {trackAnalyticsEvent} from 'sentry/utils/analytics';
|
|
|
+import {
|
|
|
+ cleanupActiveRefluxSubscriptions,
|
|
|
+ makeSafeRefluxStore,
|
|
|
+ SafeRefluxStore,
|
|
|
+ SafeStoreDefinition,
|
|
|
+} from 'sentry/utils/makeSafeRefluxStore';
|
|
|
|
|
|
function guidePrioritySort(a: Guide, b: Guide) {
|
|
|
const a_priority = a.priority ?? Number.MAX_SAFE_INTEGER;
|
|
@@ -66,8 +72,9 @@ const defaultState: GuideStoreState = {
|
|
|
};
|
|
|
|
|
|
type GuideStoreInterface = {
|
|
|
- onFetchSucceeded(data: GuidesServerData): void;
|
|
|
+ browserHistoryListener: null | (() => void);
|
|
|
|
|
|
+ onFetchSucceeded(data: GuidesServerData): void;
|
|
|
onRegisterAnchor(target: string): void;
|
|
|
onUnregisterAnchor(target: string): void;
|
|
|
recordCue(guide: string): void;
|
|
@@ -75,23 +82,45 @@ type GuideStoreInterface = {
|
|
|
updatePrevGuide(nextGuide: Guide | null): void;
|
|
|
};
|
|
|
|
|
|
-const storeConfig: Reflux.StoreDefinition & GuideStoreInterface = {
|
|
|
+const storeConfig: Reflux.StoreDefinition & GuideStoreInterface & SafeStoreDefinition = {
|
|
|
state: defaultState,
|
|
|
+ unsubscribeListeners: [],
|
|
|
+ browserHistoryListener: null,
|
|
|
|
|
|
init() {
|
|
|
this.state = defaultState;
|
|
|
|
|
|
this.api = new Client();
|
|
|
- this.listenTo(GuideActions.fetchSucceeded, this.onFetchSucceeded);
|
|
|
- this.listenTo(GuideActions.closeGuide, this.onCloseGuide);
|
|
|
- this.listenTo(GuideActions.nextStep, this.onNextStep);
|
|
|
- this.listenTo(GuideActions.toStep, this.onToStep);
|
|
|
- this.listenTo(GuideActions.registerAnchor, this.onRegisterAnchor);
|
|
|
- this.listenTo(GuideActions.unregisterAnchor, this.onUnregisterAnchor);
|
|
|
- this.listenTo(OrganizationsActions.setActive, this.onSetActiveOrganization);
|
|
|
+
|
|
|
+ this.unsubscribeListeners.push(
|
|
|
+ this.listenTo(GuideActions.fetchSucceeded, this.onFetchSucceeded)
|
|
|
+ );
|
|
|
+ this.unsubscribeListeners.push(
|
|
|
+ this.listenTo(GuideActions.closeGuide, this.onCloseGuide)
|
|
|
+ );
|
|
|
+ this.unsubscribeListeners.push(this.listenTo(GuideActions.nextStep, this.onNextStep));
|
|
|
+ this.unsubscribeListeners.push(this.listenTo(GuideActions.toStep, this.onToStep));
|
|
|
+ this.unsubscribeListeners.push(
|
|
|
+ this.listenTo(GuideActions.registerAnchor, this.onRegisterAnchor)
|
|
|
+ );
|
|
|
+ this.unsubscribeListeners.push(
|
|
|
+ this.listenTo(GuideActions.unregisterAnchor, this.onUnregisterAnchor)
|
|
|
+ );
|
|
|
+ this.unsubscribeListeners.push(
|
|
|
+ this.listenTo(OrganizationsActions.setActive, this.onSetActiveOrganization)
|
|
|
+ );
|
|
|
|
|
|
window.addEventListener('load', this.onURLChange, false);
|
|
|
- browserHistory.listen(() => this.onURLChange());
|
|
|
+ this.browserHistoryListener = browserHistory.listen(() => this.onURLChange());
|
|
|
+ },
|
|
|
+
|
|
|
+ teardown() {
|
|
|
+ cleanupActiveRefluxSubscriptions(this.unsubscribeListeners);
|
|
|
+ window.removeEventListener('load', this.onURLChange);
|
|
|
+
|
|
|
+ if (this.browserHistoryListener) {
|
|
|
+ this.browserHistoryListener();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
onURLChange() {
|
|
@@ -250,6 +279,8 @@ const storeConfig: Reflux.StoreDefinition & GuideStoreInterface = {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
-const GuideStore = Reflux.createStore(storeConfig) as Reflux.Store & GuideStoreInterface;
|
|
|
+const GuideStore = Reflux.createStore(
|
|
|
+ makeSafeRefluxStore(storeConfig)
|
|
|
+) as SafeRefluxStore & GuideStoreInterface;
|
|
|
|
|
|
export default GuideStore;
|