File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,6 @@ export type LegacyDataStoreSettingKey<k extends string> = k & (k extends keyof N
2020 * Allows interacting with the persistent storage
2121 */
2222export class NXDataStore {
23- private static readonly settingSubjectMap = new Map < string , Subject < any > > ( ) ;
24-
2523 private static readonly settingsDefaultValues : { [ k in keyof NXDataStoreSettings ] : NXDataStoreSettings [ k ] } = {
2624 EFB_UI_THEME : 'blue' ,
2725 } ;
@@ -37,6 +35,18 @@ export class NXDataStore {
3735 return this . mListener ;
3836 }
3937
38+ private static get settingSubjectMap ( ) : Map < string , Subject < any > > {
39+ // We store the subject map on the window rather than on a static property,
40+ // because there might be multiples instances of this class (multiple instruments in one VCockpit) and
41+ // triggerToAllSubscribers does not work across instruments on the same VCockpit.
42+
43+ if ( window . NXDATASTORE_SUBJECT_MAP !== undefined ) {
44+ return window . NXDATASTORE_SUBJECT_MAP ;
45+ }
46+
47+ return ( window . NXDATASTORE_SUBJECT_MAP = new Map ( ) ) ;
48+ }
49+
4050 /**
4151 * Gets a mutable subscribable setting given a key. This subscribable is updated whenever the setting is changed, and setting it
4252 * will change the setting.
@@ -48,6 +58,8 @@ export class NXDataStore {
4858
4959 if ( subject === undefined ) {
5060 subject = NXDataStore . createSettingSubject ( key ) ;
61+
62+ this . settingSubjectMap . set ( key , subject ) ;
5163 }
5264
5365 return subject ;
Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ declare global {
5454 } ;
5555
5656 interface Window {
57+ /**
58+ * Setting subject map for `NXDataStore`
59+ */
60+ NXDATASTORE_SUBJECT_MAP : Map < string , Subject < any > > | undefined ;
61+
5762 /**
5863 * Present if the instrument is running in [ACE](https://github.com/flybywiresim/ace)
5964 */
You can’t perform that action at this time.
0 commit comments