Skip to content

Refactor var to const/let in core JS utilities (1/4)#3300

Merged
Mips2648 merged 2 commits intojeedom:developfrom
limad:refactor/var-to-const-utils
May 5, 2026
Merged

Refactor var to const/let in core JS utilities (1/4)#3300
Mips2648 merged 2 commits intojeedom:developfrom
limad:refactor/var-to-const-utils

Conversation

@limad
Copy link
Copy Markdown
Contributor

@limad limad commented Apr 28, 2026

Summary

First of four migration PRs splitting the varconst/let work from #3297 by functional domain. This batch covers 11 utility/AJAX-boilerplate files:

jeedom.class.js   private.class.js   core.js
cache.class.js    queue.class.js     listener.class.js
network.class.js  security.class.js  message.class.js
dataStore.class.js  repo.class.js

Most of these files follow the same uniform AJAX boilerplate pattern (paramsRequired, paramsSpecifics, try/catch, domUtils.ajax(paramsAJAX)), so the migration is largely mechanical: var X = ...const X = ... for declarations that are never reassigned, let for the rest.

Incidental fixes (caught during migration)

  • jeedom.class.js — removed the top-level var Highcharts declaration. With var at top-level it became window.Highcharts and was overwritten by highstock.js loaded later. With const/let it would shadow window.Highcharts, leaving the local binding undefined and crashing jeedom.init() with TypeError: Highcharts.setOptions is undefined. Fix: rely on window.Highcharts directly.
  • private.class.js — renamed top-level var init to _init. With const init it collided with the global function init() declared in core.js (SyntaxError: redeclaration of non-configurable global property init).
  • private.class.jsconst valuelet value (was reassigned by value += '', would have thrown TypeError: Assignment to constant variable).
  • private.class.js — removed unused var param = null (dead code).

Test plan

  • Reload any Jeedom page — verify jeedom.init() runs without console errors
  • Open a chart that uses Highcharts (history, dashboard widget) — verify it renders
  • Trigger any API call going through jeedom.private.getParamsAJAX — verify the result handler still works
  • Verify init() and _init() both work where used

Part of the split following #3297 discussion. Stacks logically with #3299 (ESLint baseline) but does not depend on it.

Migration of `var` declarations to `const`/`let` in 11 utility/AJAX
boilerplate files: jeedom, private, core, cache, queue, listener,
network, security, message, dataStore, repo.

Also includes incidental fixes that surfaced during the migration:
- jeedom.class.js: removed `var Highcharts` declaration that was
  shadowing window.Highcharts (set by highstock.js loaded later);
  jeedom.init() crashed with "Highcharts is undefined" without it.
- private.class.js: renamed top-level `var init` to `_init` to avoid
  "redeclaration of non-configurable global property init" (collides
  with the global function init() in core.js).
- private.class.js: changed `const value` to `let value` (it was
  reassigned by `value += ''`).
Comment thread core/js/jeedom.class.js Outdated
jeedom.changes = function() {
var paramsRequired = []
var paramsSpecifics = {
const paramsRequired =[]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the space after = got stripped on empty initializations: const paramsRequired =[] instead of const paramsRequired = []. It's inconsistent with the other assignments in the diff (const params = domUtils.extend(...) keeps the space) and breaks space-infix-ops.

@limad
Copy link
Copy Markdown
Contributor Author

limad commented May 1, 2026

Good catch @kwizer15, thanks. Fixed in 148493b — restored the space after = on the 68 affected lines in jeedom.class.js. The same artefact appeared in cmd.class.js (PR #3301) and is fixed there in 5e57ff9. The other migration PRs (#3302, #3303) and the desktop/js work were not affected — verified with grep -rE "(const|let)\s+\w+\s*=[\[\{]" after the fix.

@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:05
@Mips2648 Mips2648 merged commit 9882968 into jeedom:develop May 5, 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 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