Magento v2.4.0
I have two js files. Let’s call them fileA and fileB. I need fileA to load before fileB in order to trigger a call.
fileA:
define([ 'jquery', 'underscore', 'ko', 'uiComponent' ], function ($, _, ko, Component) { return Component.extend({ initialize: function() { $(document).on('customEvent', function () { // do stuff } }, // knockout stuff }); });
fileB:
define([ 'jquery', 'Magento_Theme/js/fileA' ], function ($) { $.widget('mage.test', $.mage.test, { _init: function () { $(document).trigger('customEvent'); } }); });
fileA is a knockout file with html template. I need it to load before fileB loads because fileB will fire the event trigger which will prompt fileA to fetch the data and upate the array var. How do you tell fileB that it needs fileA to be loaded before it runs? I’ve tried a domReady on fileB, a require([‘fileA’]) before the init call on fileB, and a shim but none of them worked. Any input is appreciated. Thank you!
submitted by /u/thawkins
[link] [comments]