* Sets used conditionally. * @param {(condition: UsageStateType) => boolean} condition compare with old value * @param {UsageStateType} newValue set when condition is true * @param {RuntimeSpec} runtime only apply to this runtime * @returns {boolean} true when something has changed
(condition, newValue, runtime)
| 1281 | * @returns {boolean} true when something has changed |
| 1282 | */ |
| 1283 | setUsedConditionally(condition, newValue, runtime) { |
| 1284 | if (runtime === undefined) { |
| 1285 | if (this._globalUsed === undefined) { |
| 1286 | this._globalUsed = newValue; |
| 1287 | return true; |
| 1288 | } |
| 1289 | if (this._globalUsed !== newValue && condition(this._globalUsed)) { |
| 1290 | this._globalUsed = newValue; |
| 1291 | return true; |
| 1292 | } |
| 1293 | } else if (this._usedInRuntime === undefined) { |
| 1294 | if (newValue !== UsageState.Unused && condition(UsageState.Unused)) { |
| 1295 | this._usedInRuntime = new Map(); |
| 1296 | forEachRuntime(runtime, (runtime) => |
| 1297 | /** @type {UsedInRuntime} */ |
| 1298 | (this._usedInRuntime).set(/** @type {string} */ (runtime), newValue) |
| 1299 | ); |
| 1300 | return true; |
| 1301 | } |
| 1302 | } else { |
| 1303 | let changed = false; |
| 1304 | forEachRuntime(runtime, (runtime_) => { |
| 1305 | const runtime = /** @type {string} */ (runtime_); |
| 1306 | const usedInRuntime = |
| 1307 | /** @type {UsedInRuntime} */ |
| 1308 | (this._usedInRuntime); |
| 1309 | let oldValue = |
| 1310 | /** @type {UsageStateType} */ |
| 1311 | (usedInRuntime.get(runtime)); |
| 1312 | if (oldValue === undefined) oldValue = UsageState.Unused; |
| 1313 | if (newValue !== oldValue && condition(oldValue)) { |
| 1314 | if (newValue === UsageState.Unused) { |
| 1315 | usedInRuntime.delete(runtime); |
| 1316 | } else { |
| 1317 | usedInRuntime.set(runtime, newValue); |
| 1318 | } |
| 1319 | changed = true; |
| 1320 | } |
| 1321 | }); |
| 1322 | if (changed) { |
| 1323 | if (this._usedInRuntime.size === 0) this._usedInRuntime = undefined; |
| 1324 | return true; |
| 1325 | } |
| 1326 | } |
| 1327 | return false; |
| 1328 | } |
| 1329 | |
| 1330 | /** |
| 1331 | * Updates used using the provided new value. |
no test coverage detected