JavaScript. Using Handlebars

Содержание

Слайд 2

Rendering in the Browser

Applications are starting to use JSON “back end” services

Rendering in the Browser Applications are starting to use JSON “back end”
and construct the View HTML in JavaScript
www.backbonejs.org
www.emberjs.com
www.angular.net
www.reactjs.net
...

The only correct way to write JavaScript is whatever you were not doing last week.
@ThePracticalDev

Слайд 3

Web Server

Database Server

Time

Apache

PHP

MySql

Browser

JavaScript

DOM

Parse
Response

Send
Request

http://www.wa4e.com/code/rrc/

JQuery

Web Server Database Server Time Apache PHP MySql Browser JavaScript DOM Parse

Слайд 4

Model-View-Controller

A model that defines the elements of a web application and how

Model-View-Controller A model that defines the elements of a web application and
they interact
View – Produce output
Model – Handle data
Controller – Orchestration / Routing

https://en.wikipedia.org/wiki/Model-view-controller

Слайд 5

guess.php

$oldguess = '';
$message = false;
if ( isset($_POST['guess']) ) {

guess.php $oldguess = ''; $message = false; if ( isset($_POST['guess']) ) {
// Trick for integer / numeric parameters
$oldguess = $_POST['guess'] + 0;
if ( $oldguess == 42 ) {
$message = "Great job!";
} else if ( $oldguess < 42 ) {
$message = "Too low";
} else {
$message = "Too high...";
}
}
?>


A Guessing game


Guessing game...


if ( $message !== false ) {
echo("

$message

\n");
}
?>


value=""/>





Model

View

Controller

Context

Слайд 6

Web Server

Database Server

Time

Apache

PHP

MySql

Browser

JavaScript

DOM

Parse
Response

Send
Request

MVC in PHP

P DO

View

Controller

Context

Model

Web Server Database Server Time Apache PHP MySql Browser JavaScript DOM Parse

Слайд 7

handlebars.js

Templates with curly braces
Adapted from Django / AppEngine
Hot spots accept data from

handlebars.js Templates with curly braces Adapted from Django / AppEngine Hot spots
the context


{{title}}



{{body}}


Context


Equations



guess < 42


+

=

Слайд 8




hand-01.htm

Слайд 9

Web Server

Database Server

Time

Apache

PHP

MySql

Browser

JavaScript

DOM

Parse
Response

Send
Request

MVC in PHP

P DO

View

Controller

Context

Model

Web Server Database Server Time Apache PHP MySql Browser JavaScript DOM Parse

Слайд 10

Web Server

Database Server

Time

Apache

PHP

MySql

Browser

JavaScript

DOM

Parse
Response

Send
Request

View in JavaScript

P DO

View

Controller

Context

Model

Context

Web Server Database Server Time Apache PHP MySql Browser JavaScript DOM Parse

Слайд 11




hand-02.htm

header('Content-Type: ...');
$stuff = array(
'title' => 'Mathematics',
'body' => 'guess > 42');
echo(json_encode($stuff));

{ "title":"Mathematics",
"body":"guess > 42" }

Слайд 12

Handlebars Application

Handlebars Application

Слайд 13


index.php

res-handlebars

Слайд 14


....

index.php

Слайд 15

// This script works even if you are not logged in
require_once 'pdo.php';
header("Content-type:

// This script works even if you are not logged in require_once
application/json; charset=utf-8");
$stmt = $pdo->query('SELECT * FROM Profile');
$profiles = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo(json_encode($profiles, JSON_PRETTY_PRINT));

profiles.php

Слайд 16

profiles.php

[
{
"profile_id": "5",
"user_id": "1",
"first_name": "Chuck",
"last_name": "Severance",
"email": "csev@example.com",

profiles.php [ { "profile_id": "5", "user_id": "1", "first_name": "Chuck", "last_name": "Severance", "email":
"headline": "Python Rulez",
"summary": "Python",
"updated_at": "2016-04-04 21:15:27"
},
{
"profile_id": "6",
"user_id": "1",
"first_name": "Colleen",
"last_name": "van Lent",
"email": "colleen@example.com",
"headline": "Responsive Design Rulez",
"summary": "HTML5!",
"updated_at": "2016-04-04 21:16:12"
}
]

Слайд 17

Web Server

Database Server

Time

Apache

MySql

Browser

JavaScript

DOM

Parse
Response

Send
Request

Single Page Application - Angular

P DO

View

Controller

Model

Context

Model

Model

Web Server Database Server Time Apache MySql Browser JavaScript DOM Parse Response

Слайд 18

Summary

With JavaScript ES6 on the way and significant browser improvements on the

Summary With JavaScript ES6 on the way and significant browser improvements on
horizon, it is likely that the “best practice” both on the server and the client will continue to evolve.
It will continue to be important to understand how web applications work “all the way down” so you can work with these new innovations.

The only correct way to write JavaScript is whatever you were not doing last week.
@ThePracticalDev

Имя файла: JavaScript.-Using-Handlebars.pptx
Количество просмотров: 31
Количество скачиваний: 0