From ee2dfa3b0a9516b52ae8d2d4c888f9190b828baa Mon Sep 17 00:00:00 2001 From: Andreas Svensson Date: Wed, 16 May 2018 10:51:13 +0200 Subject: [PATCH] Add xlinkHref property to SurgicalElement Add updateElementAttributeNS Bump version to 0.5.3 --- npm-build/surgical/package.json | 2 +- packages/surgical/SurgicalElement.js | 3 +++ packages/surgical/core/updateElementAttributeNS.js | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 packages/surgical/core/updateElementAttributeNS.js diff --git a/npm-build/surgical/package.json b/npm-build/surgical/package.json index abe837c..ef86882 100644 --- a/npm-build/surgical/package.json +++ b/npm-build/surgical/package.json @@ -1,6 +1,6 @@ { "name": "surgical", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "description": "Surgical is a declarative JavaScript library with native DOM flexibility and performance, for building fast UIs.", "author": "Andreas Svensson ", diff --git a/packages/surgical/SurgicalElement.js b/packages/surgical/SurgicalElement.js index d4bb7d8..6aea0d6 100644 --- a/packages/surgical/SurgicalElement.js +++ b/packages/surgical/SurgicalElement.js @@ -1,5 +1,6 @@ import SurgicalBaseElement from './SurgicalBaseElement'; import updateElementAttribute from './core/updateElementAttribute'; +import updateElementAttributeNS from './core/updateElementAttributeNS'; import updateElementAttributes from './core/updateElementAttributes'; import updateElementProxyEventListeners from './core/updateElementProxyEventListeners'; import updateStyleProperties from './core/updateStyleProperties'; @@ -14,6 +15,7 @@ export default class SurgicalElement extends SurgicalBaseElement { this.nodeStyle = node.style; updateElementAttribute(node, 'class', props.className, null); + updateElementAttributeNS(node, 'http://www.w3.org/1999/xlink', 'xlink:href', props.xlinkHref, null); updateElementAttributes(node, props.attributes, null); updateStyleProperties(this.nodeStyle, props.style, null); this.eventListenersInstance = updateElementProxyEventListeners(node, null, props.listeners, null); @@ -30,6 +32,7 @@ export default class SurgicalElement extends SurgicalBaseElement { //} updateElementAttribute(node, 'class', nextProps.className, lastProps.className); + updateElementAttributeNS(node, 'http://www.w3.org/1999/xlink', 'xlink:href', nextProps.xlinkHref, lastProps.xlinkHref); updateElementAttributes(node, nextProps.attributes, lastProps.attributes); updateStyleProperties(this.nodeStyle, nextProps.style, lastProps.style); this.eventListenersInstance = updateElementProxyEventListeners(node, this.eventListenersInstance, nextProps.listeners, lastProps.listeners); diff --git a/packages/surgical/core/updateElementAttributeNS.js b/packages/surgical/core/updateElementAttributeNS.js new file mode 100644 index 0000000..cfdb0fd --- /dev/null +++ b/packages/surgical/core/updateElementAttributeNS.js @@ -0,0 +1,9 @@ +export default function updateElementAttributeNS(node, namespaceURI, name, nextValue, lastValue) { + if (nextValue !== lastValue) { + if (nextValue != null && nextValue !== false) { + node.setAttributeNS(namespaceURI, name, (nextValue === true ? '' : nextValue)); + } else if (lastValue != null && lastValue !== false) { + node.removeAttributeNS(namespaceURI, name); + } + } +}