Comparing version 0.1.2 to 0.1.3
@@ -11,4 +11,4 @@ 'use strict'; | ||
const attribute = (node, name) => { | ||
let oldValue, ownerLess = true; | ||
const attribute = node.ownerDocument.createAttribute(name); | ||
let oldValue, orphan = true; | ||
const attributeNode = document.createAttribute(name); | ||
return newValue => { | ||
@@ -18,12 +18,12 @@ if (oldValue !== newValue) { | ||
if (oldValue == null) { | ||
if (!ownerLess) { | ||
node.removeAttributeNode(attribute); | ||
ownerLess = true; | ||
if (!orphan) { | ||
node.removeAttributeNode(attributeNode); | ||
orphan = true; | ||
} | ||
} | ||
else { | ||
attribute.value = newValue; | ||
if (ownerLess) { | ||
node.setAttributeNode(attribute); | ||
ownerLess = false; | ||
attributeNode.value = newValue; | ||
if (orphan) { | ||
node.setAttributeNode(attributeNode); | ||
orphan = false; | ||
} | ||
@@ -30,0 +30,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var uhtmlHandlers=function(t){"use strict";const{isArray:e}=Array;return t.aria=t=>e=>{for(const r in e)t.setAttribute("role"===r?r:`aria-${r}`,e[r])},t.attribute=(t,e)=>{let r,n=!0;const o=t.ownerDocument.createAttribute(e);return e=>{r!==e&&(r=e,null==r?n||(t.removeAttributeNode(o),n=!0):(o.value=e,n&&(t.setAttributeNode(o),n=!1)))}},t.data=({dataset:t})=>e=>{for(const r in e)t[r]=e[r]},t.event=(t,r)=>{let n,o=r.slice(2);return!(r in t)&&r.toLowerCase()in t&&(o=o.toLowerCase()),r=>{const a=e(r)?r:[r,!1];n!==a[0]&&(n&&t.removeEventListener(o,n,a[1]),(n=a[0])&&t.addEventListener(o,n,a[1]))}},t.ref=t=>e=>{"function"==typeof e?e(t):e.current=t},t.setter=(t,e)=>r=>{t[e]=r},t}({}); | ||
var uhtmlHandlers=function(t){"use strict";const{isArray:e}=Array;return t.aria=t=>e=>{for(const r in e)t.setAttribute("role"===r?r:`aria-${r}`,e[r])},t.attribute=(t,e)=>{let r,n=!0;const o=document.createAttribute(e);return e=>{r!==e&&(r=e,null==r?n||(t.removeAttributeNode(o),n=!0):(o.value=e,n&&(t.setAttributeNode(o),n=!1)))}},t.data=({dataset:t})=>e=>{for(const r in e)t[r]=e[r]},t.event=(t,r)=>{let n,o=r.slice(2);return!(r in t)&&r.toLowerCase()in t&&(o=o.toLowerCase()),r=>{const a=e(r)?r:[r,!1];n!==a[0]&&(n&&t.removeEventListener(o,n,a[1]),(n=a[0])&&t.addEventListener(o,n,a[1]))}},t.ref=t=>e=>{"function"==typeof e?e(t):e.current=t},t.setter=(t,e)=>r=>{t[e]=r},t}({}); |
@@ -9,4 +9,4 @@ import {isArray} from 'uarray'; | ||
export const attribute = (node, name) => { | ||
let oldValue, ownerLess = true; | ||
const attribute = node.ownerDocument.createAttribute(name); | ||
let oldValue, orphan = true; | ||
const attributeNode = document.createAttribute(name); | ||
return newValue => { | ||
@@ -16,12 +16,12 @@ if (oldValue !== newValue) { | ||
if (oldValue == null) { | ||
if (!ownerLess) { | ||
node.removeAttributeNode(attribute); | ||
ownerLess = true; | ||
if (!orphan) { | ||
node.removeAttributeNode(attributeNode); | ||
orphan = true; | ||
} | ||
} | ||
else { | ||
attribute.value = newValue; | ||
if (ownerLess) { | ||
node.setAttributeNode(attribute); | ||
ownerLess = false; | ||
attributeNode.value = newValue; | ||
if (orphan) { | ||
node.setAttributeNode(attributeNode); | ||
orphan = false; | ||
} | ||
@@ -28,0 +28,0 @@ } |
18
index.js
@@ -15,4 +15,4 @@ var uhtmlHandlers = (function (exports) { | ||
var oldValue, | ||
ownerLess = true; | ||
var attribute = node.ownerDocument.createAttribute(name); | ||
orphan = true; | ||
var attributeNode = document.createAttribute(name); | ||
return function (newValue) { | ||
@@ -23,12 +23,12 @@ if (oldValue !== newValue) { | ||
if (oldValue == null) { | ||
if (!ownerLess) { | ||
node.removeAttributeNode(attribute); | ||
ownerLess = true; | ||
if (!orphan) { | ||
node.removeAttributeNode(attributeNode); | ||
orphan = true; | ||
} | ||
} else { | ||
attribute.value = newValue; | ||
attributeNode.value = newValue; | ||
if (ownerLess) { | ||
node.setAttributeNode(attribute); | ||
ownerLess = false; | ||
if (orphan) { | ||
node.setAttributeNode(attributeNode); | ||
orphan = false; | ||
} | ||
@@ -35,0 +35,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var uhtmlHandlers=function(t){"use strict";var i=Array.isArray;return t.aria=function(r){return function(t){for(var n in t)r.setAttribute("role"===n?n:"aria-".concat(n),t[n])}},t.attribute=function(n,t){var r,e=!0,u=n.ownerDocument.createAttribute(t);return function(t){r!==t&&(null==(r=t)?e||(n.removeAttributeNode(u),e=!0):(u.value=t,e&&(n.setAttributeNode(u),e=!1)))}},t.data=function(t){var r=t.dataset;return function(t){for(var n in t)r[n]=t[n]}},t.event=function(r,t){var e,u=t.slice(2);return!(t in r)&&t.toLowerCase()in r&&(u=u.toLowerCase()),function(t){var n=i(t)?t:[t,!1];e!==n[0]&&(e&&r.removeEventListener(u,e,n[1]),(e=n[0])&&r.addEventListener(u,e,n[1]))}},t.ref=function(n){return function(t){"function"==typeof t?t(n):t.current=n}},t.setter=function(n,r){return function(t){n[r]=t}},t}({}); | ||
var uhtmlHandlers=function(t){"use strict";var i=Array.isArray;return t.aria=function(r){return function(t){for(var n in t)r.setAttribute("role"===n?n:"aria-".concat(n),t[n])}},t.attribute=function(n,t){var r,e=!0,u=document.createAttribute(t);return function(t){r!==t&&(null==(r=t)?e||(n.removeAttributeNode(u),e=!0):(u.value=t,e&&(n.setAttributeNode(u),e=!1)))}},t.data=function(t){var r=t.dataset;return function(t){for(var n in t)r[n]=t[n]}},t.event=function(r,t){var e,u=t.slice(2);return!(t in r)&&t.toLowerCase()in r&&(u=u.toLowerCase()),function(t){var n=i(t)?t:[t,!1];e!==n[0]&&(e&&r.removeEventListener(u,e,n[1]),(e=n[0])&&r.addEventListener(u,e,n[1]))}},t.ref=function(n){return function(t){"function"==typeof t?t(n):t.current=n}},t.setter=function(n,r){return function(t){n[r]=t}},t}({}); |
{ | ||
"name": "uhandlers", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "µhtml attributes handlers", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
11550