UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

169 lines (123 loc) 6.29 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The source code</title> <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="../resources/prettify/prettify.js"></script> <style type="text/css"> .highlight { display: block; background-color: #ddd; } </style> <script type="text/javascript"> function highlight() { document.getElementById(location.hash.replace(/#/, "")).className = "highlight"; } </script> </head> <body onload="prettyPrint(); highlight();"> <pre class="prettyprint lang-js">/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ Class(&#39;Ariadne.QueryFinder.Edge&#39;, { does : Siesta.Util.Role.HasUniqueGeneratedId, has : { finder : { required : true }, maze : { required : true }, fromNode : { required : true }, toNode : { required : true }, // Array of { variant : segments, hash : hash, indicies : Object } segmentVariants : Joose.I.Array, segmentVariantsHashes : Joose.I.Object, isDirectChild : false, weight : Infinity }, methods : { register : function () { var fromNode = this.fromNode var toNode = this.toNode if (fromNode.edgesToByIndex[ toNode.index ]) throw new Error(&quot;Edge already exists&quot;) if (toNode.edgesFromByIndex[ fromNode.index ]) throw new Error(&quot;Edge already exists&quot;) fromNode.edgesToByIndex[ toNode.index ] = this toNode.edgesFromByIndex[ fromNode.index ] = this }, consumeVariant : function (segments, segmentsCombInfo) { // TUNE // FOUNDEDGECOUNTER = window.FOUNDEDGECOUNTER || 0 // FOUNDEDGECOUNTER++ if (arguments.length == 1) { segmentsCombInfo = this.finder.combineSegments(segments) } var weight = segmentsCombInfo.weight var hash = segmentsCombInfo.hash if (this.weight &gt; weight) { // if (this.weight &lt; Infinity) console.log(&quot;REDEFINED: &quot; + this.segmentVariants.length) this.weight = weight this.segmentVariants = [] this.segmentVariantsHashes = {} } // if (this.segmentVariantsHashes[ hash ]) { // console.log(&quot;REPEATED&quot;) // } if (this.weight == weight &amp;&amp; !this.segmentVariantsHashes[ hash ]) { // TUNE // console.log(&quot;Found edge from: &quot; + this. fromNode.index + &quot;[&quot; + this.fromNode.el.tagName + &quot;] to &quot; + this.toNode.index + &quot;[&quot; + this.toNode.el.tagName + &quot;] query: &quot; + segmentsCombInfo.query) // TUNE // FOUNDEDGECOUNTER = window.FOUNDEDGECOUNTER || 0 // FOUNDEDGECOUNTER++ var indicies = {} // should collect all indicies (in the &quot;combineSegments&quot;?) indicies[ segments[ 0 ].index ] = true this.segmentVariantsHashes[ hash ] = true this.segmentVariants.push({ variant : segments, hash : hash, indicies : indicies }) // indicates that something has changed return true } }, relax : function () { var fromNode = this.fromNode var toNode = this.toNode if (fromNode.isReachedWithDirectChildEdge()) { var index = fromNode.index var segmentVariants = this.segmentVariants var hasVariantWithOwnSegments = false for (var i = 0; i &lt; segmentVariants.length; i++) { if (segmentVariants[ i ].indicies[ index ]) { hasVariantWithOwnSegments = true break } } if (!hasVariantWithOwnSegments) return false } var possibleWeight = this.weight + fromNode.weightOptions[ 0 ].weight var existingWeightOption = toNode.weightOptionsByWeight[ possibleWeight ] if (existingWeightOption &amp;&amp; !existingWeightOption.minFromEdgesById[ this.id ]) { existingWeightOption.minFromEdgesById[ this.id ] = this return true } if (!existingWeightOption) { var minFromEdgesById = {} minFromEdgesById[ this.id ] = this var weightOption = { weight : possibleWeight, minFromEdgesById : minFromEdgesById } toNode.weightOptionsByWeight[ possibleWeight ] = weightOption var weightOptions = toNode.weightOptions for (var i = 0; i &lt; weightOptions.length; i++) { if (possibleWeight &lt; weightOptions[ i ].weight) { weightOptions.splice(i, 0, weightOption) return true } } weightOptions.push(weightOption) return true } } } }); </pre> </body> </html>