UNPKG

moy-dom

Version:

A flexiable Virtual DOM library for building modern web interface.

28 lines (23 loc) 728 B
/** * [diffProps diff two object(props)] * @param {[Object]} newTreeProps [the new props] * @param {[Object]} oldTreeProps [the old props] * @return {[Object]} [null for no changes, Object for changes] */ export default function diffProps(newTreeProps, oldTreeProps){ const propPatches = {} for(let [key, value] of Object.entries(oldTreeProps)){ if(newTreeProps[key] !== value){ propPatches[key] = newTreeProps[key] // undefined represents remove the attribute } } for(let [key, value] of Object.entries(newTreeProps)){ if(!Reflect.has(oldTreeProps, key)){ propPatches[key] = value } } for(let propPatch in propPatches){ return propPatches } return null }