wrapping-letters-react
Version:
SIMPLIFY THE JOB OF WRAPPING LETTERS IN HTML TAGS WITH WRAPPING-LETTERS
69 lines (52 loc) • 3.56 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.memo__process = memo__process;
var _whatIsIt = require("../common/whatIsIt");
function memo__process(prevV, nextV) {
const TEXT_OPTIONS_PREV = prevV.textOptions;
const TEXT_OPTIONS_NEXT = nextV.textOptions;
let conditions = [prevV.text === nextV.text]; // here the code will check if textOptiosn is undefiend in prev and next
// if both is undefiend the code will only will return the result of text
if (TEXT_OPTIONS_PREV === TEXT_OPTIONS_NEXT) return conditions[0];
const PERWORD_PREV = TEXT_OPTIONS_PREV.PerWord;
const PERWORD_NEXT = TEXT_OPTIONS_NEXT.PerWord;
function __basic_comprobation__(prevValue, nextValue) {
if ((0, _whatIsIt.whatItIs)(prevValue) != (0, _whatIsIt.whatItIs)(nextValue)) {
conditions.push(false);
} else if (Array.isArray(prevValue) && Array.isArray(nextValue)) {
// I can optimize the code a lot but for now it's enough
prevValue.forEach((element, index) => {
if ((0, _whatIsIt.whatItIs)(element) === "[object Object]" && (0, _whatIsIt.whatItIs)(nextValue[index]) === "[object Object]") {
if (element.structureToAdd != nextValue[index].structureToAdd) conditions.push(false);
} else if (Array.isArray(element) && Array.isArray(nextValue[index])) {
if (element.some((el, i) => el != nextValue[index][i])) conditions.push(false);
} else if (element != nextValue[index]) conditions.push(false);
});
} else if ((0, _whatIsIt.whatItIs)(prevValue) === "[object String]" && (0, _whatIsIt.whatItIs)(nextValue) === "[object String]") {
!conditions.push(prevValue != nextValue);
}
} // here the code will check ClassToAdd
if (TEXT_OPTIONS_PREV.ClassToAdd != TEXT_OPTIONS_NEXT.ClassToAdd) conditions.push(false); // here the code will check if SpecialWrapp changed
// firts check is wordToSearch
if (TEXT_OPTIONS_PREV.SelectClass || TEXT_OPTIONS_NEXT.SelectClass) {
__basic_comprobation__(TEXT_OPTIONS_PREV.SelectClass.wordToSearch, TEXT_OPTIONS_NEXT.SelectClass.wordToSearch); // second to check is classToAdd
__basic_comprobation__(TEXT_OPTIONS_PREV.SelectClass.classToAdd, TEXT_OPTIONS_NEXT.SelectClass.classToAdd); // SPW comprobation
if (TEXT_OPTIONS_PREV.SelectClass.spaceBetweenWord != TEXT_OPTIONS_NEXT.SelectClass.spaceBetweenWord) conditions.push(false);
}
if (TEXT_OPTIONS_PREV.SpecialWrapp || TEXT_OPTIONS_NEXT.SpecialWrapp) {
// here the code will check if SpecialWrapp changed
__basic_comprobation__(TEXT_OPTIONS_PREV.SpecialWrapp.wordToSearch, TEXT_OPTIONS_NEXT.SpecialWrapp.wordToSearch);
__basic_comprobation__(TEXT_OPTIONS_PREV.SpecialWrapp.structureToAdd, TEXT_OPTIONS_NEXT.SpecialWrapp.structureToAdd);
} // perWord comprobation
if (PERWORD_NEXT != PERWORD_PREV) conditions.push(false); // Here the code will comprobate if structure has been changed
const prevStruc = prevV.structure;
const nextStruc = nextV.structure;
if ((0, _whatIsIt.whatItIs)(prevStruc) != (0, _whatIsIt.whatItIs)(nextStruc)) conditions.push(false);else if ((0, _whatIsIt.whatItIs)(prevStruc) === "[object Object]" && (0, _whatIsIt.whatItIs)(nextStruc) === "[object Object]") {
if (prevStruc.structure != nextStruc.structure) conditions.push(false);
} else if ((0, _whatIsIt.whatItIs)(prevStruc) === "[object Function]" && (0, _whatIsIt.whatItIs)(nextStruc) === "[object Function]") {
if (prevStruc != nextStruc) conditions.push(false);
}
return conditions.every(el => el === true);
}
;