我花了6天时间构建了自己的 VDOM 库,因为我讨厌 React 处理 memo 的方式。
I spent 6 days building my VDOM library as I hated how React handles memo

原始链接: https://vflash.github.io/Tyaff/

**Tyaff** 是一个轻量级、高性能的 React 替代方案,完全基于纯 ES6+ JavaScript 构建。它具备自定义虚拟 DOM、极简 API,以及针对批量操作(如交换和重定向父节点)进行优化的独特架构。 主要特色包括: * **可预测的优化**:`memo()` 仅阻塞目标组件,允许子组件独立更新。 * **可变数据**:组件可以直接读取全局存储或单例,无需层层传递 props。 * **动态上下文**:基于拉取的系统允许组件充当提供者,并可在无需包装组件的情况下请求值。 * **全局键 (Global Keys)**:键在整个渲染树中是唯一的,使组件能够在父节点间移动的同时保留其状态。 Tyaff 专为高性能和易用性而设计,支持通过微任务进行批量更新、灵活的工厂模式组件以及高效的传送门(portals)。对于追求极简、高性能且灵活的现代 Web 应用开发,它是一个理想的选择。该项目是由人类架构师与多个 AI 模型共同协作的开源项目,完全兼容所有现代浏览器。

关于一个自建虚拟 DOM (VDOM) 库的 Hacker News 讨论引发了争议,主要原因是有人指责原作者是使用大模型生成内容来操纵网站首页的机器人。 除了关于平台审核和 AI 生成“垃圾内容”的元讨论外,还出现了关于是否有必要使用 VDOM 库的技术争论。批评者认为 VDOM 已经过时且效率低下。对此,作者为自己的项目辩护,强调开发体验和架构灵活性优于原始性能指标。 讨论还简要涉及了 SolidJS 等替代方案。虽然一些用户推荐 SolidJS 作为更优越的现代替代品,但其他人反驳称它不能直接替代 React,并指出这两个框架提供了根本不同的开发体验。总体而言,该帖凸显了平台对于 AI 垃圾内容的持续紧张情绪,以及现代前端开发中不同的理念分歧。
相关文章

原文
Logo

A lightweight alternative to React in pure JavaScript (ES6+) with its own virtual DOM and philosophy of minimalism.

Key differences from React

  • memo() blocks only the current component — children continue their own update chains independently, making optimization predictable
  • Mutable data from any source — a component can read a global store, singleton, or window directly, without props drilling
  • Pull-based context without Provider/Consumer — any component declares itself a provider via context: { key() { ... } }, children request values via this.context(key)
  • Props as first argument — signatures like init(props), memo(props), render({ title, items }) allow destructuring props right in the definition
  • Keys are unique across the entire render — this allows moving components between different parents while preserving instance and state

Main features

  • Compact and performant — minimal API surface, custom diff/patch algorithm, batching updates via microtask
  • Optimized for bulk operations — reverse, swap, reparenting faster than React
  • Dynamic context tree — hierarchical provider system with automatic propagation through HTML tags
  • Factory-based components — unified creation pattern, automatic method binding, flexible lifecycle
  • Portals with deferred mounting —!mounting into arbitrary DOM containers with anchor nodes
  • Key system — user-defined keys are unique across the entire render, automatic path-based keys
  • Fragment with key — grouping children without wrapper with ability to move groups

Installation

Quick start

import { h, Component, mount } from 'tyaff';

const Counter = Component({
    count: 0,

    increment() {
        this.update({ count: this.count + 1 });
    },

    render() {
        return h('div', null,
            h('p', null, 'Counter: ' + this.count),
            h('button', { onClick: this.increment }, '+')
        );
    }
});

mount(Counter, document.getElementById('app'));

Example: components with context

const ThemeProvider = Component({
    theme: 'light',

    context: {
        theme() { return this.theme; },
        toggleTheme() {
            this.theme = this.theme === 'light' ? 'dark' : 'light';
            this.update();
        }
    },

    render() {
        return h('div', null, this.props.children);
    }
});

const ThemedButton = Component({
    render() {
        const theme = this.context('theme');
        return h('button', { className: 'btn-' + theme }, 'Button');
    }
});

mount(
    h(ThemeProvider, null,
        h(ThemedButton)
    ),
    document.body
);

Example: global store

// store.js
export const store = { count: 0 };

// app.js
import { store } from './store.js';
import { h, Component, mount, refresh } from 'tyaff';

const Counter = Component({
    render() {
        return h('div', null, 'Count: ', store.count);
    }
});

mount(Counter, document.getElementById('app'));

// Update
store.count = 55;
await refresh();  // all components will re-read the store

Resources

  • Documentation — full API description, usage examples, lifecycle, context, portals, optimizations
  • Live example — interactive demo in the browser
  • Benchmark — performance comparison tyaff vs React (14 scenarios)
  • Changelog — what’s new in the project

Acknowledgments

This project is a showcase of human-AI collaboration:

  • Human: architecture, design decisions, code review, vision
  • Qwen: development, optimization, documentation, visual design
  • GLM: development, optimization
  • Gemini: research and analysis (via Search)

Browser Support

  • Chrome 86+
  • Firefox 78+
  • Safari 14+
  • All modern browsers with ES6 modules support

License

MIT

联系我们 contact @ memedata.com