vdom: Move update_attrs definition before use.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-24 14:56:34 -08:00 committed by Tim Abbott
parent d0e099853c
commit 45178e7fed
1 changed files with 17 additions and 17 deletions

View File

@ -55,6 +55,23 @@ exports.render_tag = (tag) => {
return start_tag + "\n" + innards + "\n" + end_tag;
};
exports.update_attrs = (elem, new_attrs, old_attrs) => {
const new_dict = new Map(new_attrs);
const old_dict = new Map(old_attrs);
for (const [k, v] of new_attrs) {
if (v !== old_dict.get(k)) {
elem.attr(k, v);
}
}
for (const [k] of old_attrs) {
if (!new_dict.has(k)) {
elem.removeAttr(k);
}
}
};
exports.update = (replace_content, find, new_dom, old_dom) => {
/*
The update method allows you to continually
@ -167,21 +184,4 @@ exports.update = (replace_content, find, new_dom, old_dom) => {
exports.update_attrs(find(), new_opts.attrs, old_opts.attrs);
};
exports.update_attrs = (elem, new_attrs, old_attrs) => {
const new_dict = new Map(new_attrs);
const old_dict = new Map(old_attrs);
for (const [k, v] of new_attrs) {
if (v !== old_dict.get(k)) {
elem.attr(k, v);
}
}
for (const [k] of old_attrs) {
if (!new_dict.has(k)) {
elem.removeAttr(k);
}
}
};
window.vdom = exports;