Skip to content

Commit

Permalink
Change promise to function getDictionaryRequestOptions (#421)
Browse files Browse the repository at this point in the history
* make request promise a function getRequestOptions

* rename for clarity

* change promise to a function

* describe using getRequestOptions

* temporarily enable source maps for debugging

* Revert "temporarily enable source maps for debugging"

This reverts commit 6e40684.

* Default to returning a Promise

---------

Co-authored-by: Andrew Henry <[email protected]>
  • Loading branch information
davetsay and akhenry authored Jan 31, 2024
1 parent c62d10a commit 7b2ee5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,20 @@ openmct.install(installYamcsPlugin({
| yamcsInstance | The name of the instance configured in YAMCS that you wish to connect to. | myproject |
| yamcsFolder | The name of the instance configured in YAMCS that you wish to connect to. | myproject |

## dictionaryRequestCacheStrategyPromise
installYamcsPlugin also accepts an optional promise argument `dictionaryRequestCacheStrategyPromise`. This strategy is passed to the request for loading the YAMCS dictionary, or the `#loadTelemetryDictionary` function in `object-provider.js`. An example of how to make use of this is below.
## getDictionaryRequestOptions
installYamcsPlugin also accepts an optional function argument `getDictionaryRequestOptions`. Use this function to return request options when requesting the YAMCS dictionary. An example of how to make use of this is below.
```
let cacheStrategy;
const cacheStrategyPromise = new Promise(resolve => cacheStrategy)
openmct.install(installYamcsPlugin(
configuration,
cacheStrategryPromise
getDictionaryRequestOptions
))
if (DICTIONARY_VERSION_IS_NEW) { // some check to determine dictionary version
cacheStrategy({cache: 'reload'})
} else {
cacheStrategy({})
function getDictionaryRequestOptions() {
const requestOptions = SOME_CHECK_IF_DICTIONARY_VERSION_IS_NEW
? { cache: 'reload' }
: {};
return requestOptions;
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/openmct-yamcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import ExportToCSVActionPlugin from './actions/exportToCSV/plugin.js';

export default function install(
configuration,
dictionaryRequestCacheStrategyPromise
getDictionaryRequestOptions
) {
return (openmct) => {
openmct.install(openmct.plugins.ISOTimeFormat());
Expand Down Expand Up @@ -133,7 +133,7 @@ export default function install(
pollQuestionTelemetry,
realtimeTelemetryProvider,
configuration.yamcsProcessor,
dictionaryRequestCacheStrategyPromise
getDictionaryRequestOptions
);

openmct.objects.addRoot({
Expand Down
7 changes: 4 additions & 3 deletions src/providers/object-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const YAMCS_API_MAP = {
const operatorStatusParameter = new OperatorStatusParameter();

export default class YamcsObjectProvider {
constructor(openmct, url, instance, folderName, roleStatusTelemetry, pollQuestionParameter, pollQuestionTelemetry, realtimeTelemetryProvider, processor = 'realtime', dictionaryRequestCacheStrategyPromise = Promise.resolve({})) {
constructor(openmct, url, instance, folderName, roleStatusTelemetry, pollQuestionParameter, pollQuestionTelemetry, realtimeTelemetryProvider, processor = 'realtime', getDictionaryRequestOptions = () => Promise.resolve({})) {
this.openmct = openmct;
this.url = url;
this.instance = instance;
Expand All @@ -52,7 +52,7 @@ export default class YamcsObjectProvider {
this.dictionary = {};
this.limitOverrides = {};
this.dictionaryPromise = null;
this.dictionaryRequestCacheStrategyPromise = dictionaryRequestCacheStrategyPromise;
this.getDictionaryRequestOptions = getDictionaryRequestOptions;
this.roleStatusTelemetry = roleStatusTelemetry;
this.pollQuestionParameter = pollQuestionParameter;
this.pollQuestionTelemetry = pollQuestionTelemetry;
Expand Down Expand Up @@ -194,7 +194,8 @@ export default class YamcsObjectProvider {
const operation = 'parameters?details=yes&limit=1000';
const parameterUrl = this.url + 'api/mdb/' + this.instance + '/' + operation;
const url = this.#getMdbUrl('space-systems');
const requestOptions = await this.dictionaryRequestCacheStrategyPromise;

const requestOptions = await this.getDictionaryRequestOptions();

const spaceSystems = await accumulateResults(url, requestOptions, 'spaceSystems', []);
const parameters = await accumulateResults(parameterUrl, requestOptions, 'parameters', []);
Expand Down

0 comments on commit 7b2ee5a

Please sign in to comment.