@aguacerowx/javascript-sdk 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aguacerowx/javascript-sdk",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -69,11 +69,14 @@ export class AguaceroCore extends EventEmitter {
69
69
  this.customColormaps = options.customColormaps || {};
70
70
 
71
71
  const userLayerOptions = options.layerOptions || {};
72
+ // EDIT: Determine initial mode from options
73
+ const initialMode = userLayerOptions.mode || 'model';
72
74
  const initialVariable = userLayerOptions.variable || null;
73
75
 
74
76
  this.state = {
75
77
  model: userLayerOptions.model || 'gfs',
76
- isMRMS: false,
78
+ // EDIT: Set isMRMS based on the initial mode
79
+ isMRMS: initialMode === 'mrms',
77
80
  mrmsTimestamp: null,
78
81
  variable: initialVariable,
79
82
  date: null,
@@ -135,15 +138,36 @@ export class AguaceroCore extends EventEmitter {
135
138
  await this.fetchModelStatus(true);
136
139
  await this.fetchMRMSStatus(true);
137
140
 
138
- const latestRun = findLatestModelRun(this.modelStatus, this.state.model);
139
- let initialState = this.state;
141
+ let initialState = { ...this.state };
140
142
 
141
- if (latestRun && !this.state.isMRMS) {
142
- initialState = { ...this.state, ...latestRun, forecastHour: 0 };
143
-
144
- const availableVariables = this.getAvailableVariables(initialState.model);
145
- if (availableVariables && availableVariables.length > 0) {
146
- initialState.variable = availableVariables[0];
143
+ // ADD: Logic to handle an initial MRMS state
144
+ if (initialState.isMRMS) {
145
+ const variable = initialState.variable;
146
+ if (variable && this.mrmsStatus && this.mrmsStatus[variable]) {
147
+ const sortedTimestamps = [...(this.mrmsStatus[variable] || [])].sort((a, b) => b - a);
148
+ initialState.mrmsTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
149
+ } else {
150
+ // Fallback if the provided variable is not valid
151
+ console.warn(`Initial MRMS variable '${variable}' not found. Using default.`);
152
+ const availableMRMSVars = this.getAvailableVariables('mrms');
153
+ if (availableMRMSVars.length > 0) {
154
+ const firstVar = availableMRMSVars[0];
155
+ initialState.variable = firstVar;
156
+ const sortedTimestamps = [...(this.mrmsStatus[firstVar] || [])].sort((a, b) => b - a);
157
+ initialState.mrmsTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
158
+ }
159
+ }
160
+ } else {
161
+ // EDIT: This is the existing logic, now in an else block
162
+ const latestRun = findLatestModelRun(this.modelStatus, initialState.model);
163
+ if (latestRun) {
164
+ initialState = { ...initialState, ...latestRun, forecastHour: 0 };
165
+ if (!initialState.variable) {
166
+ const availableVariables = this.getAvailableVariables(initialState.model);
167
+ if (availableVariables && availableVariables.length > 0) {
168
+ initialState.variable = availableVariables[0];
169
+ }
170
+ }
147
171
  }
148
172
  }
149
173