Front End Development
2-Day schedule - Day 2
-
Client side templating
-
OOP Patterns in JavaScript
-
Debugging JavaScript
-
Front End / Back End architectures
-
Intro to Backbone
-
Integrating with Kinvey
-
Building a music-twitter clone
Client side templating
-
Appending HTML using jQuery gets old quick
-
Wouldn't be nice to use templating like in Rails?
-
-
Rendering with Mustache
OOP In Javascript: JSON
Good: easy. Bad: each object separate
OOP In Javascript: Constructor + Prototype
Good: fast, no memory leak. Bad: no private methods, closure
OOP In Javascript: Constructor
Good: closure, data-hiding. Bad: slower, more memory
Debugging JavaScript
-
-
Watches
-
Step Debugging
-
Network Requests
-
Profiling
Front-end / Back-end Architectures
-
HTML Links and Forms - little to no JavaScript, no client side rendering
-
Ajax - Some JavaScript, still server-side rendering
-
JavaScript MVC - Generally only client side rendering
-
Hybrid - Both client and server-side rendering
Which is best?
It depends on the application.
Backbone.js is a JavaScript MVC-ish framework
-
Provides a way to structure and organize your JavaScript
-
Makes it easier to build larger JavaScript applictions
-
-
Has a nice, documented code-base at Backbonejs.org
-
Kinvey
-
A service for storing data in the cloud
-
Can push and pull arbitrary data in and out
-
Has a JavaScript API
-
Facebook
First: Facebook Javascript SDK
Facebook has a number of useful API's, we'll be using two:
-
A way of interfacing with Facebook entirely via Javascript (Yay!)
-
Their main API for accessing and posting data
All require we make a new facebook application
Facebook Javascript API Basics
Api Setup (After creating an application here: https://developers.facebook.com/apps
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : 'http://WWW.MYDOMAIN.COM/channel.html', // channel.html file
oauth : true // enable OAuth 2.0
});
</script>
Channel.html file:
<script src="http://connect.facebook.net/en_US/all.js"></script>
Facebook Javascript API Basics #2
Then, we can force a login:
<script>
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
alert("Ur Logged in!");
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'email'});
</script>
after we're logged in we can call the Graph API:
<script>
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
</script>
Graph API
The preferred method to pull data in and out of facebook
Reasonably well documented: Graph API
Before we go too much further...
Let's play around with the Facebook Graph Api via
Graph API Explorer
Let's connect With Facebook
Let's grab some more data, and the print it out
We can access the data variable in the console via: $("iframe")[0].contentWindow.responseData
Project
-
Let someone search a song via discogs API
-
Let them add that song to the Kinvey collection
-
Find a JavaScript API or two - perferably JSONp Programmable Web
-
Create a Mashup using Bootstrap to style