4

Lightning components enforces a relatively strict encapsulation of the individual components which makes it difficult to build more complex applications while still aiming for modularity.

In my specific scenario I'm having interdepencies between multiple components on a page but even across pages a certain context (huge set of values) needs to be available to all components at all times. The more I follow the encapsulation the more I'm dependent on event-based inter-component communication and many events cause negative performance impacts.

The next idea was to use a Community Custom Theme component as the root component that persists the application context across all pages. At first glance this seemed brilliant as the Theme component is shared and even if the user navigates from page to page the values are persisted.

That left the challenge of how to propagate the application context to the individual child components. And here the LockerService enters the stage as it does not allow access to the components dragged into the custom theme from the client-side controller of the root component. So again it would be necessary to work with lots of events (component events to let the root component know they're rendered and application event to propagate the context). In the end it seems to be the easiest approach to wrap all components and all application pages with a single component using aura:if or some other logic to render what's needed. But that again would mean to completely abandon the design principle of modular, independent components as it would basically end in one monster component representing a SPA within the Lightning Components SPA.

So I'm wondering if there's an elegant way to build modular components while still being able to have deep interdependencies and a cross application context? Or maybe the question should be: how can I build complex web applications in Lightning Components without Angular features like Services and Dependency Injection?

1 Answer 1

1

Conceptually I would try if the usage of Local Storage is feasible.

As far as I know it is available even in the context of LockerService as well as from the theme-side.

Using it might give you the benefit of an enhanced persistence of data even if you come back in a new session.

Honestly I never coded it, but having your situation in mind, I would try this in your place and do some experiments.

Considerations

  • Not sure about Security Review if this might be important for you
  • Massive data in the storage might be vulnerable and I would encrypt it
  • There are browser limits. 50 MB in Chrome as fas as I remenber

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .