Interactive frontend development
Urmas Talimaa
SaleMove Inc
History
Urmas Talimaa
Teaching assistant Älli
What’s SaleMove?
A bleeding edge tech company right here in Tartu
Business in US, Development in Tartu
The future of online Customer Experience
Teamviewer and skype straight in your browser with no installs
Course overview
What is expected of you?
Homeworks
Homeworks
Communication
Grading
Why build a JavaScript browser application?
Why build a JavaScript browser application?
Examples of websites that are not applications
Examples of websites that could be applications
Definitions
ECMAScript (ES) is a specification e.g ES5, ES6 ES7
JavaScript is a programming language (conforms to ECMAScript spec)
There are other languages that conform to different ECMAScript versions:
Different runtime engines for JavaScript
Definitions
Document Object Model (DOM) is an interface for programming HTML documents (also XML and SVG)
Can be used to interact with the web page in a web browser
JavaScript Tooling
JavaScript Tooling
Generally you have a task runner/build tool �that invokes a transpiler to transform source code to ES5 compliant JavaScript and then calls a module bundler that gathers modules into one or more JavaScript files that can be loaded in a browser.
JavaScript files are served by an asset server which might also be providing live reloading.
User loads a HTML file which requires a JavaScript file that either includes all your modules or loads some immediately and some later on demand.
JavaScript Tooling
ES6
Robot
ES7
App
Transpiler
ES5
Robot
ES5
App
Module bundler
ES5
bundle.js
Asset server
Web Browser
<script src=’public/bundle.js’>
How to get libraries?
NodeJS, JS in the backend
JavaScript Tooling - Packages
JavaScript Tooling - Yarn
JavaScript Tooling - Yarn
https://yarnpkg.com/en/docs/cli/
How to import other files?
ECMAScript 6 or ECMAScript 2015
JavaScript in general has become fluid, different browser versions supporting different features/syntax
ECMAScript 6 or ECMAScript 2015
JavaScript Tooling - Modules
JavaScript runs in the browser, no native modules
ES6 has finalized module syntax http://www.2ality.com/2014/09/es6-modules-final.html
Previously there were competing standards:
JavaScript Tooling - Modules
Promise-based asynchronous loading using System.import (used later in the course)
Example
JavaScript Tooling - Transpilers
Compiling: Transforming source code to a language on another level of abstraction (e.g from C to machine code)
Transpiling: Transforming source code to a language on a similar level of abstraction
JavaScript Tooling - Transpilers
JavaScript Tooling - Build tools
Everything about your build should be repeatable
https://stateofjs.com/2017/build-tools/results
Example continued
Live reload
Transpiler
Module bundler
Asset server
Web Browser
<script src=’dist/bundle.js’>
ES6
Robot
Filesystem watcher
1. File changes
2. Rebuild
3. Notify via Websocket
4. Reload
Example continued
Source maps
A source map tells the browser what the original source code looked like and how do the different functions and classes map to the generated final file (app.js). Errors/console statements point to lines in the source code instead of the generated file. It greatly simplifies developing, especially when using transpilation.
Source maps need to be configured in the build tool.
CSS
CSS modules
Lint
Unit tests
Unit tests
Manual DOM manipulation
const myDiv = document.querySelector(“#my-div”);�myDiv.innerHTML = “my-text’;�myDiv.onclick = function(){ myDiv.innerHTML = ‘clicked!’; };
Manual DOM manipulation
DOM can only be manipulated when it has been parsed (DOM is ready)
function doWork() { … }�if (document.readyState === "complete") {� doWork();�} else { � document.addEventListener("DOMContentLoaded", doWork);�}
https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded
"Running your code at the right time"
<script … defer=true> is simplest option to defer JavaScript execution until DOM is ready
Running scripts using yarn
“scripts”: {� “test”: “mocha ./test/”� “start”: “webpack-dev-server --open --config webpack.config.js”,�}
Homework
Deadline 23/03/2017 11:59
Only submit what is yours
Only assume that NodeJS v8.10 is available locally
Feel free to use tools other than described (provided they are installed with yarn install), but don’t expect full support or less-strict grading if you do. If you need to provide further information, include it in README.md.
Submit zipped file to https://courses.cs.ut.ee/2018/react/Main/Submit
Don’t include node_modules or .git/, .hg/, .svn/, make sure that your zipped file size is reasonable
You can use/modify/extend this script (usage: node zipHomework.js) to automate creating a zip file without specific folders.
Homework solution
DEMO