How baidu/san works
Main components
• Core API & Component Definition: This is where developers call san.defineComponent (as shown in the README’s quick start). It acts as the entry point and is defined in the “src/main.js” and “src/view/define-component.js” files.
• Template Parser: In the “src/parser” directory, you have multiple specialized modules (like parse-template.js, parse-text.js, and several “read-*.js” files) that work together to convert a component’s template (possibly expressed in HTML-like ANode structures) into an internal/intermediate representation.
• Runtime/Data Binding: The “src/runtime” directory contains modules (data-proxy.js, eval-expr.js, default-filters.js, etc.) that manage the reactive data-binding, changes detection, and evaluation of expressions.
• View & Virtual DOM Management: The “src/view” directory contains logic that transforms parsed templates and runtime changes into actual DOM operations. It includes functions responsible for creating nodes, hydrating components, handling transitions, and managing slots.
• Browser Utilities: The “src/browser” directory includes helper modules for DOM manipulation, event handling, compatibility (like “ie-old-than-9.js”), and other browser-specific operations.
• Utility Functions: The “src/util” directory has helper functions (like bind.js, extend.js, warn.js) that support various tasks across the framework.
• Tooling & Build Process: While not part of the runtime, the “tool” and “types” directories include scripts for building, packaging, development utilities and TypeScript definitions that enable smooth ecosystem integration.
Relationships and interactions
• View Layer Integration: From the Runtime, show data and template information being passed to the View module, where components are actually rendered, mounted, and updated. The View layer then interacts with the Browser Utilities to perform DOM operations.
Important architectural patterns
• Modular Design: Notice that functionalities are clearly separated into independent modules (parser, runtime, view, browser, util), reflecting a layered architecture.
• Template-to-VM Flow: Emphasize the pattern where the template is first parsed and then becomes a reactive model (ANode) that eventually drives the view updates.
• Cross-Cutting Tools: Recognize that testing, documentation, and build/packaging are handled separately, underscoring good open-source project practices.
Relevant technologies/frameworks
• JavaScript is the primary language.
• The framework supports different module systems (examples include AMD, ESNext, TypeScript, and store patterns) as evidenced by the multiple “example/todos-*” directories.
• Browser compatibility utilities in “src/browser” indicate an emphasis on cross-browser support.
• Build and packaging tools are integrated for both development and distribution (look at package.json, appveyor.yml, and the “tool” directory).
• Clear labels on each component (e.g., “Core API”, “Parser”, “Runtime”, “View”, “Browser Utilities”, “Tooling”).