SlideShare a Scribd company logo
1 of 40
Mastering the
Lightning Framework
JF Paradis
Principal Engineer - Salesforce
@jfparadis
Part 2 – The programmatic aspects
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 3: JS Controller and Helper
3.1 MVC in Lightning
3.2 JS Controller
3.3 Events and Methods
3.4 Helper
3.1 MVC in Lightning
Model–View–Controller (MVC) is a software architectural pattern for
implementing user interfaces:
• The model, consists of application data, business rules, logic and functions.
It’s not only a database.
• The view can be any output representation of information, such as a chart or a
diagram.
• The controller, accepts input and converts it to commands for the model or
view.
Overview of MVC
MVC in single page web apps
Browser:
Backbone, Angular
Server:
Nancy, Spring
View
(HTML)
Controller
(JS)
Model
(JS)
View
(REST API)
Controller
(Java)
Model
(SQL)
MVC in Lightning
Browser Server
View
(HTML)
Controller
(JS)
Storage
(JS)
Controller
(Apex)
Model
(SQL)
Model: persistence
• Storage (topic covered in the Apex section)
• Component attributes v.something
View: presentation
• XML component definition
Controller: logic
• JS and Apex Controller
MVC in lightning
3.2 JS Controller
Example set 10:
JS Controller
/c/basics301.app
• JS file named <component>Controller.js
• Auto wired to the component
• Inherited when the component is extended
• Contains one JS object literal
• Members are functions called “actions”
• Actions parameter list is usually a tuple:
• cmp: the context, the current component
• event: if the action was called by an event
• helper: a pointer to a component file use for code
• Actions usually return nothing (undefined)
• No access to this (can’t call an action from an action)
JS Controller
Actions are similar to callbacks
Example set 11:
Anchor onclick vs ui:button press
/c/basics302.app
Actions can receive two types of events
• DOM event
• e.g. anchor onclick
• event.target: the caller
• event.currentTarget: the listener
• need to prevent default to indicate you have handled call
• Lightning event
• e.g. ui:button press of type ui:press
• event.source: the caller, e.g. the button component
• no need to prevent default to indicate you have handled call
• event.getParam(<parameter>)
• e.g. event.getParam("domEvent”) returns the original DOM event inside ui:press
Main purposes of controller action
Used as events handlers:
1. Interaction with a component
• e.g. respond to onclick
2. Change handler
• e.g. respond to a value change
3. Event responder
• e.g. component event, global event
3.3 Events and Methods
Example set 12:
Firing and handling events
/c/basics202.app
Lightning Events
• Declared as a bundle, like a component
• One XML file named <event>.evt
• Can declare attributes
• Two types:
• Application events: global broadcast, don’t use them (no scope)
• Component events: bubble like DOM events
• Caution (2016/06, will change):
• components events don’t bubble inside component body
• they jump to the components that declare the attributes
• If you can’t write a component that will be used as a wrapper to catch
events in another component (as you can do with DOM events).
Component Methods
• Public API for controller actions
• Declared in the component XML
• Can declare attributes
• Point to a controller action
• Parameters passed through the event attribute of the action
3.4 Helper
Helper
• JS file named <component>Helper.js
• Auto wired to the component.
• One instance per level of inheritance.
• Contains one JS object literal.
• Members are JS constants, JS functions, JS shared variables.
• No restrictions on function parameters and return types.
• Helpers are singletons: all components of a given type share the same
instance.
Controller ot Helper?
Controller tasks:
• “callbacks”
• get/set component attributes
• respond to events
• fire events (other components)
Helper tasks:
• code sharing/reuse between controller
actions
• reduce bloat on the controller
• process data
• fire events (server, other components)
• create testable functions
Section 4: Using Apex
4.1 Apex Controller
4.2 Action Service
4.1 Apex Controller
Apex Controller: definition
On the server side:
• Apex Class - Singleton
• Instance methods are “actions” annotated with @AuraEnabled
• Not part of the component bundle
• Return value auto serialized as JSON
On the client side:
• Wired using attribute controller="<class>"
• Accessed with cmp.get("{!c.<action>}")
• Response in action.getReturnValue()
• Return value is a JS object
Apex Controller: example
Example set 13:
Apex Controller
/c/basics401.app
4.2 Action Service
Lightning Action Service
• A framework to invoke client- and server-side logic
• Emphasis on performance
• Multiple actions are multiplexed in a single XHR
• Emphasis on security
• Constraints on target hosts via CSP
• Ensures component can only talk to its controller
• Mobile-centric caching
• Support offline
• Use cached value then async update cache + caller
Action control flow
Foreground
• Default
• Batched
• To reduce number of requests
Background
• Sent individually
• For long server-side execution
Storable
• Result cached
• To reduce repeated calls for the same data
Abortable
• Canceled if same action triggered again
before completion
• To avoid multiple results
Lightning event cycle
Lightning uses a stack to keep track of
the deferred tasks to process. At the end
of a run cycle, all queued actions are
executed.
Fire
Execute
handlers
Queue
actions
Execute
queued
actions
Example set 14:
Action Control Flow
/c/basics402.app
Action State
NEW: The action was created but is not in progress yet
RUNNING: The action is in progress
SUCCESS: The action executed successfully
ERROR: The server returned an error
INCOMPLETE: The server didn't return a response. The server might be down or
the client might be offline.
ABORTED: The action was aborted. You can register a callback for this explicitly.
• For server actions that are idempotent, replayable, and non-mutating
• Time-based expiration (15 min in SFX) auto-refresh (30s in SFX)
• Re-invoke callback only if refreshed value changes
Storable Lightning Actions
Storable Lightning Actions
Fire action
Action
callback
no
Action
callback
yes
Cache hit?
Add to
cache
Action
callback x2
no
yes
no
yes
Refresh?
Update
cache
Different?
Resources: Trailhead
Resources: Lightning section
Resources: Lightning section
thank y u
Mastering the Lightning Framework - Part 2

More Related Content

What's hot

Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java DevelopersYakov Fain
 
Integrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowIntegrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowYakov Fain
 
Lightning Components Workshop
Lightning Components WorkshopLightning Components Workshop
Lightning Components WorkshopGordon Bockus
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life CycleAbhishek Sur
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesMarios Fakiolas
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction TutorialScott Lee
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1Neeraj Mathur
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsSalesforce Developers
 
Winter '19 release development.ppt
Winter '19 release development.pptWinter '19 release development.ppt
Winter '19 release development.pptKailas Shimpi
 
Building a custom Oracle ADF Component
Building a custom Oracle ADF ComponentBuilding a custom Oracle ADF Component
Building a custom Oracle ADF ComponentWilfred van der Deijl
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.netSireesh K
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - IntroductionWebStackAcademy
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
Angular JS, steal the idea
Angular JS, steal the ideaAngular JS, steal the idea
Angular JS, steal the ideaScott Lee
 
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerIntroduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerAgusto Sipahutar
 

What's hot (20)

Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Web controls
Web controlsWeb controls
Web controls
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
 
Integrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowIntegrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business Workflow
 
Lightning Components Workshop
Lightning Components WorkshopLightning Components Workshop
Lightning Components Workshop
 
Angular 5
Angular 5Angular 5
Angular 5
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directives
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction Tutorial
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong Foundations
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
 
Winter '19 release development.ppt
Winter '19 release development.pptWinter '19 release development.ppt
Winter '19 release development.ppt
 
Building a custom Oracle ADF Component
Building a custom Oracle ADF ComponentBuilding a custom Oracle ADF Component
Building a custom Oracle ADF Component
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Angular JS, steal the idea
Angular JS, steal the ideaAngular JS, steal the idea
Angular JS, steal the idea
 
Mule Integration with Dropbox
Mule Integration with DropboxMule Integration with Dropbox
Mule Integration with Dropbox
 
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerIntroduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
 

Similar to Mastering the Lightning Framework - Part 2

Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptLalith86
 
Lightning Components - Down Under Dreaming Sydney
Lightning Components - Down Under Dreaming Sydney Lightning Components - Down Under Dreaming Sydney
Lightning Components - Down Under Dreaming Sydney Techforce Services
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32Bilal Ahmed
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applicationsIvano Malavolta
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoSergii Shymko
 
Component-based Front-End architecture
Component-based Front-End architectureComponent-based Front-End architecture
Component-based Front-End architectureArtyom Trityak
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJSLilia Sfaxi
 
ServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging LabServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging LabJohn Roberts
 
The cornerstones of SAP workflow
The cornerstones of SAP workflowThe cornerstones of SAP workflow
The cornerstones of SAP workflowNorikkon, LLC.
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular jsAndrew Alpert
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor FrameworkDamien Magoni
 
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by Flink
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by FlinkFlink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by Flink
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by FlinkFlink Forward
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with ReduxFITC
 
Using extended events for troubleshooting sql server
Using extended events for troubleshooting sql serverUsing extended events for troubleshooting sql server
Using extended events for troubleshooting sql serverAntonios Chatzipavlis
 
ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017Lucas Jellema
 
Meteor Boulder meetup #1
Meteor Boulder meetup #1Meteor Boulder meetup #1
Meteor Boulder meetup #1Robert Dickert
 

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

Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.ppt
 
Lightning Components - Down Under Dreaming Sydney
Lightning Components - Down Under Dreaming Sydney Lightning Components - Down Under Dreaming Sydney
Lightning Components - Down Under Dreaming Sydney
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applications
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
 
Component-based Front-End architecture
Component-based Front-End architectureComponent-based Front-End architecture
Component-based Front-End architecture
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJS
 
ServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging LabServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging Lab
 
The cornerstones of SAP workflow
The cornerstones of SAP workflowThe cornerstones of SAP workflow
The cornerstones of SAP workflow
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
Event Programming JavaScript
Event Programming JavaScriptEvent Programming JavaScript
Event Programming JavaScript
 
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by Flink
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by FlinkFlink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by Flink
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by Flink
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
 
Android101
Android101Android101
Android101
 
Using extended events for troubleshooting sql server
Using extended events for troubleshooting sql serverUsing extended events for troubleshooting sql server
Using extended events for troubleshooting sql server
 
ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017
 
Meteor Boulder meetup #1
Meteor Boulder meetup #1Meteor Boulder meetup #1
Meteor Boulder meetup #1
 

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
 
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
 
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
 
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
 
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
 

Recently uploaded

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 

Recently uploaded (20)

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 

Mastering the Lightning Framework - Part 2

  • 1. Mastering the Lightning Framework JF Paradis Principal Engineer - Salesforce @jfparadis Part 2 – The programmatic aspects
  • 2. 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
  • 3. Section 3: JS Controller and Helper 3.1 MVC in Lightning 3.2 JS Controller 3.3 Events and Methods 3.4 Helper
  • 4. 3.1 MVC in Lightning
  • 5. Model–View–Controller (MVC) is a software architectural pattern for implementing user interfaces: • The model, consists of application data, business rules, logic and functions. It’s not only a database. • The view can be any output representation of information, such as a chart or a diagram. • The controller, accepts input and converts it to commands for the model or view. Overview of MVC
  • 6. MVC in single page web apps Browser: Backbone, Angular Server: Nancy, Spring View (HTML) Controller (JS) Model (JS) View (REST API) Controller (Java) Model (SQL)
  • 7. MVC in Lightning Browser Server View (HTML) Controller (JS) Storage (JS) Controller (Apex) Model (SQL)
  • 8. Model: persistence • Storage (topic covered in the Apex section) • Component attributes v.something View: presentation • XML component definition Controller: logic • JS and Apex Controller MVC in lightning
  • 10. Example set 10: JS Controller /c/basics301.app
  • 11. • JS file named <component>Controller.js • Auto wired to the component • Inherited when the component is extended • Contains one JS object literal • Members are functions called “actions” • Actions parameter list is usually a tuple: • cmp: the context, the current component • event: if the action was called by an event • helper: a pointer to a component file use for code • Actions usually return nothing (undefined) • No access to this (can’t call an action from an action) JS Controller
  • 12. Actions are similar to callbacks
  • 13. Example set 11: Anchor onclick vs ui:button press /c/basics302.app
  • 14. Actions can receive two types of events • DOM event • e.g. anchor onclick • event.target: the caller • event.currentTarget: the listener • need to prevent default to indicate you have handled call • Lightning event • e.g. ui:button press of type ui:press • event.source: the caller, e.g. the button component • no need to prevent default to indicate you have handled call • event.getParam(<parameter>) • e.g. event.getParam("domEvent”) returns the original DOM event inside ui:press
  • 15. Main purposes of controller action Used as events handlers: 1. Interaction with a component • e.g. respond to onclick 2. Change handler • e.g. respond to a value change 3. Event responder • e.g. component event, global event
  • 16. 3.3 Events and Methods
  • 17. Example set 12: Firing and handling events /c/basics202.app
  • 18. Lightning Events • Declared as a bundle, like a component • One XML file named <event>.evt • Can declare attributes • Two types: • Application events: global broadcast, don’t use them (no scope) • Component events: bubble like DOM events • Caution (2016/06, will change): • components events don’t bubble inside component body • they jump to the components that declare the attributes • If you can’t write a component that will be used as a wrapper to catch events in another component (as you can do with DOM events).
  • 19. Component Methods • Public API for controller actions • Declared in the component XML • Can declare attributes • Point to a controller action • Parameters passed through the event attribute of the action
  • 21. Helper • JS file named <component>Helper.js • Auto wired to the component. • One instance per level of inheritance. • Contains one JS object literal. • Members are JS constants, JS functions, JS shared variables. • No restrictions on function parameters and return types. • Helpers are singletons: all components of a given type share the same instance.
  • 22. Controller ot Helper? Controller tasks: • “callbacks” • get/set component attributes • respond to events • fire events (other components) Helper tasks: • code sharing/reuse between controller actions • reduce bloat on the controller • process data • fire events (server, other components) • create testable functions
  • 23. Section 4: Using Apex 4.1 Apex Controller 4.2 Action Service
  • 25. Apex Controller: definition On the server side: • Apex Class - Singleton • Instance methods are “actions” annotated with @AuraEnabled • Not part of the component bundle • Return value auto serialized as JSON On the client side: • Wired using attribute controller="<class>" • Accessed with cmp.get("{!c.<action>}") • Response in action.getReturnValue() • Return value is a JS object
  • 27. Example set 13: Apex Controller /c/basics401.app
  • 29. Lightning Action Service • A framework to invoke client- and server-side logic • Emphasis on performance • Multiple actions are multiplexed in a single XHR • Emphasis on security • Constraints on target hosts via CSP • Ensures component can only talk to its controller • Mobile-centric caching • Support offline • Use cached value then async update cache + caller
  • 30. Action control flow Foreground • Default • Batched • To reduce number of requests Background • Sent individually • For long server-side execution Storable • Result cached • To reduce repeated calls for the same data Abortable • Canceled if same action triggered again before completion • To avoid multiple results
  • 31. Lightning event cycle Lightning uses a stack to keep track of the deferred tasks to process. At the end of a run cycle, all queued actions are executed. Fire Execute handlers Queue actions Execute queued actions
  • 32. Example set 14: Action Control Flow /c/basics402.app
  • 33. Action State NEW: The action was created but is not in progress yet RUNNING: The action is in progress SUCCESS: The action executed successfully ERROR: The server returned an error INCOMPLETE: The server didn't return a response. The server might be down or the client might be offline. ABORTED: The action was aborted. You can register a callback for this explicitly.
  • 34. • For server actions that are idempotent, replayable, and non-mutating • Time-based expiration (15 min in SFX) auto-refresh (30s in SFX) • Re-invoke callback only if refreshed value changes Storable Lightning Actions
  • 35. Storable Lightning Actions Fire action Action callback no Action callback yes Cache hit? Add to cache Action callback x2 no yes no yes Refresh? Update cache Different?