Skip to content

Commit

Permalink
Exposes concat method (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Nov 26, 2019
1 parent 6ec6c02 commit b7f3fcc
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/xml/xpath/concat.js
Original file line number Diff line number Diff line change
@@ -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 = [];
}
});

0 comments on commit b7f3fcc

Please sign in to comment.