Messiahhh Frontend Blog and Documentation

website·Indexed 30 days ago

https://messiahhh.github.io/blog/

A comprehensive collection of technical notes and documentation covering frontend development. Topics include JavaScript (BOM, DOM, Proxy, Promise), TypeScript (tsconfig.json, declaration files), React (useState, Hooks), Vue, Node.js (Event Loop, NPM, pnpm), Rust (Cargo, WebAssembly, Tauri), WebGL, Three.js, and database management with MongoDB and MySQL.

Tokens
67.7K
Snippets
419
Records
497
Agent score
75%

What's inside Messiahhh Blog

  1. Overview of Tauri framework

    Tauri is a multi-platform application solution implemented in Rust. Unlike Electron, which bundles Chromium and Node.js, Tauri achieves significantly smaller application sizes by utilizing the operating system's native renderer (WebView).
  2. Understand how pnpm solves phantom dependencies and npm doppelgängers

    pnpm improves upon npm and yarn by changing how node_modules are structured to solve two primary issues:

    1. Phantom Dependencies: npm and yarn use a flattened node_modules structure, allowing code to import sub-dependencies that aren't explicitly listed in package.json. pnpm solves this by using symbolic links (soft links). The top-level node_modules only contains the packages explicitly declared in package.json, which point to a hidden .pnpm directory where the actual dependency tree resides.

    2. npm Doppelgängers: In flattened structures, if multiple packages require different versions of the same dependency, duplicate copies are often created in nested node_modules folders, increasing disk usage. pnpm solves this by using a content-addressable store (typically in ~/.pnpm-store). It creates hard links from the project's node_modules/.pnpm to the global store, ensuring each version of a package is stored only once on the disk regardless of how many projects use it.

  3. Understand the modern browser multi-process architecture

    Modern browsers use a multi-process architecture to ensure stability and performance. The primary processes include:

    • Browser Process (Main Process): The core coordinator.
    • Renderer Process (Multiple): Responsible for converting HTML, CSS, and JS into pixels. It contains the Main Thread (Blink engine for parsing/layout/paint and V8 engine for JS execution) and the Compositor Thread (splits the layout tree into layers for independent rasterization).
    • GPU Process: Handles drawing via the Skia graphics library, which interfaces with OpenGL.
    • Network Process: Manages network communication.
    • Plugin Process (Multiple): Handles browser plugins.
  4. Choose between WebAssembly and Node-API for Rust integration

    Depending on the target environment and performance requirements, Rust can be integrated into the frontend ecosystem using two main approaches:

    1. WebAssembly (WASM): Compatible with both Web browsers and Node.js. It is ideal for cross-platform compatibility and overcoming performance bottlenecks in the browser.
    2. Node-API: Exclusive to Node.js. It offers higher performance than WASM but requires a separate .node binary compilation for every target platform.
  5. Set up PostCSS for CSS compilation

    PostCSS provides CSS compilation capabilities. It can be used via the postcss-cli for command-line compilation or integrated into Webpack using postcss-loader. Configuration can be passed via command-line arguments or defined in a postcss.config.js file. By default, PostCSS does not transform code; plugins must be installed and configured to provide specific transformation features.
  6. Understand the Browser Same-Origin Policy

    The Same-Origin Policy (SOP) prevents scripts from reading or writing resources across different origins unless authorized. Two origins are considered 'same-origin' only if their protocol, domain, and port are identical. While AJAX/Fetch requests are restricted by SOP, certain tags like <script src=""> and <form> are not.
  7. Understand the relationship between JSX and the Virtual DOM

    JSX is a syntactic sugar that is compiled into React.createElement calls. The result of React.createElement is a plain JavaScript object known as a JSX.Element or React.ReactElement, which is commonly referred to as the Virtual DOM. These objects describe the type of element and its properties (props) but do not contain pointers to other elements.
    // JSX Syntax
    const element = <h1 class="hello">hello, world!</h1>
    
    // Compiled to:
    const element = React.createElement('h1', { class: 'hello' }, 'hello, world')
    
    // Resulting Virtual DOM object:
    const element = {
        $$typeof: Symbol(react.element),
        key: null,
        props: {class: "hello", children: "hello, world!"},
        ref: null,
        type: "h1",
    }
  8. Understand TypeScript Declaration Files (.d.ts)

    TypeScript separates variable context (found in .js files) from type context (found in .d.ts files). Declaration files allow developers to provide type information for JavaScript code or external libraries.

    TypeScript loads declaration files via:

    1. tsconfig.json's include array (all .ts and .d.ts files).
    2. tsconfig.json's types and lib options, which default to node_modules/@types and node_modules/typescript/lib respectively.

    Libraries typically distribute types in two ways:

    • As a separate package in node_modules/@types.
    • Bundled with the library, with the path specified in package.json under the types field (requires explicit import to get type hints).
  9. Understand the JavaScript Event Loop and Task Queues

    The event loop manages the execution of code by coordinating between the main thread and task queues. Tasks are categorized into two types:

    1. Macro-tasks: Include the initial script execution, setTimeout, setInterval, I/O operations (e.g., AJAX, file reading), UI events (e.g., clicks), and setImmediate (Node.js specific).
    2. Micro-tasks: Most commonly Promise.then().

    Execution Rule: The event loop executes one macro-task, then exhausts the entire micro-task queue, then moves to the next macro-task.

  10. Understand JavaScript primitive wrapper types

    When calling methods on primitive values (e.g., calling .toString() on a string literal), JavaScript temporarily wraps the primitive in an object of the corresponding wrapper type, executes the method, and then discards the object.
    // Conceptual process of '1'.toString()
    var s = new String('1');
    s.toString();
    s = null;
  11. Intercept object property access and modification with Proxy

    The Proxy object allows you to create a wrapper around a target object to intercept and redefine fundamental operations, such as property lookup (get) and assignment (set).
    let handler = {
        get: function (target, propKey, receiver) {
            console.log(`Reading property: ${propKey}`);
            return target[propKey];
        },
        set: function (target, propKey, newValue, receiver) {
            console.log(`Setting property: ${propKey} to ${newValue}`);
            target[propKey] = newValue;
            return true; // Return true to indicate success
        }
    };
    
    let proxy = new Proxy({ name: 'akara' }, handler);
    
    proxy.name; // Triggers 'get' handler
    proxy.age = 20; // Triggers 'set' handler
  12. Understand the WebGL Rendering Pipeline

    The WebGL rendering process follows these primary stages:

    1. Preparation: Compiling shaders, linking programs, creating VBOs, configuring VAOs, and setting Uniforms/Textures.
    2. Execution: Calling gl.drawArrays() to send draw commands to the GPU.
    3. Vertex Processing: The Vertex Shader runs for each vertex to transform coordinates into Homogeneous Clip Space using three matrices:
      • Model Matrix: Model Space $\rightarrow$ World Space.
      • View Matrix: World Space $\rightarrow$ Camera/View Space.
      • Projection Matrix: Camera Space $\rightarrow$ Clip Space (Perspective or Orthographic).
    4. Rasterization: GPU performs perspective division to get Normalized Device Coordinates (NDC) [-1, 1], clips vertices outside the view frustum, maps to the Viewport, and interpolates varying values for pixels.
    5. Fragment Processing: The Fragment (Pixel) Shader runs for each pixel to determine the final color, which is written to the Framebuffer.
    6. Finalization: Depth testing and other per-pixel operations.