You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
|
2 years ago
|
const CAPS_REGEX = /[A-Z]/g;
|
||
|
|
function updateDataset(oldVnode, vnode) {
|
||
|
|
const elm = vnode.elm;
|
||
|
|
let oldDataset = oldVnode.data.dataset;
|
||
|
|
let dataset = vnode.data.dataset;
|
||
|
|
let key;
|
||
|
|
if (!oldDataset && !dataset)
|
||
|
|
return;
|
||
|
|
if (oldDataset === dataset)
|
||
|
|
return;
|
||
|
|
oldDataset = oldDataset || {};
|
||
|
|
dataset = dataset || {};
|
||
|
|
const d = elm.dataset;
|
||
|
|
for (key in oldDataset) {
|
||
|
|
if (!dataset[key]) {
|
||
|
|
if (d) {
|
||
|
|
if (key in d) {
|
||
|
|
delete d[key];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
elm.removeAttribute("data-" + key.replace(CAPS_REGEX, "-$&").toLowerCase());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for (key in dataset) {
|
||
|
|
if (oldDataset[key] !== dataset[key]) {
|
||
|
|
if (d) {
|
||
|
|
d[key] = dataset[key];
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
elm.setAttribute("data-" + key.replace(CAPS_REGEX, "-$&").toLowerCase(), dataset[key]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
export const datasetModule = {
|
||
|
|
create: updateDataset,
|
||
|
|
update: updateDataset,
|
||
|
|
};
|
||
|
|
//# sourceMappingURL=dataset.js.map
|