Lightning Standards
Lightning Standards
Contents ii
1 Introduction 1
2 Components 2
2.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Styling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Design File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Controllers 5
3.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Renderers 6
5 Event Handling 7
5.1 Application Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5.2 Component Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5.3 Special Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
ii
Chapter 1
Introduction [Intro.Scope]
(1)
The language in this document follows the ISO Directive standards as such:
1
Chapter 2
Components [Components]
(2)
1 A developer shall not use inline EMCAScript (JavaScript) for event handlers on elements.
Inline ECMAScript is not guaranteed to work properly as very few things are in the global
scope in lightning. Instead a developer should instead call the component’s Controller methods
to handle the events.
2 A developer shall not use the following elements:
• center
• b use <strong> instead if you need to indicate heavy emphasis that is non-stylistic
• i use <em> instead if you need to emphasize text that is non-stylistic
• strike use <del> instead if you need to indicate text is removed text that is non-stylistic
• listing use <pre> or <code> instead if you need to display pre-formatted content or code,
ensure that & and < are escaped as & and < respectively
• big if the content is a heading use the appropriate heading element otherwise use CSS
• spacer
• multicol
• hgroup
• tt
2
8 A developer should favor using unbound expressions ({#v.foo}) versus bound expressions ({!v.foo})
when binding variables to components.
Unbound expressions when used correctly dramatically reduce the overhead in a component
and speed up how fast a user can interact with it. Bound expressions require the framework to
check if the value has changed and propagate that change. This is expensive and is one of the
primary performance hits in lightning.
9 A developer shall implement force:hasRecordId if a component’s functionality focuses on a
single record.
The force:hasRecordId provides several key benefits to a developer:
• flexipage:availableForAllPageTypes
• flexipage:availableForRecordHome
• forceCommunity:availableForAllPageTypes
shall have a design file.
2 Every public or global attribute on a component should have a corresponding entry in the
component’s design file.
3 Every component implementing force:hasRecordId shall have an sfdc:Objects enumeration
in the design file with a sfdc:object entry for the sObjects the component is valid to be used
with.
Chapter 3
Controllers [Controllers]
(3)
1 A developer shall not modify the DOM in the controller
If a developer needs to modify the DOM they should put the logic to do so in the appropriate
renderer method. Modifying the DOM from a controller can have unpredictable results.
2 A developer shall put business logic in the Helper, not the controller.
A controller is designed to handle events and should be focused on event handling. Mixing
in business logic results in business logic being preformed inconsistently. Rather the controller
should delegate to the helper which can ensure that business logic is always applied correctly.
5
Chapter 4
Renderers [Renderers]
(4)
1 A developer shall not fire an event from any renderer method.
Firing events from a component’s renderer can trigger an infinite rendering loop.
2 A developer shall only manipulate the DOM from a renderer.
A component’s renderer is the only place where DOM elements can be manipulated without
causing odd behavior in the application.
3 A developer should avoid assigning to document.location.href.
4 A developer should avoid using <unescapedHTML>, v.body, or innerHTML.
All of these methods can allow for Cross Site Scripting, and should be avoided. Instead prefer
using attributes and innerText.
5 A developer shall escape string attributes if they are not rendered via Lightning.
6
6
Chapter 5
7
1 A developer shall not call stopPropagation() on the Init event.
The init event is special in the sense that it is called during the initialization process. Calling
stopPropagation() during this time disrupts initialization.