UNPKG

react-application-core

Version:

A react-based application core for the business applications.

110 lines 4.54 kB
"use strict"; var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllIndependentStackSections = exports.toAllIndependentStackSections = exports.findStackSectionsByPredicate = exports.toGraphComponents = exports.getAdditionalStackSectionsToDestroy = exports.collectStackMainSectionsByIndex = void 0; var graphlib = require("@dagrejs/graphlib"); var R = require("ramda"); var util_1 = require("../../util"); /** * @stable [21.09.2019] * @param {IReduxStackEntity} stackEntity * @param {number} startingIndex * @returns {string[]} */ exports.collectStackMainSectionsByIndex = function (stackEntity, startingIndex) { if (startingIndex < 0) { return []; } var additionalSectionsToDestroy = new Set(); stackEntity.stack.forEach(function (entry, index) { if (index >= startingIndex) { additionalSectionsToDestroy.add(entry.section); } }); return Array.from(additionalSectionsToDestroy); }; /** * @stable [21.09.2019] * @param {string} section * @param {IReduxStackEntity} stackEntity * @returns {string[]} */ exports.getAdditionalStackSectionsToDestroy = function (section, stackEntity) { return exports.collectStackMainSectionsByIndex(stackEntity, util_1.findStackItemEntityIndexBySection(section, stackEntity)); }; /** * @stable [20.09.2019] * @param {string} currentSection * @param {IReduxStackEntity} stackEntity * @returns {string[][]} */ exports.toGraphComponents = function (currentSection, stackEntity) { var stack = stackEntity.stack; /** * The cases: * R0 -> R1 -> R2 -> R3 -> R0 * R0 -> R1 -> R2 -> R3 -> R1 */ var currentSectionIndex = util_1.findStackItemEntityIndexBySection(currentSection, stackEntity); var additionalSectionsToPreventToBeLinked = currentSectionIndex > -1 // // R0 -> R1 -> R2 -> R3 -> R1 ==> The links between R1-R2 + R1-R3 will be broken ? exports.collectStackMainSectionsByIndex(stackEntity, currentSectionIndex + 1) : []; var gr = new graphlib.Graph(); stack.forEach(function (entry) { gr.setNode(entry.section); entry.linkedSections.forEach(function (linkedSection) { gr.setNode(linkedSection); // We need to prevent link the destroyable nodes if (R.isEmpty(R.intersection([entry.section, linkedSection], __spreadArrays(stackEntity.destroySections, additionalSectionsToPreventToBeLinked)))) { gr.setEdge(entry.section, linkedSection); } }); }); return graphlib.alg.components(gr); }; /** * @stable [20.09.2019] * @param {string} currentSection * @param {IReduxStackEntity} stackEntity * @param {(linkedSections: string[]) => boolean} predicate * @returns {Set<string>} */ exports.findStackSectionsByPredicate = function (currentSection, stackEntity, predicate) { var resultSections = new Set(); var graphComponents = exports.toGraphComponents(currentSection, stackEntity); graphComponents.forEach(function (graphComponent) { if (predicate(graphComponent)) { graphComponent.forEach(function (entry) { return resultSections.add(entry); }); } }); return resultSections; }; /** * @stable [20.09.2019] * @param {string} currentSection * @param {IReduxStackEntity} stackEntity * @returns {Set<string>} */ exports.toAllIndependentStackSections = function (currentSection, stackEntity) { var result = new Set(); exports.findStackSectionsByPredicate(currentSection, stackEntity, function (subTree) { return !subTree.includes(currentSection); }).forEach(function (itm) { return result.add(itm); }); stackEntity.destroySections.forEach(function (itm) { return result.add(itm); }); return result; }; /** * @stable [20.09.2019] * @param {string} currentSection * @param {IReduxStackEntity} stackEntity * @returns {string[]} */ exports.getAllIndependentStackSections = function (currentSection, stackEntity) { return Array.from(exports.toAllIndependentStackSections(currentSection, stackEntity)); }; //# sourceMappingURL=stack.support.js.map