Using Promise Patterns with JavaScript, jQuery, and the SharePoint 2013 App Model Doug Hemminger SharePoint Solutions Architect, Protiviti
Agenda SharePoint 2013 App Primer JavaScript “Function” Primer Asynchronous Patterns in JavaScript
App Shapes
Terminology Host Web – A SharePoint website where the app is installed and surfaced to the user. App Web – An isolated SharePoint web site on the SharePoint app domain that hosts SharePoint components used in the app
Hosting Architectures SharePoint Hosted – App is hosted by SharePoint Provider Hosted – App is hosted on a dedicated server either on-premises or on a third party hosting service
SharePoint-hosted Apps Runs on an isolated app domain of the SharePoint farm Authorized using the privileges of the signed in user Can only use JavaScript and HTML- No server side code
Provider-hosted Apps Runs on a dedicated server or hosting service (not in SharePoint) Authorization is through OAuth or the JavaScript cross-domain library Can use any language supported by the web server or hosting service
JavaScript Functions Functions are Objects in JavaScript. Essentially they are strings of JavaScript code.
Asynchronous Patterns Callbacks Events Promises
Callbacks A callback is a function that is passed to another function as a parameter and somehow affects the flow of execution Functions are Objects in JavaScript
Callback
Promises A promise represents the eventual value returned from the single completion of an operation. Three states Unfullfilled Fulfilled Rejected
Promises In jQuery the Promise pattern can be used with $.when(object) where object is a deferred object or a promise
TitleUrl Choose patterns for developing and hosting your app for SharePoint us/library/office/fp179887(v=office.15).aspx Host webs, app webs, and SharePoint components in SharePoint us/library/office/fp179925(v=office.15).aspx Apps for Office and SharePoint Bloghttp://blogs.msdn.com/b/officeapps/ Showcase: Contoso Incubation Search Apphttp://msdn.microsoft.com/en-US/office/dn Asynchronous Programming in JavaScript with “Promises” chronous-programming-in-javascript-with- promises.aspx Promise Patternshttp://modernjavascript.blogspot.com/2013/09/prom ise-patterns.html Understand JavaScript callback functions and use them callback-functions-and-use-them/
TitleUrl Understanding Callbacks in JavaScripthttp://recurial.com/programming/understanding- callback-functions-in-javascript/