all aboard the lightning components action service

32
All Aboard The Lightning Components Action Service Peter Chittum Developer Evangelist @pchittum github.com/pchittum

Upload: peter-chittum

Post on 16-Apr-2017

292 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: All Aboard the Lightning Components Action Service

All Aboard The Lightning Components Action Service

 Peter Chittum  Developer Evangelist  @pchittum  github.com/pchittum  

Page 2: All Aboard the Lightning Components Action Service

Safe Harbor Safe harbor statement 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.

Page 3: All Aboard the Lightning Components Action Service

Peter Chittum Developer Evangelist @pchittum github.com/pchittum

Speaker

Page 4: All Aboard the Lightning Components Action Service

Agenda

▪  Brief Overview of Components ▪  Action Service Basics ▪  Beyond the Basics ▪  A Miscellany of Things

Page 5: All Aboard the Lightning Components Action Service

App Cloud and Lightning

Connect Process Builder

App Builder

Component Framework

Page 6: All Aboard the Lightning Components Action Service

Introducing Lightning Components  Reusable UI components for any device

Connect Process Builder

App Builder

Component Framework

Page 7: All Aboard the Lightning Components Action Service

Component Artifacts

Design Principles

•  Structured Bundle of Resources

•  Client-side Rendered

•  Extensible, Reusable, Atomic, Event-Driven

•  Apex as backend

•  First Class UI Citizen APP or COMPONENT BUNDLE

Definition: markup

Style: css

Helper : js

Documentation

Controller: js

Renderer: js

Design Markup Icon: SVG

Page 8: All Aboard the Lightning Components Action Service

Component Client Side Rendering

JSON

component:{...}

<div>...</div>

Page 9: All Aboard the Lightning Components Action Service

Component State

Attribute

Page 10: All Aboard the Lightning Components Action Service

Component-to-Component Communication

Event

Page 11: All Aboard the Lightning Components Action Service

Component-to-Server Communication

Action

Page 12: All Aboard the Lightning Components Action Service

Agenda

▪  Brief Overview of Components ▪  Action Service Basics ▪  Beyond the Basics ▪  A Miscellany of Things

Page 13: All Aboard the Lightning Components Action Service

Actions: Interact with the Server

•  Apex Method Surfaced to Lightning Components •  @AuraEnabled annotation

Page 14: All Aboard the Lightning Components Action Service

Many Components Many Server Trips

XMLHttpRequest

XMLHttpRequest

XMLHttpRequest

Page 15: All Aboard the Lightning Components Action Service

Many Components Many Actions: Boxcarring

Action S

ervice

Page 16: All Aboard the Lightning Components Action Service

Demo

Page 17: All Aboard the Lightning Components Action Service

Agenda

▪  Brief Overview of Components ▪  Action Service Basics ▪  Beyond the Basics ▪  A Miscellany of Things

Page 18: All Aboard the Lightning Components Action Service

Defer High Volume Actions

Action S

ervice

•  Defer High-Volume Actions •  Action.setCaboose()

Page 19: All Aboard the Lightning Components Action Service

Insert tracking record

Caboose action measures on

setInterval

Device Orientation

Stop tracking Update record Clear handlers

Component render

wobble__c measurement__c

Demo

Page 20: All Aboard the Lightning Components Action Service

Parent Child Display Optimization

1

2

Page 21: All Aboard the Lightning Components Action Service

Actions: Chained

callback enqueueAction(child)

Page 22: All Aboard the Lightning Components Action Service

Demo

Page 23: All Aboard the Lightning Components Action Service

Agenda

▪  Brief Overview of Components ▪  Action Service Basics ▪  Beyond the Basics ▪  A Miscellany of Things

Page 24: All Aboard the Lightning Components Action Service

Useful Tools and Lessons

•  Javascript

•  Callbacks and isValid

•  Closures

•  Unsupported Events

•  Only on init

•  Component Lifecycle

Page 25: All Aboard the Lightning Components Action Service

Learn Javascript

James Governor, RedMonk

Page 26: All Aboard the Lightning Components Action Service

Javascript is Async

 console.log('this will go first’);  setTimeout(function(){'this happens third'},1);  console.log('this happens second');

 // output:  'this will go first'  'this happens second'  'this happens third'

 1  2  3  4  5  6  7  8

Page 27: All Aboard the Lightning Components Action Service

Check Component Validity: isValid()  myhandler : function(component, event, helper){   ...   var action = component.get('c.myApexMethod');   ...   action.setCallback(this, function(serverResponse){   ...   component.set('v.myAttrib',serverResponse.getReturnValue());   });   $A.enqueueAction(action);

 1  2  3  4  5  6  7  8  9

 action.setCallback(this, (function(serverResponse){   ... if (component.isValid()) {

  component.set('v.myAttrib',serverResponse.getReturnValue());   } else {   ...exit gracefully   }  });

 1  2  3  4  5  6  7  8  9

Page 28: All Aboard the Lightning Components Action Service

Closures for Reusability

 //in MyComponentHelper.js  callbackFactory : function(component){   return function (serverResponse){   component.set('v.myAttribute', serverResponse.getReturnValue());     }  }

 1  2  3  4  5  6  7

 doInit: function(component, event, helper){   component.myCallbackFunction = helper.callbackFactory(component);  });

 1  2  3

 //while setting up action do this...  action.setCallback(this, helper.myCallbackFunction);

 1  2

Page 29: All Aboard the Lightning Components Action Service

Clean Up After Yourself in Unrender

 unrender: function(component, helper){     window.removeEventListener('deviceorientation',component.doOrientation);

 }

 1  2  3  4  5  6  7  8  9

Page 30: All Aboard the Lightning Components Action Service

Go Play and Break Things  That what your Developer Edition org is for!

•  Action Service is how your Lightning Component talks to the App Cloud

•  Learn it!

•  It is still new, so learn the effects of working with it

•  http://salesforce.stackexchange.com

Page 31: All Aboard the Lightning Components Action Service

Q & A

Peter Chittum Developer Evangelist @pchittum github.com/pchittum

 A list of resources will be posted to the session Chatter feed.

Page 32: All Aboard the Lightning Components Action Service

Thank you