SlideShare a Scribd company logo
1 of 58
Mastering the
Lightning Framework
JF Paradis
Principal Engineer - Salesforce
@jfparadis
Part 1 – The declarative aspects
Overview
In this session you will learn:
What is Lightning, and how it compares with other Single Page Application
frameworks.
What is a component-based architecture, and its relation with OOP.
How the four Lightning base languages (XML, CSS, JavaScript, and Apex) are
used and combined to build components, and applications.
Single Page Application Frameworks
Polymer React Lightning Angular Ember
Lightning follows current best practices:
• Rendering like React
• Bindings like Ember
• Styling like Sass and Bootstrap
We are looking ahead:
• Emerging practices, like Web Components
• Member of TC39, the committee driving the evolution of JavaScript
What we do like the others
Lightning focuses on business needs:
• Access rights
• Secure DOM and Execution Context
• Stable API
• Complete platform
We build an ecosystem:
• App Exchange
• Interoperability with VisualForce
• Leverage current assets
What we do differently
Single Page Application Frameworks
Polymer React
Lightning
Angular EmberAura
• Available at https://github.com/forcedotcom/aura
• Think of Aura in Lightning as Webkit in Safari and Chrome
• Transparency
• Learning tool
• Open to contributions
• Contains features and components not yet exposed in Lightning
Open-Source Framework: Aura
Four languages in one framework
LIGHTNING
XML CSS
ApexJS
Four sections
XML
CSS Apex
JS
Section 1:
XML Component Definition
Section 2:
Styling Components
Section 3:
JS Controller and Helper
Section 4:
Apex Controller
Section 1: XML Component Definition
1.1 Component Based architecture
1.2 Structure of a component
1.3 Key components
1.4 Implementation Detail
1.1 Component-based architecture
Lightning Components
“Components are self-contained and [...] represent a reusable section of the UI,
and can range in granularity from a single line of text to an entire app.”
W3C Web Components
“Web Components [...] define widgets with a level of visual richness and
interactivity not possible with CSS alone, and ease of composition and reuse”
Flash Components
“Components are pre-built controls [...] that you can reuse within your projects.
[...] A component is generally a user interface widget, like a button, a checkbox,
or a menu bar.”
Component-based Frameworks
Polymorphism: process objects using a parent type or a parent class.
Inheritance: extend a behavior of a superclass.
Interfaces: define a contract.
Composition: contain instances of other classes.
Encapsulation: hide the data and the implementation.
Separation of concerns: deal with related sets of information.
Generalization: extract shared characteristics into superclass.
Specialization: derive subclass with specific behavior.
Modularity: write according to functionality and responsibility.
Similarities: Component-based vs Object Oriented
Object-oriented
Write according to a mental model of the actual or imagined objects it represents,
for example a user, a record, etc.
Component-based
Glue together other prefabricated components - much like in the fields of
electronics or mechanics.
Differences: Component-based vs Object Oriented
Inheritance vs Composition
Inheritance defines “is a” Composition defines “has a”
Formula 1
Ferrari
Car
Turbo Engine
Racing Tires
Frame
Cockpit
Ferrari
1.2 Structure of a component
Example set 1:
Lightning vs HTML
/c/basics101.app
Lightning vs Web Components
/c/basics102.app
• A bundle is a folder containing the resources
owned by the component: XML, JS, CSS, etc.
• The name of the folder is the component name.
• There is always one XML file per bundle, with the
same name as the bundle.
• The file extension defines the type of bundle:
• .cmp = component
• .app = application
• .intf = interface
• .evt = event
Component bundles
Example of a component XML
• Define the base type (enclosing tag):
• <aura:component>, <aura:application>, <aura:interface>, <aura:event>
• Set attributes values:
• implements = "<name>" (no default)
• abstract = "<true|false>" (defaults to false, can’t create an instance if true)
• extensible = "<true|false>" (defaults to false)
• Declare definitions
• <aura:attribute name="<name>”/> (declare an attribute)
• Important:
• <aura:set> (not a declaration, alternative syntax to set an attribute)
• Used primarily to set facets (arrays of components)
• <aura:set attribute="body”> (not required, implied)
Inside the component XML
Example of attribute declaration
Example set 2:
Passing attributes
/c/buttonTest.app?label=Ok
/c/meterTest.app?value=0.5
• Attributes are used to pass values into a component.
• The declaration:
• must have a name and a type,
• can set a default value, can specify required.
• The attributes are reusable declaratively inside the component.
• The reference follows the v.<name> syntax.
• Attributes member can also be referenced:
• Object members: v.<name>.<member>
• Array members: v.<name>.<index> or v.<name>[<index>]
• All attributes are shared with subclasses except body.
Component Attributes
Children populate the body attribute of their parent
Children populate the body attribute of their parent
<i>Text</i>
<p>
<i>Text</i>
</p>
<h1>Title</h1>
<p>
<i>Text</i>
</p>
Example set 3:
Simple Parent & Simple Child
/c/basics103.app
Ignored Child
/c/basics104.app
• It is declared by default on all components.
• Set to everything between opening and closing tag
• It’s of a special type Aura.component[] called “facet”.
• Equivalent to node properties innerHTML and children.
• There is one body instance for each level of inheritance.
• The body has a peculiar mode of inheritance:
• The child sets the body attribute of its parent,
• The parent can output its v.body inside its own body, it can also ignore it.
• Consequences:
• No child can override the parent body.
• Top parent ultimately decides what a component will render.
The body attribute
• Two types: property reference or function.
• Expression functions look like JavaScript but they work differently.
• They use a subset of the JavaScript functions.
• Those functions have logic to handle in null and undefined:
• null + "abc" = "nullabc" in JavaScript, but "abc" in Lightning.
• undefined + null = NaN in JavaScript, but "" in Lightning.
Expressions
Expressions: examples
• Attribute value passing (like passing a value to a JavaScript function):
• <ui:button label="{#v.whom}"/>
• Attribute reference passing (special Lightning mode):
• <ui:button label="{!v.whom}"/>
• Calculation:
• <div style="{!'width:' + (v.value * 100) + '%'}"/>
• Conditional Expression:
• <div class="{!v.isHidden ? 'hidden' : 'default'}"/>
Expressions: usage
1.3 Key Components
HTML components
• HTML components are instances of <aura:html>.
• Can be created using <aura:html tag="<tag>”> if an expression is
required.
• The majority of HTML5 tags are alowed.
• We don’t support unsafe or unnecessary tags:
• No <applet>, <object>, <font>, etc.
• HTML components are not extensible, neither is <aura:html>.
Example set 4:
Using <aura:if>
/c/basics106.app
Using <aura:renderIf>
/c/basics107.app
Conditionals
• There are two: <aura:if> and <aura:renderIf>:
• conditional: attribute “isTrue”,
• consequent: attribute “body”,
• alternative (optional): attribute “else”.
• Why two?
• <aura:renderIf> is the naive implementation,
• equivalent to using a function expression {! v.isTrue ? v.body : v.else },
• needs both facets created before the function is evaluated,
• don’t use <aura:renderIf>, it creates more components.
• Difference: <aura:if> creates and renders only the consequent or the
alternative, <aura:renderIf> creates both consequences, renders one.
Example set 5:
Using <aura:iteration>
/c/basics108.app
Loops
• One component <aura:iteration>.
• Uses the body as a template to create multiple instances.
• Iterates over an array attribute named items.
• Each item is placed into a customizable attribute called var.
• The loop index is specified using indexVar.
• Attributes start and end can be used to control which items are rendered.
1.4 Implementation Details
• From XML to DOM
• Lightning is not a template engine.
• Counting component instances
• Lightning is optimized for composition
• Inheritance is as expensive as composition
• Components created ≠ rendered:
• Best illustrated with <aura:if> and <aura:renderIf>
What’s under the hood?
Lightning isn’t a JS template engine (mustache, handlebars, etc.) which parses
the template file to replaces variables:
Template → HTML → DOM
Lightning create components:
• The server creates Java Objects from component XML,
• Components are serialized to JSON,
• The client creates JS Component instances,
• The JS Components create DOM elements:
XML → Java → JSON → JS → DOM
From XML to DOM
One instance per child and per parent
<aura:component>
<div><div><div><div>
</...</...</...</...
</aura:component>
<aura:application>
<meter>60%</...
<c:meter>60%</...
<c:meter>60%</...
</aura:application>
= 2 components (current + base parent)
= 4 components (simple HTML)
Total: 6
= 2 components
= 2 components (simple HTML + text)
= 7 components (6 above + text)
= 7 components
Total: 18
How to count components instances
In the browser console:
$A.componentService.countComponents()
With a bookmarklet:
javascript:alert("Components: "+$A.componentService.countComponents())
Example set 6:
Counting components
/c/basics105.app
Section 2: Styling Components
2.1 CSS in components
2.2 Limits of encapsulation
3.3 Using OOCSS
2.1 CSS in Components
Example set 7:
CSS in components
/c/basics201.app
• What you do:
• create a file named <component>.css
• placed in the component bundle
• all rules start with .THIS
• What Lightning does:
• wire the file to the cmp
• convert .THIS to .<namespace><Component> pseudo CSS class
• add <namespace><Component> to top element(s)
• creates any vendor-specific extension.
• CSS rules are scoped to a component since namespace:component is
unique.
CSS in components
2.2 Limits of Encapsulation
Example set 8:
Limits of CSS encapsulation
/c/basics202.app
• styling crosses component boundaries
• no true encapsulation, unlike virtual DOM from Web Components
• no CSS file means .THIS not added*
• parent can’t style using generated class name
• multiple top elements means multiple .THIS added
• CSS rules might not apply to every element
• removing top element might change rules
• .THIS tag becomes tag.THIS
• better to style other components by assigning them classes (API)
• no attribute class by default on custom components
• implement it yourself
Limits of CSS encapsulation
2.3 Using OOCSS
• Limit of component CSS:
• it creates a lot of repetition
• styles changes mean manually updating every component
• Limitation of “skinning”:
• overriding styles means more CSS
• breaks encapsulation
• unstable
• Limitations of CSS variables:
• styles are usually related
• a change in one style might produce unpredictable results
• e.g. text color and background color, padding
Before OOCSS?
Using a redline
• Object Oriented CSS
• technique to write CSS
• creates related CSS classes each one containing relates styles
• e.g. Bootstrap, jQuery UI, Foundation, Semantic UI
• Benefits:
• creates reusable CSS, reduces CSS bloat and improves consistency
• improves predictability
• creates an abstraction layer, an API
• e.g. components use the OOCSS classes as a styling vocabulary
• maintains functionality and presentation as orthogonal concerns
What is OOCSS?
Our OOCSS
• Documentation
• https://developer.salesforce.com/lightning/design-system
• How to use it:
• Install the package
• Add a declaration
• <ltng:require styles="/resource/SLDS105/assets/styles/salesforce-
lightning-design-system.css"/>
• Start writing your components
• Open-source
• https://github.com/salesforce-ux/design-system
Salesforce Lightning Design System
Examples set 9:
Using SLDS
/c/basics203.app
thank y u
Mastering the Lightning Framework - Part 1

More Related Content

What's hot

Oracle EBS R12 Self service user manual
Oracle EBS R12 Self service user manualOracle EBS R12 Self service user manual
Oracle EBS R12 Self service user manualFeras Ahmad
 
SAP Integration: Best Practices | MuleSoft
SAP Integration: Best Practices | MuleSoftSAP Integration: Best Practices | MuleSoft
SAP Integration: Best Practices | MuleSoftMuleSoft
 
Salesforce development lifecycle
Salesforce development lifecycleSalesforce development lifecycle
Salesforce development lifecyclegiridhar007
 
Oracle Cloud Integrations Overview
Oracle Cloud Integrations OverviewOracle Cloud Integrations Overview
Oracle Cloud Integrations OverviewAbdelrahman Saied
 
Salesforce Streaming Api
Salesforce Streaming ApiSalesforce Streaming Api
Salesforce Streaming ApiJayant Jindal
 
Salesforce Admin 201-certification Notes
Salesforce Admin 201-certification NotesSalesforce Admin 201-certification Notes
Salesforce Admin 201-certification NotesAslam Tayyab
 
Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15
Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15
Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15Paris Salesforce Developer Group
 
Salesforce Integration Patterns
Salesforce Integration PatternsSalesforce Integration Patterns
Salesforce Integration Patternsusolutions
 
Salesforce complete overview
Salesforce complete overviewSalesforce complete overview
Salesforce complete overviewNitesh Mishra ☁
 
Mule salesforce integration solutions
Mule  salesforce integration solutionsMule  salesforce integration solutions
Mule salesforce integration solutionshimajareddys
 
01 oracle application integration overview
01 oracle application integration overview01 oracle application integration overview
01 oracle application integration overviewnksolanki
 
Salesforce Lightning Process builder
Salesforce Lightning Process builderSalesforce Lightning Process builder
Salesforce Lightning Process builderThinqloud
 
Oracle ame complete setup
Oracle ame complete setupOracle ame complete setup
Oracle ame complete setuprahul chowdary
 
Platform Events by Tim Taylor
Platform Events by Tim TaylorPlatform Events by Tim Taylor
Platform Events by Tim TaylorChristine Smith
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionSalesforce Developers
 
ABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.infoABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.infosapdocs. info
 
Salesforce CI/CD - A strategy for success
Salesforce CI/CD - A strategy for successSalesforce CI/CD - A strategy for success
Salesforce CI/CD - A strategy for successYassine ELQANDILI ☁
 
Canvas Apps for the Model-driven mind
Canvas Apps for the Model-driven mindCanvas Apps for the Model-driven mind
Canvas Apps for the Model-driven mindJukka Niiranen
 
Salesforce Sharing Architecture
Salesforce Sharing ArchitectureSalesforce Sharing Architecture
Salesforce Sharing Architecturegemziebeth
 

What's hot (20)

Oracle EBS R12 Self service user manual
Oracle EBS R12 Self service user manualOracle EBS R12 Self service user manual
Oracle EBS R12 Self service user manual
 
SAP Integration: Best Practices | MuleSoft
SAP Integration: Best Practices | MuleSoftSAP Integration: Best Practices | MuleSoft
SAP Integration: Best Practices | MuleSoft
 
Salesforce development lifecycle
Salesforce development lifecycleSalesforce development lifecycle
Salesforce development lifecycle
 
Oracle Cloud Integrations Overview
Oracle Cloud Integrations OverviewOracle Cloud Integrations Overview
Oracle Cloud Integrations Overview
 
SAP Fiori ppt
SAP Fiori pptSAP Fiori ppt
SAP Fiori ppt
 
Salesforce Streaming Api
Salesforce Streaming ApiSalesforce Streaming Api
Salesforce Streaming Api
 
Salesforce Admin 201-certification Notes
Salesforce Admin 201-certification NotesSalesforce Admin 201-certification Notes
Salesforce Admin 201-certification Notes
 
Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15
Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15
Introducing salesforce shield - Paris Salesforce Developer Group - Oct 15
 
Salesforce Integration Patterns
Salesforce Integration PatternsSalesforce Integration Patterns
Salesforce Integration Patterns
 
Salesforce complete overview
Salesforce complete overviewSalesforce complete overview
Salesforce complete overview
 
Mule salesforce integration solutions
Mule  salesforce integration solutionsMule  salesforce integration solutions
Mule salesforce integration solutions
 
01 oracle application integration overview
01 oracle application integration overview01 oracle application integration overview
01 oracle application integration overview
 
Salesforce Lightning Process builder
Salesforce Lightning Process builderSalesforce Lightning Process builder
Salesforce Lightning Process builder
 
Oracle ame complete setup
Oracle ame complete setupOracle ame complete setup
Oracle ame complete setup
 
Platform Events by Tim Taylor
Platform Events by Tim TaylorPlatform Events by Tim Taylor
Platform Events by Tim Taylor
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
 
ABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.infoABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.info
 
Salesforce CI/CD - A strategy for success
Salesforce CI/CD - A strategy for successSalesforce CI/CD - A strategy for success
Salesforce CI/CD - A strategy for success
 
Canvas Apps for the Model-driven mind
Canvas Apps for the Model-driven mindCanvas Apps for the Model-driven mind
Canvas Apps for the Model-driven mind
 
Salesforce Sharing Architecture
Salesforce Sharing ArchitectureSalesforce Sharing Architecture
Salesforce Sharing Architecture
 

Similar to Mastering the Lightning Framework - Part 1

Lightning web components
Lightning web components Lightning web components
Lightning web components Cloud Analogy
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.jsIvano Malavolta
 
Lightning web components - Introduction, component Lifecycle, Events, decorat...
Lightning web components - Introduction, component Lifecycle, Events, decorat...Lightning web components - Introduction, component Lifecycle, Events, decorat...
Lightning web components - Introduction, component Lifecycle, Events, decorat...Nidhi Sharma
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JSIvano Malavolta
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningSyed Irtaza Ali
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDmitry Vinnik
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfSreeVani74
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperFabrit Global
 
Salesforce Lightning Web Components Overview
Salesforce Lightning Web Components OverviewSalesforce Lightning Web Components Overview
Salesforce Lightning Web Components OverviewNagarjuna Kaipu
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipseanshunjain
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answersKrishnaov
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Aura Framework Overview
Aura Framework OverviewAura Framework Overview
Aura Framework Overviewrajdeep
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptxsyedabbas594247
 
Web Components v1
Web Components v1Web Components v1
Web Components v1Mike Wilcox
 

Similar to Mastering the Lightning Framework - Part 1 (20)

Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
 
Lightning web components
Lightning web components Lightning web components
Lightning web components
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
 
Lightning web components - Introduction, component Lifecycle, Events, decorat...
Lightning web components - Introduction, component Lifecycle, Events, decorat...Lightning web components - Introduction, component Lifecycle, Events, decorat...
Lightning web components - Introduction, component Lifecycle, Events, decorat...
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
 
Salesforce Lightning Web Components Overview
Salesforce Lightning Web Components OverviewSalesforce Lightning Web Components Overview
Salesforce Lightning Web Components Overview
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Aura Framework Overview
Aura Framework OverviewAura Framework Overview
Aura Framework Overview
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Aem best practices
Aem best practicesAem best practices
Aem best practices
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Java script
Java scriptJava script
Java script
 

More from Salesforce Developers

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSalesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceSalesforce Developers
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base ComponentsSalesforce Developers
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsSalesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaSalesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentSalesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsSalesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsSalesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsSalesforce Developers
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and TestingSalesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilitySalesforce Developers
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce dataSalesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPSalesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceSalesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureSalesforce Developers
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DXSalesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectSalesforce Developers
 

More from Salesforce Developers (20)

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component Performance
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base Components
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer Highlights
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX India
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local Development
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web Components
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer Highlights
 
Live coding with LWC
Live coding with LWCLive coding with LWC
Live coding with LWC
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and Testing
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura Interoperability
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce data
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCP
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in Salesforce
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data Capture
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DX
 
Get Into Lightning Flow Development
Get Into Lightning Flow DevelopmentGet Into Lightning Flow Development
Get Into Lightning Flow Development
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS Connect
 
Introduction to MuleSoft
Introduction to MuleSoftIntroduction to MuleSoft
Introduction to MuleSoft
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

Mastering the Lightning Framework - Part 1

  • 1. Mastering the Lightning Framework JF Paradis Principal Engineer - Salesforce @jfparadis Part 1 – The declarative aspects
  • 2. Overview In this session you will learn: What is Lightning, and how it compares with other Single Page Application frameworks. What is a component-based architecture, and its relation with OOP. How the four Lightning base languages (XML, CSS, JavaScript, and Apex) are used and combined to build components, and applications.
  • 3. Single Page Application Frameworks Polymer React Lightning Angular Ember
  • 4. Lightning follows current best practices: • Rendering like React • Bindings like Ember • Styling like Sass and Bootstrap We are looking ahead: • Emerging practices, like Web Components • Member of TC39, the committee driving the evolution of JavaScript What we do like the others
  • 5. Lightning focuses on business needs: • Access rights • Secure DOM and Execution Context • Stable API • Complete platform We build an ecosystem: • App Exchange • Interoperability with VisualForce • Leverage current assets What we do differently
  • 6. Single Page Application Frameworks Polymer React Lightning Angular EmberAura
  • 7. • Available at https://github.com/forcedotcom/aura • Think of Aura in Lightning as Webkit in Safari and Chrome • Transparency • Learning tool • Open to contributions • Contains features and components not yet exposed in Lightning Open-Source Framework: Aura
  • 8. Four languages in one framework LIGHTNING XML CSS ApexJS
  • 9. Four sections XML CSS Apex JS Section 1: XML Component Definition Section 2: Styling Components Section 3: JS Controller and Helper Section 4: Apex Controller
  • 10. Section 1: XML Component Definition 1.1 Component Based architecture 1.2 Structure of a component 1.3 Key components 1.4 Implementation Detail
  • 12. Lightning Components “Components are self-contained and [...] represent a reusable section of the UI, and can range in granularity from a single line of text to an entire app.” W3C Web Components “Web Components [...] define widgets with a level of visual richness and interactivity not possible with CSS alone, and ease of composition and reuse” Flash Components “Components are pre-built controls [...] that you can reuse within your projects. [...] A component is generally a user interface widget, like a button, a checkbox, or a menu bar.” Component-based Frameworks
  • 13. Polymorphism: process objects using a parent type or a parent class. Inheritance: extend a behavior of a superclass. Interfaces: define a contract. Composition: contain instances of other classes. Encapsulation: hide the data and the implementation. Separation of concerns: deal with related sets of information. Generalization: extract shared characteristics into superclass. Specialization: derive subclass with specific behavior. Modularity: write according to functionality and responsibility. Similarities: Component-based vs Object Oriented
  • 14. Object-oriented Write according to a mental model of the actual or imagined objects it represents, for example a user, a record, etc. Component-based Glue together other prefabricated components - much like in the fields of electronics or mechanics. Differences: Component-based vs Object Oriented
  • 15. Inheritance vs Composition Inheritance defines “is a” Composition defines “has a” Formula 1 Ferrari Car Turbo Engine Racing Tires Frame Cockpit Ferrari
  • 16. 1.2 Structure of a component
  • 17. Example set 1: Lightning vs HTML /c/basics101.app Lightning vs Web Components /c/basics102.app
  • 18. • A bundle is a folder containing the resources owned by the component: XML, JS, CSS, etc. • The name of the folder is the component name. • There is always one XML file per bundle, with the same name as the bundle. • The file extension defines the type of bundle: • .cmp = component • .app = application • .intf = interface • .evt = event Component bundles
  • 19. Example of a component XML
  • 20. • Define the base type (enclosing tag): • <aura:component>, <aura:application>, <aura:interface>, <aura:event> • Set attributes values: • implements = "<name>" (no default) • abstract = "<true|false>" (defaults to false, can’t create an instance if true) • extensible = "<true|false>" (defaults to false) • Declare definitions • <aura:attribute name="<name>”/> (declare an attribute) • Important: • <aura:set> (not a declaration, alternative syntax to set an attribute) • Used primarily to set facets (arrays of components) • <aura:set attribute="body”> (not required, implied) Inside the component XML
  • 21. Example of attribute declaration
  • 22. Example set 2: Passing attributes /c/buttonTest.app?label=Ok /c/meterTest.app?value=0.5
  • 23. • Attributes are used to pass values into a component. • The declaration: • must have a name and a type, • can set a default value, can specify required. • The attributes are reusable declaratively inside the component. • The reference follows the v.<name> syntax. • Attributes member can also be referenced: • Object members: v.<name>.<member> • Array members: v.<name>.<index> or v.<name>[<index>] • All attributes are shared with subclasses except body. Component Attributes
  • 24. Children populate the body attribute of their parent
  • 25. Children populate the body attribute of their parent <i>Text</i> <p> <i>Text</i> </p> <h1>Title</h1> <p> <i>Text</i> </p>
  • 26. Example set 3: Simple Parent & Simple Child /c/basics103.app Ignored Child /c/basics104.app
  • 27. • It is declared by default on all components. • Set to everything between opening and closing tag • It’s of a special type Aura.component[] called “facet”. • Equivalent to node properties innerHTML and children. • There is one body instance for each level of inheritance. • The body has a peculiar mode of inheritance: • The child sets the body attribute of its parent, • The parent can output its v.body inside its own body, it can also ignore it. • Consequences: • No child can override the parent body. • Top parent ultimately decides what a component will render. The body attribute
  • 28. • Two types: property reference or function. • Expression functions look like JavaScript but they work differently. • They use a subset of the JavaScript functions. • Those functions have logic to handle in null and undefined: • null + "abc" = "nullabc" in JavaScript, but "abc" in Lightning. • undefined + null = NaN in JavaScript, but "" in Lightning. Expressions
  • 30. • Attribute value passing (like passing a value to a JavaScript function): • <ui:button label="{#v.whom}"/> • Attribute reference passing (special Lightning mode): • <ui:button label="{!v.whom}"/> • Calculation: • <div style="{!'width:' + (v.value * 100) + '%'}"/> • Conditional Expression: • <div class="{!v.isHidden ? 'hidden' : 'default'}"/> Expressions: usage
  • 32. HTML components • HTML components are instances of <aura:html>. • Can be created using <aura:html tag="<tag>”> if an expression is required. • The majority of HTML5 tags are alowed. • We don’t support unsafe or unnecessary tags: • No <applet>, <object>, <font>, etc. • HTML components are not extensible, neither is <aura:html>.
  • 33. Example set 4: Using <aura:if> /c/basics106.app Using <aura:renderIf> /c/basics107.app
  • 34. Conditionals • There are two: <aura:if> and <aura:renderIf>: • conditional: attribute “isTrue”, • consequent: attribute “body”, • alternative (optional): attribute “else”. • Why two? • <aura:renderIf> is the naive implementation, • equivalent to using a function expression {! v.isTrue ? v.body : v.else }, • needs both facets created before the function is evaluated, • don’t use <aura:renderIf>, it creates more components. • Difference: <aura:if> creates and renders only the consequent or the alternative, <aura:renderIf> creates both consequences, renders one.
  • 35. Example set 5: Using <aura:iteration> /c/basics108.app
  • 36. Loops • One component <aura:iteration>. • Uses the body as a template to create multiple instances. • Iterates over an array attribute named items. • Each item is placed into a customizable attribute called var. • The loop index is specified using indexVar. • Attributes start and end can be used to control which items are rendered.
  • 38. • From XML to DOM • Lightning is not a template engine. • Counting component instances • Lightning is optimized for composition • Inheritance is as expensive as composition • Components created ≠ rendered: • Best illustrated with <aura:if> and <aura:renderIf> What’s under the hood?
  • 39. Lightning isn’t a JS template engine (mustache, handlebars, etc.) which parses the template file to replaces variables: Template → HTML → DOM Lightning create components: • The server creates Java Objects from component XML, • Components are serialized to JSON, • The client creates JS Component instances, • The JS Components create DOM elements: XML → Java → JSON → JS → DOM From XML to DOM
  • 40. One instance per child and per parent <aura:component> <div><div><div><div> </...</...</...</... </aura:component> <aura:application> <meter>60%</... <c:meter>60%</... <c:meter>60%</... </aura:application> = 2 components (current + base parent) = 4 components (simple HTML) Total: 6 = 2 components = 2 components (simple HTML + text) = 7 components (6 above + text) = 7 components Total: 18
  • 41. How to count components instances In the browser console: $A.componentService.countComponents() With a bookmarklet: javascript:alert("Components: "+$A.componentService.countComponents())
  • 42. Example set 6: Counting components /c/basics105.app
  • 43. Section 2: Styling Components 2.1 CSS in components 2.2 Limits of encapsulation 3.3 Using OOCSS
  • 44. 2.1 CSS in Components
  • 45. Example set 7: CSS in components /c/basics201.app
  • 46. • What you do: • create a file named <component>.css • placed in the component bundle • all rules start with .THIS • What Lightning does: • wire the file to the cmp • convert .THIS to .<namespace><Component> pseudo CSS class • add <namespace><Component> to top element(s) • creates any vendor-specific extension. • CSS rules are scoped to a component since namespace:component is unique. CSS in components
  • 47. 2.2 Limits of Encapsulation
  • 48. Example set 8: Limits of CSS encapsulation /c/basics202.app
  • 49. • styling crosses component boundaries • no true encapsulation, unlike virtual DOM from Web Components • no CSS file means .THIS not added* • parent can’t style using generated class name • multiple top elements means multiple .THIS added • CSS rules might not apply to every element • removing top element might change rules • .THIS tag becomes tag.THIS • better to style other components by assigning them classes (API) • no attribute class by default on custom components • implement it yourself Limits of CSS encapsulation
  • 51. • Limit of component CSS: • it creates a lot of repetition • styles changes mean manually updating every component • Limitation of “skinning”: • overriding styles means more CSS • breaks encapsulation • unstable • Limitations of CSS variables: • styles are usually related • a change in one style might produce unpredictable results • e.g. text color and background color, padding Before OOCSS?
  • 53. • Object Oriented CSS • technique to write CSS • creates related CSS classes each one containing relates styles • e.g. Bootstrap, jQuery UI, Foundation, Semantic UI • Benefits: • creates reusable CSS, reduces CSS bloat and improves consistency • improves predictability • creates an abstraction layer, an API • e.g. components use the OOCSS classes as a styling vocabulary • maintains functionality and presentation as orthogonal concerns What is OOCSS?
  • 55. • Documentation • https://developer.salesforce.com/lightning/design-system • How to use it: • Install the package • Add a declaration • <ltng:require styles="/resource/SLDS105/assets/styles/salesforce- lightning-design-system.css"/> • Start writing your components • Open-source • https://github.com/salesforce-ux/design-system Salesforce Lightning Design System
  • 56. Examples set 9: Using SLDS /c/basics203.app