Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit...

37
Working with JavaScript App Frameworks and ArcGIS API for JavaScript Derek Swingley Mike Juniper Matt Priour Fred Aubry

Transcript of Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit...

Page 1: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Working with JavaScript App Frameworks and

ArcGIS API for JavaScript

Derek Swingley Mike Juniper

Matt Priour Fred Aubry

Page 2: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS
Page 3: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS
Page 4: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

• Views react to changes on models/collections

• RESTful JSON interface

Page 5: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Pros: • Provides structure* • Separation of concerns (testability, maintainability)* • No more hanging state on the DOM ($(…).data(…))* • Huge community • Simple, flexible, lightweight • Lots of plugins available

marzbars/4315696107 * Thus improving testability and maintainability!

Page 6: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Cons: • Lots of boilerplate* • No view binding by default*

blade_dancer/3563118741

* Mitigated by plugins!

Page 7: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

https://github.com/mjuniper/backbone-demo-ds2014

Page 8: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Frederic Aubry Operations Dashboard Developer

esri JavaScript API and ember.js

Page 9: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

ember.js

• ember.js is an MVC JavaScript framework (http://www.emberjs.com)

• Highly inspired by Cocoa MVC from Apple (http://developer.apple.com/library/mac/documentation/general/conceptual/devpedia-cocoacore/MVC.html)

UI View Controller Model

input notifies updates

draws notifies notifies

Route

Route

sends event

sends event

Bootstrap Objects -> Route

Draw initial UI -> Template

Template

uses

Input to User Intent -> View/Template

Application State -> Route

Update Domain Objects -> Controller

Notify UI of changes -> Data Binding

Update UI -> View/Template

Page 10: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Demos

• Demo 1 - Rewritten the “Gas price data by state mashup” sample with ember.js - Code can be accessed on http://github.com/ffaubry/data-gas-prices-ember

• Demo 2

- Share implementations and designs by using ember.js web components - http://jsbin.com/fuhix/6/edit

Page 11: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

ember.js and dojo being good friends

• No issue with AMD and build… If you do it right • Use view.didInsertElement to bootstrap dojo/dijit instances • Use view.willRemoveElement to destroy dijit instances • BorderContainer and other dijit layout classes require a bit more plumbing

Map View

Child View

Parent View

Page 12: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

From developer to developers

• MVC is essential for ambitious apps • Search for UX patterns when you write your app => Components • Encapsulate your styles => Component • AMD is good if you use a build system

Page 13: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Matt Priour JS API Core Development Team [email protected] @mattpriour

Esri JS API and AngularJS Using Frameworks with the JS API

Page 14: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

What is AngularJS ?

A markup-centric MVW framework

Page 15: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

http://angularjs.org/#todo-html

Page 16: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

http://angularjs.org/#todo-js

Page 17: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

It’s not cluttered. It’s working.

Page 18: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Self contained logic can be wrapped in a

“directive”

Page 19: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS
Page 20: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

http://mpriour.github.io/ds14-frameworks-angular/app/

Page 21: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Show the Code

index.html

Page 22: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Load the libraries and the initialization scripts

index.html

Page 23: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Show the Code

ß setup.js

init.js à

Page 24: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Wrap Angular Code in dojo-AMD

Page 25: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

index.html

Application specific logic goes in the controllers

Page 26: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

‘extent= . . . . .’ -- or --

‘center = . .’ and ‘zoom’ = .

index.html

Layer options and event handlers

Page 27: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Next Steps • Make application parts more modular

• Don’t include large objects in $scope, like

Map or FeatureLayer

• Make better use of template expressions.

• Towards an angular based esri js api component library.

Page 28: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Learning More Angular.org – http://angular.org - http://docs.angular.org YouTube - https://www.youtube.com/user/angularjs Map, FeatureLayer and Setup/Init taken directly from Patrick Arlt https://github.com/patrickarlt/dev-summit-talk-angular-js/ Egghead.io - https://egghead.io/ Just Try It. Actually doing it is the best way to learn !

Page 29: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Matt Priour JS API Core Development Team [email protected] @mattpriour

Patrick Arlt Portland R&D Team [email protected] @patrickarlt

Page 30: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

• Templates* • Shadow DOM* • Custom elements* • Packaging*

* Web Components!

Page 31: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Pros: • Everything is an element! • It’s the way the web is headed? • Works today in ‘evergreen

browsers’

evanhahn/4991130110

Page 32: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Cons: • Everything is an element! • Not production ready • Evolving standards

quinnanya/4894977089

Page 33: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

https://github.com/mjuniper/polymer-demo-ds2014

Page 34: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Summary

Backbone: simple, lightweight, flexible,

community…boilerplate, no data binding à Marionette?

Angular: markup-centric, MV “watcher”, directives,

community/videos/egghead… JS in my markup, seems

complicated/magical

Page 35: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Summary

Ember: MVVM, data binding, leaning toward web

components, templating, routes + controllers

Polymer / web-components: not-MVC, future, markup,

performance … future (templates, shadow DOM, custom

elements, packaging)

Page 36: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Get the code…

https://github.com/mjuniper/backbone-demo-ds2014

https://github.com/mpriour/ds14-frameworks-angular

https://github.com/ffaubry/data-gas-prices-ember

https://github.com/mjuniper/polymer-demo-ds2014

Bonus: https://github.com/mjuniper/polymer-sandbox

Page 37: Working with JavaScript App Frameworks and ... - Amazon S3 · 2014 International Developer Summit -- Technical Workshop Presentation, Working with JavaScript App Frameworks and ArcGIS

Session survey: http://esriurl.com/7517

Derek Swingley Mike Juniper

Matt Priour Fred Aubry