Do not pad negative numbers (#50)

This commit is contained in:
Borys Levytskyi
2023-05-15 18:53:27 +03:00
committed by GitHub
parent 0b1f5fa862
commit 22f38e936f
20 changed files with 258 additions and 154 deletions

View File

@@ -9,7 +9,8 @@ export type PersistedAppData = {
debugMode: boolean | null;
pageVisistsCount: number;
donationClicked: boolean;
annotateTypes: boolean
annotateTypes: boolean;
dimExtrBits: boolean;
}
export type CommandResultView = {
@@ -23,7 +24,7 @@ export type AppStateChangeHandler = (state: AppState) => void;
type ViewFactory = () => JSX.Element;
export default class AppState {
version: number = APP_VERSION;
emphasizeBytes: boolean;
debugMode: boolean = false;
@@ -37,23 +38,25 @@ export default class AppState {
donationClicked: boolean;
showSettings: boolean = false;
annotateTypes: boolean = false;
dimExtraBits: boolean = false;
constructor(persistData : PersistedAppData, env: string) {
constructor(persistData: PersistedAppData, env: string) {
this.env = env;
this.emphasizeBytes = !!persistData.emphasizeBytes;
this.emphasizeBytes = !!persistData.emphasizeBytes;
this.persistedVersion = persistData.version || 0.1;
this.wasOldVersion = persistData.version != null && this.version > this.persistedVersion;
this.debugMode = persistData.debugMode === true;
this.pageVisitsCount = persistData.pageVisistsCount || 0;
this.donationClicked = persistData.donationClicked;
this.annotateTypes = !!persistData.annotateTypes;
this.dimExtraBits = !!persistData.dimExtrBits;
}
addCommandResult(input : string, view : ViewFactory) {
addCommandResult(input: string, view: ViewFactory) {
const key = generateKey();
this.commandResults.unshift({key, input, view});
this.commandResults.unshift({ key, input, view });
log.debug(`command result added: ${input}`);
this.triggerChanged();
}
@@ -64,19 +67,19 @@ export default class AppState {
}
removeResult(index: number) {
if(index < 0 || index >= this.commandResults.length)
if (index < 0 || index >= this.commandResults.length)
return;
this.commandResults.splice(index, 1);
this.triggerChanged();
}
toggleEmphasizeBytes() {
this.emphasizeBytes = !this.emphasizeBytes;
toggleEmphasizeBytes(value?: boolean) {
this.emphasizeBytes = value != null ? value : !this.emphasizeBytes;
this.triggerChanged();
}
onChange(handler : AppStateChangeHandler) {
onChange(handler: AppStateChangeHandler) {
this.changeHandlers.push(handler);
}
@@ -85,8 +88,8 @@ export default class AppState {
}
setUiTheme(theme: string) {
this.uiTheme = theme;
this.triggerChanged();
this.uiTheme = theme;
this.triggerChanged();
}
toggleDebugMode() {
@@ -99,8 +102,13 @@ export default class AppState {
this.triggerChanged();
}
toggleAnnotateTypes() {
this.annotateTypes = !this.annotateTypes;
toggleAnnotateTypes(value?: boolean) {
this.annotateTypes = value != null ? value : !this.annotateTypes;
this.triggerChanged();
}
toggleDimExtrBits() {
this.dimExtraBits = !this.dimExtraBits;
this.triggerChanged();
}
@@ -109,15 +117,15 @@ export default class AppState {
this.triggerChanged();
}
onDonationClicked() : boolean{
if(this.donationClicked === true) return false;
onDonationClicked(): boolean {
if (this.donationClicked === true) return false;
this.donationClicked = true;
this.triggerChanged();
return true;
}
getPersistData() : PersistedAppData {
getPersistData(): PersistedAppData {
return {
emphasizeBytes: this.emphasizeBytes,
uiTheme: this.uiTheme,
@@ -125,11 +133,12 @@ export default class AppState {
debugMode: this.debugMode,
pageVisistsCount: this.pageVisitsCount,
donationClicked: this.donationClicked,
annotateTypes: this.annotateTypes
annotateTypes: this.annotateTypes,
dimExtrBits: this.dimExtraBits
}
}
};
function generateKey() : number {
return Math.ceil(Math.random()*10000000) ^ Date.now(); // Because why the hell not...
function generateKey(): number {
return Math.ceil(Math.random() * 10000000) ^ Date.now(); // Because why the hell not...
}