diffDOM을 사용한 DOM 비교
                                            
                                                
                                                
                                                
                                                
                                                
                                                 24164 단어  domjavascript
                    
실제로 많은 대안이 있으며 diffDOM이 그 중 하나입니다.
다음은 사용 예입니다. diffDOMSample
lib.js
const diffDOM=function(e){...};
const dd = new diffDOM.DiffDOM(); 
let render;
function html(html) {
    var template = document.createElement('template');
    html = html.trim(); // Never return a text node of whitespace as the result
    template.innerHTML = html;
    return template.content.firstChild;
}
function init(view, state, target = document.body) {
  let preview = view(state);
  target.append(preview);
  render = function () {
    dd.apply(preview, dd.diff(preview, view(state)));
  }
}
export { html, init, render }
state.js
import { render } from "./lib.js"
const State = {
    counter: 0
}
const handler = { 
    get(target, property) {
        return target[property];
    },
    set(target, property, value) {
       Reflect.set(target, property, value);   
       render()
       return true
    }
}
const state = new Proxy(State, handler);
export { state }
main.js
import { html, init } from "./lib.js" 
import { state  } from "./state.js"
function inc() {
  state.counter = state.counter + 1;
}
function view (state) {
  let view = html(`
    <div>
      <div>Counter <span>${state.counter}</span> </div> 
      <button>INC</button>
    </div>
 `);
 let btn = view.querySelector("button")
 btn.onclick = inc;
 return view;
}
init(view, state);fully at the following sample :
                Reference
이 문제에 관하여(diffDOM을 사용한 DOM 비교), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/artydev/dom-diffing-with-diffdom-4eml텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)