Размер выражения превышает максимальный в Google AMP State - PullRequest
1 голос
/ 04 августа 2020

Мне нужно рассчитать диапазон затрат на разлив различных этикеток. Я обновляю состояние Google AMP при каждом нажатии радиокнопки в соответствии с вариантом использования.

// data from mockapi
const costData = [
    {
        "label": "Treatment 1",
        "cost": "20,000 - 30,000"
    },
    {
        "label": "Treatment 2",
        "cost": "10,000 - 20,000"
    },
    {
        "label": "Treatment 3",
        "cost": "10,000 - 20,000"
    },
    .....
    .....
    .....
]


// component
const TreatmentLabels = (props) => {
    const costArr = cost.cost.split("-");
    const lowCost = parseInt(costArr[0].replace(",", "").trim());
    const highCost = parseInt(costArr[1].replace(",", "").trim());

    return costData.map((costObj) => {
        <span on={`tap:AMP.setState(
                { totalEstimatedCostRange: {
                  low: totalEstimatedCostRange.low == undefined
                        ? (selectedChoice.subtype == 'type_1'
                            ? 79000
                            : selectedChoice.subtype == 'type_2'
                              ? 96000
                              : 126000
                            ) + totalEstimatedCostRange.low + ${lowCost}
                        : labelWithSelect == '${cost.label}'
                          ? totalEstimatedCostRange.low - ${lowCost}
                          : totalEstimatedCostRange.low + ${lowCost},
                  high: totalEstimatedCostRange.high == undefined
                        ? (selectedChoice.subtype == 'type_1'
                            ? 115000
                            : selectedChoice.subtype == 'type_2'
                              ? 140000
                              : 190000
                            ) + totalEstimatedCostRange.high + ${highCost}
                        : labelWithSelect == '${cost.label}'
                          ? totalEstimatedCostRange.high - ${highCost}
                          : totalEstimatedCostRange.high + ${highCost},
                },
                labelWithSelect: labelWithSelect['${cost.label}'] == undefined ? true : !labelWithSelect['${cost.label}']
              })
              }`>
            {costObj.label}
        </span>

        <p>
            ₹{" "}
            <span data-amp-bind-text="totalEstimatedCostRange.low == undefined
                                      ? selectedChoice.subtype == 'type_1'
                                          ? 79000 
                                          : selectedChoice.subtype == 'type_2'
                                              ? 96000
                                              : 126000
                                      : totalEstimatedCostRange.low"></span>
            -{" "}
             <span data-amp-bind-text="totalEstimatedCostRange.high == undefined
                                       ? selectedChoice.subtype == 'type_1'
                                           ? 115000
                                           : selectedChoice.subtype == 'type_2'
                                               ? 140000
                                               : 190000
                                       : totalEstimatedCostRange.high"></span>
        </p>
    });
}

Но при нажатии на ярлык консоль показывает ошибку превышения размера выражения

введите описание изображения здесь

Я здесь что-то не так делаю, или как исправить эту ошибку. Любая помощь будет принята с благодарностью, поскольку я пытаюсь решить эту проблему с последних 2 дней.

Заранее спасибо

...