![]() |
|
// OLD const oldList = reflect.array(['a', 'b']); oldList.push('c'); render(); // NEW (made with reflect4 list new) const newList = reflect4.list.new(['a', 'b']); newList.append('c'); // No render() call needed.
// Helper method to add a new task function addTask(taskText) tasks.append( id: Date.now(), text: taskText, completed: false ); made with reflect4 list new
When you add a new task or toggle completion, activeTasks automatically recomputes and the UI updates only the necessary elements. Reflect4’s list new includes a powerful patch method for batch updates: // OLD const oldList = reflect
Reflect4 wins because it doesn’t diff the virtual DOM. It directly patches the DOM based on exact array mutations. This makes it ideal for real-time dashboards, stock tickers, and collaborative editing tools. Even with a powerful tool like list new , mistakes happen. Here’s what to watch for: Pitfall 1: Direct Array Reassignment Bad: It directly patches the DOM based on exact array mutations
// Helper to remove function removeTask(id) const index = tasks.findIndex(task => task.id === id); if (index !== -1) tasks.deleteAt(index);
| Operation | React (keyed) | Vue 3 | Reflect4 List New | |-----------|---------------|-------|-------------------| | Append 1 item | ~45ms | ~28ms | | | Remove first item | ~52ms | ~30ms | ~6ms | | Update every 10th item | ~120ms | ~65ms | ~22ms |
| Â |