]> git.ardis.lu - 4-byte-gen/commitdiff
Use one state reference
authorArdis Lu <ardisglu@gmail.com>
Sun, 26 Mar 2023 04:06:19 +0000 (21:06 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 26 Mar 2023 04:06:19 +0000 (21:06 -0700)
index.html

index 468c2f4aa79edf7658c9e9ff4a32b961fd613d69..8572938a66ed46c206f57b102bdbbce4648a5ff2 100644 (file)
     const outputContainer = document.querySelector('output')
     const outputBody = document.querySelector('tbody');
 
-    let state = new Map(); // Store for all active functions
+    const state = new Map(); // Store for all active functions
     globalThis.state = state; // For debugging
 
     /* UI */
 
     // Parse code input and update state to set the new functions. This is the only function that modifies state.
     function setState(code) {
-      const newState = new Map();
+      state.clear();
 
       let strict = false;
       const fns = code.split('\n'); // Assume each function is on its own line
         const normalizedName = `${name}(${parametersTypes})`;
         const byteArray = keccak256(encoder.encode(normalizedName)).slice(0, 4);
         const hash = `0x${[...byteArray].map(b => b.toString(16).padStart(2, '0')).join('')}`;
-        newState.set(normalizedName, {
+        state.set(normalizedName, {
           name,
           parametersTypes,
           normalizedName,
       }
 
       // Retain old state if new state is empty
-      if (newState.size === 0) {
+      if (state.size === 0) {
         status.textContent = 'No Solidity functions were found. Is the input valid Solidity code?';
         return;
       }
-
-      state = newState;
-      globalThis.state = state; // For debugging
     }
 
     // Update status and output table to match state
This page took 0.03889 seconds and 4 git commands to generate.