diff --git a/src/xml/xpath/concat.js b/src/xml/xpath/concat.js index 085416b4..53bb90e2 100644 --- a/src/xml/xpath/concat.js +++ b/src/xml/xpath/concat.js @@ -1,39 +1,45 @@ /** - * @file XML XPath Concat object + * @file XML XPath Concat operator * @since 1.0.1 */ /*#ifndef(UMD)*/ "use strict"; -/*global _gpfErrorDeclare*/ // Declare new gpf.Error names -/*global _gpfIgnore*/ /*global _gpfDefine*/ /*global _gpfXmlXPathBase*/ -/*exported _gpfXmlXPathConcat*/ +/*exported _gpfXmlXpathConcatNodes*/ // Returns a list of unique nodes +/*exported _gpfXmlXPathConcat*/ // gpf.xml.xpath.Concat /*#endif*/ +/** + * Concat the node lists to ensure the result contain only unique nodes + * @param {gpf.interfaces.IXmlNodeSyncAdapter[]} currentNodes List of nodes to concatenate with + * @param {gpf.interfaces.IXmlNodeSyncAdapter[]} newNodes List of nodes to add in the currentNodes list + * @return {gpf.interfaces.IXmlNodeSyncAdapter[]} List of unique nodes + */ +function _gpfXmlXpathConcatNodes (currentNodes, newNodes) { + return currentNodes.concat(newNodes.filter(function (node) { + return !curretNodes.includes(node); + })); +} + +/** + * Implementation of the | operator + * + * @class gpf.xml.xpath.Concat + * @extend gpf.xml.xpath.Base + * @since 1.0.1 + */ var _gpfXmlXPathConcat = _gpfDefine({ $class: "gpf.xml.xpath.Concat", - $extend: _gpfXmlXPathBase, - - _xpath: [], + $extend: _GpfXmlXPathBase, /** * @inheritdoc * @since 1.0.1 */ - select: function (contextNode, namespaces) { - return this._xpath.reduce(function (nodes, xpath) { - nodes = nodes.concat(xpath.evaluate(contextNode, namespaces)); + execute: function (contextNode, namespaces) { + return this._children.reduce(function (nodes, xpath) { + return _gpfXmlXpathConcatNodes(nodes, xpath.execute(contextNode, namespaces)); }, []); - }, - - /** - * Implementation of the | operator - * - * @class gpf.xml.xpath.Concat - * @since 1.0.1 - */ - constructor: function () { - this._xpath = []; } });