Skip to content

Commit

Permalink
fix: make datastorage aircraft specific (#9116)
Browse files Browse the repository at this point in the history
* fix: make datastorage aircraft specific

* fix: remove usages of legacy persistence.ts

* use common name for datastore update event

(cherry picked from commit 8c58f8b)
  • Loading branch information
Saschl authored and flogross89 committed Oct 22, 2024
1 parent f346cfb commit aba9b96
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class NXDataStore {

static set(key, val) {
SetStoredData(`A32NX_${key}`, val);
this.listener.triggerToAllSubscribers('A32NX_NXDATASTORE_UPDATE', key, val);
this.listener.triggerToAllSubscribers('FBW_NXDATASTORE_UPDATE', key, val);
}

static subscribe(key, callback) {
return Coherent.on('A32NX_NXDATASTORE_UPDATE', (updatedKey, value) => {
return Coherent.on('FBW_NXDATASTORE_UPDATE', (updatedKey, value) => {
if (key === '*' || key === updatedKey) {
callback(updatedKey, value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { forwardRef, PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react';
import { NXDataStore } from '@shared/persistence';
import { NXDataStore } from '@flybywiresim/fbw-sdk';
import { DcElectricalBus } from '@shared/electrical';
import { useSimVar } from './simVars';
import { useUpdate } from './hooks';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { NXDataStore } from '@shared/persistence';
import { NXDataStore } from '@flybywiresim/fbw-sdk';

/**
* This hook allows to read and set a persistent storage property.
Expand Down
2 changes: 1 addition & 1 deletion fbw-a380x/src/systems/instruments/src/SD/StatusArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';

import { useSimVar } from '@instruments/common/simVars';
import { useArinc429Var } from '@instruments/common/arinc429';
import { NXUnits } from '@shared/NXUnits';
import { NXUnits } from '@flybywiresim/fbw-sdk';
import { Layer } from '@instruments/common/utils';

export const StatusArea = () => {
Expand Down
33 changes: 0 additions & 33 deletions fbw-a380x/src/systems/shared/src/NXUnits.ts

This file was deleted.

51 changes: 0 additions & 51 deletions fbw-a380x/src/systems/shared/src/persistence.ts

This file was deleted.

136 changes: 0 additions & 136 deletions fbw-a380x/src/systems/shared/src/units.ts

This file was deleted.

9 changes: 5 additions & 4 deletions fbw-common/src/systems/shared/src/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type SubscribeCancellation = () => void;
* Allows interacting with the persistent storage
*/
export class NXDataStore {
private static aircraftProjectPrefix: string = process.env.AIRCRAFT_PROJECT_PREFIX.toUpperCase();
private static mListener: ViewListener.ViewListener;

private static get listener() {
Expand All @@ -22,7 +23,7 @@ export class NXDataStore {
static get(key: string, defaultVal: string): string;
static get(key: string, defaultVal?: string): string | undefined;
static get(key: string, defaultVal?: string): any {
const val = GetStoredData(`A32NX_${key}`);
const val = GetStoredData(`${this.aircraftProjectPrefix}_${key}`);
// GetStoredData returns null on error, or empty string for keys that don't exist (why isn't that an error??)
// We could use SearchStoredData, but that spams the console with every key (somebody left their debug print in)
if (val === null || val.length === 0) {
Expand All @@ -38,12 +39,12 @@ export class NXDataStore {
* @param val The value to assign to the property
*/
static set(key: string, val: string): void {
SetStoredData(`A32NX_${key}`, val);
this.listener.triggerToAllSubscribers('A32NX_NXDATASTORE_UPDATE', key, val);
SetStoredData(`${this.aircraftProjectPrefix}_${key}`, val);
this.listener.triggerToAllSubscribers('FBW_NXDATASTORE_UPDATE', key, val);
}

static subscribe(key: string, callback: SubscribeCallback): SubscribeCancellation {
return Coherent.on('A32NX_NXDATASTORE_UPDATE', (updatedKey: string, value: string) => {
return Coherent.on('FBW_NXDATASTORE_UPDATE', (updatedKey: string, value: string) => {
if (key === '*' || key === updatedKey) {
callback(updatedKey, value);
}
Expand Down

0 comments on commit aba9b96

Please sign in to comment.