I have a few components, that can be placed inside different layout sections using Community Builder. But, when I first load the page, I want to get some information from cookies. I can grab cookies data from each component separately, but it would be great to do it once and spread it through all of the components using an application event.
Sadly, when I fire the application event from init handler, other components are not constructed yet and can't capture the event. I've solved this by adding setTimeout(fn, 0), so firing the event will be asynchronous, and it works for me. But is there any other way to wait for the components in the page being constructed?

  • Just Off topic. Out of Curiosity what data are you trying to access via cookie? Its generally discouraged to touch cookies. As they are prone to hijacking, – Pranay Jaiswal Jan 12 '18 at 15:18
  • @PranayJaiswal I save application state, so when I return from a detailed page, I can restore filters etc. – Mr Smith Jan 12 '18 at 15:21
  • 1
    Because of how components are initialized, you're correct that you'll need to setTimeout(...) to wait for all other components to init. – sfdcfox Jan 12 '18 at 15:39

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.