Render
roots
lưu các gốc Element chuyển thành các component ở View thông qua DOM như sau: function render(){
// Vòng lặp qua roots để chuyển ra VIEW
for(const [root, component] of roots){
const output = component(); // Callback html() ra chuỗi
root.innerHTML = output; // Gán chuỗi html vào element #root để hiển thị
}
Khi này hàm createStore
sẽ là :
function createStore(reducer) {
let state = reducer(); // Sử dụng closure
const roots = new Map();
function render(){
// Vòng lặp qua roots để chuyển ra VIEW
for(const [root, component] of roots){
const output = component();
root.innerHTML = output;
}
}