5

Reading the latest Lightning Components Developer Guide I couldn't find out where and where not to use access=GLOBAL in Lightning Components that I want to package in a managed app. I'm confused about the following questions:

  1. I know that <aura:component>s that should show up in the App Builder need to be GLOBAL. What about the internal sub-components that are used by them?
  2. What about the <aura:attribute>s? Do only need those to be GLOBAL that are exposed to the App Builder via a .design file?
  3. When can I make <aura:attribute> access=private?
6

Let's consider the following base scenario to answer your questions:

  • you plan to use a contrib:parentComp component.
  • contrib:parentComp has a child component contrib:childComp.
  • contrib:childComp has 3 attributes globalAttr, publicAttr and privateAttr with the 'hinted' access levels.
  • the contrib namespace does not belong to your org.
  • your org has your own myns customized namespace (it could also be the default c namespace as long as it differs from contrib).

Back to your questions, here are the answers:

  1. Only the parentComp component needs to be global if your want to use it in the myns namespace.

    • If childComp is public you cannot directly call it as a standalone in your myns code but parentComp will still work as expected.
    • If childComp is global you could call it directly in your myns code without using parentComp.
  2. The same rule applies to aura:attribute. Let's consider for this answer that childComp is global.

    • If you use it in myns code, you can only access globalAttr.
    • If you use it in contrib code (in the org where the component was implemented) then, you can access globalAttr and publicAttr when declaring an instance of the component.
  3. private attributes are used to hold internal component state that will not be shared with a parent component regardless of the namespace.

I hope that this clarifies the use of the different access levels.

3

The Developer's Blog on How to Design, Build and Publish Your Lightning Component for AppExchange states the following:

Development best practice is to specify access attributes manually from the start. If you are planning to contribute an application or component, remember to always use “global” access to expose functionalities.

For point number 1, as a best practice, always set component level access to GLOBAL if you wish to expose them.

For point 2, if you plan on making the attributes accessible through the .design file, you will need to set access to GLOBAL.

For point 3, It is recommended to set them to private if you don't plan on making them accessible by other components outside of the attribute’s namespace.

As mentioned in Attribute Access control and in Modularizing Code in Lightning Components

Both articles are worth reading.

Generally speaking:

  • Global: Any component can access the value of this attribute.
  • Public: Only components in the same namespace can set the value of this attribute.
  • Private: Only this component can set the value of this attribute.
  • I could accept this as answer if you add a solution to 1) 2) and 3) and point to resources. – Robert Sösemann Jun 1 '17 at 9:29
  • 2
    @glls I disagree with Point 1. Only add access="global" to component which are going to be exposed to subscribers. – Praveen Jun 1 '17 at 10:31
  • 1
    point 1 is in context of the documentation," need to be global if you wish to expose them". I should specify it to avoid confusion. Thanks @Praveen for pointing that out – glls Jun 1 '17 at 10:35

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.