mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	vdom: Convert new_dict, old_dict from object to Map.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							737efd1fac
						
					
				
				
					commit
					88c73602e0
				
			@@ -174,30 +174,20 @@ exports.update = (replace_content, find, new_dom, old_dom) => {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.update_attrs = (elem, new_attrs, old_attrs) => {
 | 
					exports.update_attrs = (elem, new_attrs, old_attrs) => {
 | 
				
			||||||
    function make_dict(attrs) {
 | 
					    const new_dict = new Map(new_attrs);
 | 
				
			||||||
        const dict = {};
 | 
					    const old_dict = new Map(old_attrs);
 | 
				
			||||||
        _.each(attrs, (attr) => {
 | 
					 | 
				
			||||||
            const k = attr[0];
 | 
					 | 
				
			||||||
            const v = attr[1];
 | 
					 | 
				
			||||||
            dict[k] = v;
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        return dict;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const new_dict = make_dict(new_attrs);
 | 
					    for (const [k, v] of new_attrs) {
 | 
				
			||||||
    const old_dict = make_dict(old_attrs);
 | 
					        if (v !== old_dict.get(k)) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
    _.each(new_dict, (v, k) => {
 | 
					 | 
				
			||||||
        if (v !== old_dict[k]) {
 | 
					 | 
				
			||||||
            elem.attr(k, v);
 | 
					            elem.attr(k, v);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    _.each(old_dict, (v, k) => {
 | 
					    for (const [k] of old_attrs) {
 | 
				
			||||||
        if (new_dict[k] === undefined) {
 | 
					        if (!new_dict.has(k)) {
 | 
				
			||||||
            elem.removeAttr(k);
 | 
					            elem.removeAttr(k);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
window.vdom = exports;
 | 
					window.vdom = exports;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user