Skip to content

Commit

Permalink
Add checkbox to enable/disable RTI type checking (#168)
Browse files Browse the repository at this point in the history
* Add checkbox to enable/disable RTI type checking

* Fix lint
  • Loading branch information
kungfooman authored Jun 17, 2024
1 parent d11b27e commit 1dac208
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
"no-dupe-else-if": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
// "no-duplicate-imports": "error",
"no-empty-character-class": "error",
"no-empty-pattern": "error",
"no-ex-assign": "error",
Expand Down
29 changes: 23 additions & 6 deletions src-runtime/TypePanel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {assertMode } from "./assertMode.js";
import {options } from "./options.js";
import {warnedTable} from "./warnedTable.js";
import {Warning } from "./Warning.js";
import {assertMode } from "./assertMode.js";
import {options } from "./options.js";
import {disableTypeChecking} from "./validateType.js";

Check warning on line 3 in src-runtime/TypePanel.js

View workflow job for this annotation

GitHub Actions / Lint

'/home/runner/work/RuntimeTypeInspector.js/RuntimeTypeInspector.js/src-runtime/validateType.js' imported multiple times
import {enableTypeChecking } from "./validateType.js";

Check warning on line 4 in src-runtime/TypePanel.js

View workflow job for this annotation

GitHub Actions / Lint

'/home/runner/work/RuntimeTypeInspector.js/RuntimeTypeInspector.js/src-runtime/validateType.js' imported multiple times
import {warnedTable } from "./warnedTable.js";
import {Warning } from "./Warning.js";
/**
* @param {HTMLDivElement} div - The <div>.
*/
Expand Down Expand Up @@ -39,8 +41,13 @@ function niceDiv(div) {
div.classList.add('rti');
document.head.appendChild(rule);
}
function isEnabled() {
const tmp = localStorage.getItem('rti-enabled');
return tmp === null || tmp === 'true';
}
class TypePanel {
div = document.createElement('div');
inputEnable = document.createElement('input');
spanErrors = document.createElement('span');
span = document.createElement('span');
select = document.createElement('select');
Expand All @@ -51,12 +58,22 @@ class TypePanel {
buttonLoadState = document.createElement('button');
buttonSaveState = document.createElement('button');
constructor() {
const {div, spanErrors, span, select, option_spam, option_once, option_never, buttonHide, buttonLoadState, buttonSaveState} = this;
const {div, inputEnable, spanErrors, span, select, option_spam, option_once, option_never, buttonHide, buttonLoadState, buttonSaveState} = this;
div.style.position = "absolute";
div.style.bottom = "0px";
div.style.right = "0px";
div.style.zIndex = "10";
niceDiv(div);
inputEnable.checked = isEnabled();
inputEnable.type = "checkbox";
inputEnable.onchange = (e) => {
if (inputEnable.checked) {
enableTypeChecking();
} else {
disableTypeChecking();
}
};
inputEnable.onchange();
span.innerText = " Type report mode:";
option_spam.text = 'spam';
option_once.text = 'once';
Expand All @@ -83,7 +100,7 @@ class TypePanel {
buttonLoadState.onclick = () => this.loadState();
buttonSaveState.textContent = 'Save state';
buttonSaveState.onclick = () => this.saveState();
div.append(spanErrors, span, select, buttonHide, buttonLoadState, buttonSaveState, warnedTable);
div.append(inputEnable, spanErrors, span, select, buttonHide, buttonLoadState, buttonSaveState, warnedTable);
div.style.maxHeight = '200px';
div.style.overflow = 'scroll';
const finalFunc = () => document.body.append(div);
Expand Down
2 changes: 2 additions & 0 deletions src-runtime/validateType.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import {validateUnion } from "./validateUnion.js";
export let enabled = true;
export function disableTypeChecking() {
enabled = false;
localStorage.setItem('rti-enabled', 'false');
}
export function enableTypeChecking() {
enabled = true;
localStorage.setItem('rti-enabled', 'true');
}
/**
* @typedef {object} TypeObject
Expand Down

0 comments on commit 1dac208

Please sign in to comment.