1

My question is more towards design approach than being code specific.

I have a requirement in lightning migration where I need to convert their existing Vf page that comes as inline Vf in account detail compatible with lightning experience as well as salesforce 1 mobile app (android/ios and all devices). So basically the Vf displays list of related custom object records, with each record having edit and delete link associated with it. onclick of edit(link) or add button(shown at bottom of saved records table), renders a section that enables the user to add or edit related record. I have developed a component where I can pass in List of sobject records and list of columns and it renders as expected. Now to initialize values to be passed I can either do it in seperate component can store it in its local aura attribute and can then pass in to its child display records component.

<c:DisplayAccountRecords>
     <aura:attribute name="recordList" type="CustomObj__c[]" />
     <aura:attribute name="columnList" type="String[]" />
     <c:DisplayRecords recordList="{!v.recordList}" columnList="{!columnList}" />
</c:DisplayAccountRecords>

Or I can directly wrap it in aura:application that does the same logic in its controller.

Also, I want the DisplayRecord component to be shown with the horizontal scrollbar as the number of fields are high. For that also I can write custom Ui either in the parent DisplayAccountRecords component or lightning out aura application. Is aura:application Ui, controller,helper,renderer resources are meant to serve these specific use cases only, As basically code writting in aura:application are not reusable.

Thanks

5

In Object Oriented programming languages, the best solution is often to add more classes rather than to add more complexity to the existing classes. And in my experience the same is true for Lightning Components: more components leads to a cleaner design.

Somewhat more formally, it is the Single responsibility principle that is in play. In this case, the aura:application's job would be to adapt your root aura:component to work in a Visualforce page and nothing else. The extra logic you detail would be placed in an extra layer or layers of aura:components.

With this approach, if you wanted to re-use this work via the Lightning App Builder in the future that hosts aura:components directly, less change would be involved as the logic would already be in a root aura:component.

The documentation:

aura:application

An app is a special top-level component whose markup is in a .app resource.

The markup looks similar to HTML and can contain components as well as a set of supported HTML tags. The .app resource is a standalone entry point for the app and enables you to define the overall application layout, style sheets, and global JavaScript includes. It starts with the top-level tag, which contains optional system attributes. These system attributes tell the framework how to configure the app.

implies that you could put your logic in there but by my reading does not particularly encourage that you do.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.