Learn-Redux

Hàm Render


Xử lý Render

  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;
    }
}