Upload
lieven-juwet
View
483
Download
0
Embed Size (px)
Citation preview
Dreamforce 2016 - #SFLightningChess
Lightning ChessThe fun way of learning the Lightning Component Framework
Lieven Juwet@LievenJuwet
Technical Architect @ ABSI
Samuel De Rycke@SamuelDeRycke
Technical Architect @ ABSISalesforce MVP
Forward-Looking StatementsStatement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Agenda
● Demo● Lightning Component Framework● Component Encapsulation● Lightning Chess: Component Composition● Event Driven Architecture● Lightning Chess: Event Driven approach● Let’s code it● Q&A
Lightning Chess
● R&D project● Effort: 40 hours + rework● Chess application on the Salesforce Platform● Real-time multiplayer game● Built using Lightning Component framework
Lightning what?!
Application Architecture
Streaming API
Custom Objects
Apex Controllers
Lightning Chess Player ClientsLightning Chess
Player Clients
Serv
er C
all
Subs
crib
e
Upda
tes
Salesforce Platform
Demo: Lightning Chess
Lightning Component Framework
● Lightning Application
● Lightning Components
● Lightning Events
The Fundamentals
Lightning Component Component Bundle
Component Bundle
Component< markup />
StyleCSS
RendererJavascript
ControllerJavascript
HelperJavascript
Design< markup />
Documentation
< markup />SVG File
Component Encapsulation
● Object Oriented Programming principles● Internals are not exposed to the outside● Public vs Private interface
What happens in the component, stays in the component
Component Public:● Public
Attributes● Public
Methods● Events
Private:● HTML DOM● CSS Style● Private Attributes● Controller Functions● Helper Functions● Apex Controller
Component Encapsulation
● Easy to reuseUse them in different applications or other components making use of a component’s
public interface● Open for extension
Extend the functionality of a component without impacting other components.● Independent
A component does not rely on its consumers but on its public interface to function. This makes it easy to use a component in any system.
● CompactSplitting up your application/component into smaller components each with their
own function will lead to code that is small and easy to maintain.
Component can be:
“Think Component Encapsulation“
Lightning Chess: Component Architecture Divide and conquer
Streaming API Listener
General Game ComponentChessboardChessboard Location
Streaming API Listener
Player List
Challenge List
Streaming API Listener
Streaming API Listener
Streaming API Listener
Subscribe to streaming API and forward streaming event messages
Lightning Chess: Streaming API Listener
<aura:component> <!-- public interface --> <aura:attribute name=”listeners” type=”String[]” access=”public”/> <aura:registerEvent name=”StreamingEvent” type=”c:StreamingEvent” />
<!-- private interface --> <ltng:require scripts="<!--Required scripts -->" afterScriptsLoaded="{!c.setupStreaming}" />
<aura:attribute name="sessionId" type="String" access="private"/> <aura:handler name="destroy" value="{!this}" action="{!c.closeConnections}"/>
</aura:component>
Lightning Chess: Component Architecture Mistakes were madeChessboard
Chessboard Location
Streaming API Listener
Player List
Challenge List
Streaming API Listener
Streaming API Listener
Chessboard has too much responsibility. What if we want to extend and allow users to choose what game they want to play?
“Single Responsibility“
Lightning Chess: Component Architecture Divide and conquer
Streaming API Listener
General Game ComponentChessboardChessboard Location
Streaming API Listener
Player List
Challenge List
Streaming API Listener
Streaming API Listener
Streaming API Listener
“Single Responsibility“
Event Driven Architecture Event types
Component Event Application EventSend only to components in the parent hierarchy above
Broadcast to the entire Lighting Application.
Tighter coupling between sender and receivers
Very loose coupling between sender and receivers
<aura:event type=”Component” description=”Chessboard_Location_Select”>
<aura:attribute name=”location” type=”Object” />
</aura:event>
Event Driven Architecture
● Part of the public interface● “Something happened, I don’t know what to do, so do whatever you like!”
Loosely coupled communication
<aura:component description=”Chessboard_Location”> <!-- Chessboard Location Component Definition--> <aura:registerEvent name=”select” type=”c:Chessboard_Location_Select” /></aura:component>
<aura:component description=”Chessboard”> <!-- Chessboard has a Chessboard Location component--> <c:Chessboard_Location select=”{!c.handleLocationSelect}” /></aura:component>
Lightning Chess: Event Driven Approach Communication is key
Chessboard
Chessboard Location
Streaming API Listener
Chess Logic Server Call
I am selected as a starting location
I am selected as a target location
Locations x,y please mark yourself as targetable
I received a new move with following details
Following piece moved from x to y
Click
Click
“Loose communication through Events“
Let’s Code!Extend the Chessboard Location component by adding Drag-and-Drop support
Summary Takeaways
“Think Component Encapsulation“
“Single Responsibility“
“Loose communication through Events“
Resources
Code @ Github!http://bit.ly/LightningChess-CodeRead more about Lightning Chess Architecture:http://bit.ly/LightningChess-Blog
Questions?Reach us on twitter #SFLightningChess
Thank Y u