0

I'm developing 2 forms with knockout js and html template. This 2 forms templates need to be separated, however they share data in common, for example, coverages amounts (this templates are about insurances).

So I have my structure like this:

templates
 -portability.html
 -conversion.html
js
 -quote.js

The problem is that I feel that mixing methods of this 2 separated products in a single js file like quote.js will be a mess, because there will be methods applying just for portability.html and other methods applying just for conversion.html.

My idea:

Separate this methods in 2 different js, like portability.js and conversion.js

My problem:

I don't see how to send data from portability.js to conversion.js and vice versa.

This is how my phtml will look like when I get this 2 different js files communicated:

 <div id="custom-component" data-bind="scope:'customcomponent'">
        <!-- ko template: getTemplate() --><!-- /ko -->
        <script type="text/x-magento-init">
        {
            "#custom-component": {
                "Magento_Ui/js/core/app": {
                   "components": {
                        "customcomponent": {
                            "component": "Vendor_GetQuote/js/portability",
                            "basic_amount": "<?= /* @escapeNotVerified */ $ee_basic_amount_original ?>",
                            "supp_amount": "<?= /* @escapeNotVerified */ $ee_supp_amount_original ?>",
                        }
                    }
                }
            }
        }
        </script>
        </div>

<div id="custom-component" data-bind="scope:'customcomponent'">
    <!-- ko template: getTemplate() --><!-- /ko -->
    <script type="text/x-magento-init">
    {
        "#custom-component2": {
            "Magento_Ui/js/core/app": {
               "components": {
                    "customcomponent2": {
                        "component2": "Vendor_GetQuote/js/conversion",
                        "basic_amount": "<?= /* @escapeNotVerified */ $ee_basic_amount_original ?>",
                        "supp_amount": "<?= /* @escapeNotVerified */ $ee_supp_amount_original ?>",
                    }
                }
            }
        }
    }
    </script>
    </div>

Greetings!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.