mirror of https://github.com/zulip/zulip.git
vdom: Move update_attrs definition before use.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
d0e099853c
commit
45178e7fed
|
@ -55,6 +55,23 @@ exports.render_tag = (tag) => {
|
||||||
return start_tag + "\n" + innards + "\n" + end_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) => {
|
exports.update = (replace_content, find, new_dom, old_dom) => {
|
||||||
/*
|
/*
|
||||||
The update method allows you to continually
|
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(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;
|
window.vdom = exports;
|
||||||
|
|
Loading…
Reference in New Issue