A JavaScript framework

Slides:



Advertisements
Similar presentations
CIS 4004: Web Based Information Technology Spring 2013
Advertisements

ExtJS 4.0 JavaScript MVC Framework. Who ExtJS is provided by Sencha ( o Sencha Touch o GWT o CSS Animator o IO (Cloud Data Management)
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
NextGen Technology upgrade – Synerizip - Sandeep Kamble.
Chris Pinski.  History  What is Ajax  Who uses Ajax  Underlying Technologies  SE Aspect  Common Problems  Conclusion.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
D2L Notes Be sure to submit your link in the dropbox provided on D2L You can just upload an empty text file if a file upload is required Do not use D2L.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
SE-2840 Web Application Development 1. 2 Contact info Dr. Mark L. Hornick For office hours, course syllabus, see:
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
SE-2840 Dr. Mark L. Hornick1 NodeJS Server-side JavaScript.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
SE-2840 Dr. Mark L. Hornick1 AngularJS A library for JavaScript.
Web Technologies Lecture 8 JQuery. “A fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Flux & React Web Application Development Mark Repka, Rich McNeary, Steve Mueller.
The New Face of ASP.NET ASP.NET MVC, Razor, and jQuery Ido Flatow | Senior Architect | Sela | This session is.
Wes Preston DEV 202. Audience: Info Workers, Dev A deeper dive into use-cases where client-side rendering (CSR) and SharePoint’s JS Link property can.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
React Tutorial Giuseppe Attardi Università di Pisa.
Using React, Drupal and Google Chrome to build an interactive kiosk + + =
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Advanced Topics in Concurrency and Reactive Programming: React
Introduction to.
DHTML.
Angular vs React John
Angular JS and SharePoint
Web Technologies Computing Science Thompson Rivers University
Web API - Introduction AJAX, Spring Data REST SoftUni Team Web API
Introduction to Dynamic Web Programming
What's new in the world of SharePoint development and deployment
Unleash the Power of jQuery
Creating React Components with JSX and Babel
MVC Architecture, Symfony Framework for PHP Web Apps
AJAX and jQuery AJAX AJAX Concepts, XMLHttpRequest, jQuery AJAX: $.ajax(), $.get(), $.post() jQuery AJAX XMLHttpRequest SoftUni Team Technical Trainers.
Human Computer Interaction
Play Framework: Introduction
AJAX and REST.
Arrays and files BIS1523 – Lecture 15.
Haritha Dasari Josue Balandrano Coronel -
PHP Training at GoLogica in Bangalore
Not Sure how you Should React
Intro to PHP & Variables
Jessica Betts, Sophia Pandey, & Ryan Amundson
JavaScript Introduction
JavaScript an introduction.
HTML A brief introduction HTML.
Angular (JS): A Framework for Dynamic Web Pages
Advanced Topics in Concurrency and Reactive Programming: React
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
Model-View-Controller (MVC) Pattern
15 minute break.
Lesson 9: GUI HTML Editors and Mobile Web Sites
Secure Web Programming
Input CS 422: UI Design and Programming
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
JavaScript CS 4640 Programming Languages for Web Applications
HTML5 and Local Storage.
Innovation Co-Lab roots/React
Web Technologies Computing Science Thompson Rivers University
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Web Client Side Technologies Raneem Qaddoura
Web Programming Anselm Spoerri PhD (MIT) Rutgers University
Build’an’Office add-in- using’modern JavaScript tools and techniques
JavaScript CS 4640 Programming Languages for Web Applications
SharePoint Saturday Kansas City October 19, 2019
Presentation transcript:

A JavaScript framework SE-2840 Dr. Mark L. Hornick

Introductory topics MVC jQuery/DOM manipulation Virtual DOM Components Babel JSX Webpack SE-2840 Dr. Mark L. Hornick

React Executive Summary Created/Backed by Facebook First prototype with php in 2010 Open-sourced in 2013 Stable 2015 Adaptation 2016 - present Current stable release is 16 React allows you to write special HTML components that synchronizes with your JavaScript leaving you to write your application logic instead of manually updating the DOM.  SE-2840 Dr. Mark L. Hornick

Review What is the Model-View-Controller pattern about? SE-2840 Dr. Mark L. Hornick

What is React and what problem(s) does it address? First, consider the structure of the web apps you have done so far: Does the code present a clean implementation of the MVC pattern? Where is the View implemented? what code file(s)/module(s) create or modifie what is seen in the browser? Where is the Controller implemented? what code is responsible for getting data and deciding what data is to be displayed? Where is the Model implemented? what code is responsible for storing data?

HTML/jQuery approach mixes Controller and View The typical paradigm is as follows: Access a DOM element Read its value Send the value to the Model OR Read a value from the Model Update its content with the value SE-2840 Dr. Mark L. Hornick

Typical jQuery approach $('#program').html(track.curriculum); $('#year').html(track.year); $('#quarter').html(track.term); $('#courselist').empty(); // clear the course list (note: managing the ui here) $('#courselist').append("<ul class='list-group'>"); // add the <ul> element track.courses.forEach((course, index) => { // iterate all courses // note html mixed with script (ui+control = low cohesion/bad code smell) $('#courselist > ul').append("<li class='list-group-item list-group-item-success'>" + course.id + " : " + course.desc + '</li>'); }); // end forEach Green = UI markup Blue=UI manipulation in control code ALSO: Manipulating the DOM is slow and CPU intensive SE-2840 Dr. Mark L. Hornick

Low cohesion! High coupling! Bad code smell! Note that the JavaScript “knows” about the View, since it explicitly has to add a <li> element to the <ul> This is an example of poor cohesion and tight coupling SE-2840 Dr. Mark L. Hornick

React Motivation Evolution has moved wep app architecture towards SPA (single page applications) , where the : Server implements the Model (e.g. Phonebook) Client (browser) implements the View and Controller The Controller is responsible for Getting data from the server and making it accessible to the view. Extracting data from the view and posting it to the server The View is responsible for Deciding how to display components/elements and information to ensure a unified UI experience (desktop, tablets, phones) SE-2840 Dr. Mark L. Hornick

React is one of many competing frameworks that attempt/promise to: Decouple DOM manipulation from app logic (control) Decouple client-side from server-side Improve testability Make common coding tasks easier This is changing rapidly. To get the latest, google “javascript mvc frameworks” SE-2840 Dr. Mark L. Hornick

SE-2840 Dr. Mark L. Hornick

SE-2840 Dr. Mark L. Hornick

SE-2840 Dr. Mark L. Hornick

2017 survey results: Google: “angularjs vs other frameworks” for many differing opinions SE-2840 Dr. Mark L. Hornick

SE-2840 Dr. Mark L. Hornick

React (generally, web frameworks) are not perfect Not a good fit for applications that require intensive and tricky DOM manipulation of the DOM (ie games, gui editors) In such cases, it may be better to use a library that exposes a lower level of abstraction, like jQuery Although React Canvas might be just as good React has been accused of being a memory hog SE-2840 Dr. Mark L. Hornick

Lab 8 Tables must used the same React Component You’ll be developing a React Component to represent both tables The “buses on route” table contained (rt, vid, spd, lat, lon, dist) The “speeding bus” table contained columns (rt, vid, spd, lat, lon, tmstmp) Write your Component to conform to the “speeding bus” format Both tables will display the same data format The same information is in both Ajax responses from your Node server (although the “buses on route” response has more information) MAKE SURE ONLY THE TABLE SCROLLS SE-2840 Dr. Mark L. Hornick

Include a couple of <scripts> into your html: React approach #1 (nobody actually does this – for illustration purposes only!) Include a couple of <scripts> into your html: <!-- These are the React core modules --> <script src="https://unpkg.com/react@15.4.2/dist/react.js"></script> <script src="https://unpkg.com/react-dom@15.4.2/dist/react-dom.js"></script> In the js file, use React’s createElement() method to build an VirtualDOM locally: let listitems = []; track.courses.forEach( (course, index) => { let element = React.createElement("li", {key:index, 'className':'list-group-item list-group-item-info'}, (course.id + ' : ' + course.desc) ); listitems.push(element); } ); // end forEach let unsignedlist = React.createElement("ul", {'className': 'list-group'}, listitems ); // This tells React where to render the virtual DOM structure ReactDOM.render(unsignedlist, document.getElementById("courselist")); HTML-like elements still in code; We need to separate this out! Use ReactDOM.render to display the VirtualDOM (much more efficient). SE-2840 Dr. Mark L. Hornick

Using createElement() to create <p id=‘p1’ class=‘text-primary’>Hello SE2840</p> createElement(‘p’, {id:’p1’, className:’text-primary’}, ‘Hello SE2840’ ) Syntax: createElement( type, [props], […children] ) Type – tag name string (‘div’, ‘p’, etc) Props – element properties as a Javascript object Since ‘class’ is a js reserved word, we must use ‘className’ …children – an iterable (0 or more arguments) Returns a ReactElement object SE-2840 Dr. Mark L. Hornick

Using createElement() to create <div> <h1>A heading</h1> <p>A paragraph</p> </div> createElement(‘div’,null, createElement(‘h1’,null,’A heading’), createElement(‘p’,null,’A paragraph’) ) The nesting of calls can be repeated as much as necessary. SE-2840 Dr. Mark L. Hornick

React approach #2 (separate the control code from the view code) Include a couple of <scripts> into your html: <!-- These are the React core modules --> <script src="https://unpkg.com/react@15.4.2/dist/react.js"></script> <script src="https://unpkg.com/react-dom@15.4.2/dist/react-dom.js"></script> Use ReactDOM.render to display the VirtualDOM (much more efficient). $('#program').html(track.curriculum); $('#year').html(track.year); $('#quarter').html(track.term); // This tells React where to render the virtual DOM structure ReactDOM.render(<Courselist items={track.courses}/>, document.getElementById("courselist")); But have the control code use Courselist, a custom view component that is defined elsewhere, and provide that component with data SE-2840 Dr. Mark L. Hornick

React approach #2 (the view code) Include a couple of <scripts> into your html: <!-- These are the React core modules --> <script src="https://unpkg.com/react@15.4.2/dist/react.js"></script> <script src="https://unpkg.com/react-dom@15.4.2/dist/react-dom.js"></script> Use JSX to define the view – almost identical to regular HTML (except ‘className’) class Courselist extends React.Component { render() { return <ul className='list-group'> { // Javascript in the middle of JSX needs to be delimited with {} this.props.items.map((course, index) => <li key={index} className='list-group-item list-group-item-danger'> {course.id + ' : ' + course.desc} </li> ) } </ul> } // end render() } JSX can embed Javascript to get at data (that is, the items array) provided by controller SE-2840 Dr. Mark L. Hornick

But JSX is not Javascript, so we have to use the Babel transpiler to convert it to regular Javascript The view code as transpiled by Babel: class Courselist extends React.Component { render() { return React.createElement("ul", { className: "list-group" }, // Javascript in the middle of JSX needs to be delimited with {} this.props.items.map((course, index) => React.createElement("li", { key: index, className: "list-group-item list-group-item-danger" }, course.id + ' : ' + course.desc))); } // end render() In our html file, we need to include the Babel-script rather than the original script containing the JSX SE-2840 Dr. Mark L. Hornick