Skip to content

Refactor var to const/let in equipment and commands (2/4)#3301

Merged
Mips2648 merged 4 commits into
jeedom:developfrom
limad:refactor/var-to-const-equipment
May 6, 2026
Merged

Refactor var to const/let in equipment and commands (2/4)#3301
Mips2648 merged 4 commits into
jeedom:developfrom
limad:refactor/var-to-const-equipment

Conversation

@limad
Copy link
Copy Markdown
Contributor

@limad limad commented Apr 28, 2026

Summary

Second of four migration PRs splitting #3297 by functional domain. This batch covers 4 files handling core domain logic (equipment, commands, objects, scenarios):

eqLogic.class.js   cmd.class.js
object.class.js    scenario.class.js

These are the most complex files in core/js/, with deeply nested callbacks (success/error/pre_success/forEach), so this batch warrants more careful review than the utility batch.

Incidental fix (caught during migration)

  • cmd.class.js (jeedom.cmd.execute)var eqLogic was declared inside an if (notify) { ... } block but referenced from callbacks at lines 87, 107, 131, 151, 166, 172 (the jeedom.cmd.notifyEq(eqLogic, true) calls in pre_success). With var, function-scoped hoisting made it visible. Migrated to const/let it became block-scoped and threw ReferenceError: eqLogic is not defined on every dashboard command execution. Fix: hoisted the declaration out of the if block using a ternary so const eqLogic = ... : null.

Test plan

  • Execute a command from the dashboard (action button or info refresh) — verify no ReferenceError and the eqLogic notification (the brief icon flash) still triggers
  • Open the configuration modal of any equipment — verify eqLogic.print and eqLogic.save work
  • Open a scenario and run it manually — verify scenario execution
  • Open an object summary on the dashboard — verify summary updates

Part of the split following #3297 discussion.

limad added 2 commits April 28, 2026 07:49
Migration of `var` declarations to `const`/`let` in 4 files handling
core domain logic: eqLogic, cmd, object, scenario.

Also includes incidental fixes that surfaced during the migration:
- cmd.class.js: hoisted eqLogic out of `if (notify) { ... }` block
  in jeedom.cmd.execute. With `var`, hoisting made it visible to
  callbacks at lines 87-172 (notifyEq calls in pre_success). With
  `let`/`const` block-scoping, those callbacks would throw
  "ReferenceError: eqLogic is not defined" on every command
  execution from the dashboard.
@limad
Copy link
Copy Markdown
Contributor Author

limad commented May 1, 2026

FYI: applied the same formatting fix here in 5e57ff9 — restored the space after = on 38 affected lines in cmd.class.js. Spotted thanks to @kwizer15 in #3300.

@Mips2648 Mips2648 added the changelog-dev Use to generate release notes / changelog To be apply on PR label May 5, 2026
@Mips2648 Mips2648 requested review from Salvialf and zoic21 May 5, 2026 13:12
Comment thread core/js/cmd.class.js Outdated
@Mips2648 Mips2648 added this to the 4.6 milestone May 5, 2026
Replace the ternary expression with an explicit let + if block for clarity
and consistency with the imperative style used throughout the file:

  const eqLogic = notify ? querySelector... : null
→
  let eqLogic = null
  if (notify) {
    eqLogic = querySelector...
  }
Comment thread core/js/cmd.class.js
Comment thread core/js/cmd.class.js
@Mips2648 Mips2648 merged commit 622a0a3 into jeedom:develop May 6, 2026
9 checks passed
@Mips2648 Mips2648 added changelog-other Use to generate release notes and removed changelog-dev Use to generate release notes / changelog To be apply on PR Ready to merge Need review labels May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-other Use to generate release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants