Getting Started Developing JavaScript Web Apps. this = that. VT Geospatial Forum 2015

Size: px
Start display at page:

Download "Getting Started Developing JavaScript Web Apps. this = that. VT Geospatial Forum 2015"

Transcription

1 Getting Started Developing JavaScript Web Apps this = that VT Geospatial Forum 2015

2 GCS = Geographic Communication Systems GCS specializes in location technology development, working with GIS and other location based services.

3 console.log( hello world ); John Waterman, PMP, GISP GCS East Burke, Vermont johnrobertwaterman

4 Why JavaScript? Why JavaScript?

5 Modern Browsers

6

7 [JS] Frameworks TodoMVC Frameworks Full Spectrum of Options MicroJS "Plain Old JavaScript Object" Toolkits Dojo JQuery Libraries Backbone MarionetteJS Ampersand (Models, Collections, Views, Router, and JavaScript) (need to write boilerplate code) Frameworks (They try to do it all) AngularJS forms-over-data apps Enterprise Ember Building big apps; big teams; many apps Consistent

8 Learning JS and Dojo

9 Developing and Debugging Tips and Tricks JavaScript IDEs many options Developer Tools Set breakpoints Log information console.log() - new vs. alert() old school View network traffic Inspect CSS Chrome - Canary

10

11 Developing and Debugging Tips and Tricks Code Quality Tools the good parts JSLint JSHint For example, trailing commas IDE Integration: Grunt, VS Web Essentials Plug In, etc. Esri JSAPI Resources jshint Typescript

12 Developing and Debugging Tips and Tricks Beautifiers Jsbeautifier.org Cssbeautify.com Plug-ins

13 Developing and Debugging Tips and Tricks Task Automation Automate tasks Beautify Minification Grunt Gulp

14 Developing and Debugging Tips and Tricks

15 1 2

16 1 2

17

18

19 Investigate code

20 2 Update Map based on code changes 1 Change basemap to streets

21 Edit Code Locally Set-Up

22 Edit Code Locally Set-Up Notice local file path Open local file in browser

23 Sources Tab Edit Code Locally Set-Up Open Dev Tools

24 In order to edit file, we need give editing permissions to Chrome Edit Code Locally Set-Up Highlight file Directory where file is located

25 In order to edit file, we need give editing permissions to Chrome Edit Code Loca Set-Up

26 Edit Code Locally Set-Up Folder appears You can edit this code Navigate to html and highlight

27 Inspect Global Variables Example Type map Console Tab Investigate map properties

28 Inspect Global Variables Example

29 Inspect Global Variables Example

30 Inspect Global Variables Example

31 Inspect Global Variables Example Cannot edit this file Select editable HTML file

32 Editing Code Example Refresh browser to view changes Note: * means edited file Change basemap to streets Save changes

33 Developing and Debugging Tips and Tricks Console.log() Map load event Add code block Save Changes Refresh Browser Console tab: view

34 Developing and Debugging Tips and Tricks Console.time() Console.timeEnd() Add Code Block Time it takes to load

35 Developing and Debugging Tips and Tricks CSS Design Inspect CSS 3

36 Hover over until you find this Inspect CSS Inspect CSS with Magnifying Glass

37 Developing and Debugging Tips and Tricks CSS Design Padding Save Changes Add sty 2 Inspect CSS

38 Inspect CSS

39 Inspect CSS

40 Developing and Debugging Tips and Tricks Inspect Network Traffic

41 Inspect Network Traffic

42 Create Requests Inspect Network Traffic View Network Traffic Investigate requests

43 Inspect Network Traffic Investigate Requests View request Parameters Click Request

44 Inspect Network Traffic Click URL Request Preview tab Investigate response

45 Developing and Debugging Tips and Tricks Trouble Shooting Bad module ID example

46 Developing and Debugging Tips and Tricks Debugging Minified JavaScript

47 Developing and Debugging Tips and Tricks Breakpoints XHR Breakpoints Event Listeners

48

49

50 Developing and Debugging Tips and Tricks Mobile Testing Best Test on Device Test Quickly on Browser

51 Modular JavaScript Typical Project Start small Add features Grow complexity Add developers Trouble Use Modules to avoid Monolithic apps

52 Modular JavaScript (Building blocks of code.) What is a module? Cohesive Single-purpose Reusable Interchangeable Why us modules? Focused code Simplifies Reuse Testing Collaboration Clean global scope Promotes DRY Don t Repeat Yourself

53 Modular JavaScript Example Creates namespace Private data Expose API var MyModule = (function () { // My Module API return { //private _privatemethod: function () { }, }; })(); //public publicmethod: function () { },

54 Defining Modules in Dojo Define Declare* Defining Widgets in Dojo Extend_WidgetBase What do you gain? Lifecycle Modular JavaScript define([ dojo/_base/declare, dijit/_widgetbase, dijit/_templatemixin, dojo/text!./templates/myhelloworld.html ], function (declare, _WidgetBase, _TemplatedMixin, template){ return declare ([_WidgetBase, _TemplatedMixin, template], { declaredclass: MyHelloWorld, templatestring: template }); Constructor->postMixInProperties->buildRendering->postCreate- >startup->destroy Ensure properties exist when you need them Extend_TemplatedMixin adding UI to widget HTML Define template in separate file; import template file as a string

55

56

57 John Waterman, PMP, GISP GCS East Burke, Vermont johnrobertwaterman