On Github climboid / workshop
Created by
We are very similar in many ways, especially when it comes to working hard and being passionate about our teams
The secret sauce is in using the right tools
Using the right tools also means that we have the power to do things better and more organized with richer interactions
Start with your workflow
How much time do you spend this days creating a boilerplate template? Do you have all of your set up processes optimized so that you spend very little effort finding and installing what you need?Takes care of minification, compilation (sass, coffeescript), unit testing etc
Automation
A package manager for the web, mainly front end packaging management.
How many js libraries are there out there? Name a few out loud Back in the day we had prototypeJSA way to instantiate convention over configuration
Boilerplate code
Anybody does rails? This is like scaffoldingAddy Osmani, Hemanth HM and some of the best in the world
Some of the best devs around... they're all buddies actually and most of them work at Google. Pitfalls of that. Benefits of thatLive example
npm install -g yo npm install -g generator-webapp npm install -g generator-angular
Live example
Create a project with Yeoman Install something via bower Run a grunt command to create the dist folderA pattern for your code that separates interaction and view
<!doctype html> <html> <head> <meta charset="utf-8"/> </head> <body ng-app="App"> <div class="container" ng-view></div> <script src="components/angular/angular.js"></script> <script src="scripts/app.js"></script> <script src="scripts/controllers/main.js"></script> </body> </html>This is a basic index.html file. You don't need to break out the controller and app.js files but its recommended for best practices. That way as your app gets bigger you can follow a nice file/folder structure where each route potentially can have its own controller and view (unless sharing makes more sense)
'use strict'; angular.module('App', []) .config(function ($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' }) .otherwise({ redirectTo: '/' }); });This snippet would belong to the app.js file. Here we define all of our routes and potentially any ajax interceptors. Maybe some rootscope properties as well
A router allows you to glue a controller to a view, creates a scope underneath that controller and maintains state within the app.
$routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' }) .when('/directory', { templateUrl: 'views/directory.html', controller: 'DirectoryCtrl' }) .otherwise({ redirectTo: '/' });
Instantiation of a new controller object along with its child scope
'use strict'; angular.module('App') .controller('MainCtrl', function ($scope) { $scope.awesomeThings = [ 'HTML5 Boilerplate', 'AngularJS', 'Karma' ]; });
ng-viewTemplates that interpolate scope objects that are part of a given controller or are inherited prototypically.
<div class="hero-unit"> <h1>'Allo, 'Allo!</h1> <p>You now have</p> <ul> <li ng-repeat="thing in awesomeThings">{{thing}}</li> </ul> <p>installed.</p> <h3>Enjoy coding! - Yeoman</h3> </div>
Keeps your logic contained to that controller unless you are using $rootScope
$scope will allow you to interpolate its properties in a given view
$scope.hello = "world"
<div ng-bind="hello">...</div> <div>{{hello}}... </div>
What gets rendered in the ... ?
angular.module('App') .controller('MainCtrl', function ($scope) { $scope.hello = [ { title:'me',color:'blue',value:2 }, { title:'you',color:'red',value:0 } ]; $scope.btnClicked = function(){ ... }; $scope.falsy = false; }); <!-- main.html--> <ul ng-if="!falsy"> <li ng-repeat="item in hello" ng-click="btnClicked()"> <div ng-bind="item.title"></div> <div>{{item.color}}</div> <input type="number" ng-model="item.value"/> </li> </ul>
Something that spans multiple controllers and doesn't have a view tied to it.
'use strict'; angular.module('App') .service('Welcoming', function Calculations() { return{ sayHello: function(){ return 'hello' }, sayGoodbye: function(){ return 'goodbye' } } });
Maintained across the entire application. Can be injected as a service. Use this for constants within your application.
'use strict'; angular.module('App') .constant('Pi', 3.141516);
UI components, charts, visualization... anything that has specific html conversion and needs to be part of the given scope.
'use strict'; angular.module('App') .directive('chart', function () { return { restrict: 'E', controller: function($scope, $element){ ... }, templateUrl: 'my-dialog.html', link: function (scope, element) { scope.name = 'Jeff'; } }; });
If you have Yeoman installed follow the presenter
If you do not have Yeoman installed please clone this repo
You can think of it as Flash but way cooler because it can interact with the rest of the app given that it uses JavaScript to draw items inside of it
D3.js Raphael Bonsai JS
Edward Tufte is the guru of graphics, the high priest of presentation. For more than 30 years he has been showing us how to visualise data with simplicity, clarity and elegance, while campaigning against “chartjunk” and other design practices that lead to obfuscation.
/
var width = 960, height = 500; var projection = d3.geo.albersUsa() .scale(1000) .translate([width / 2, height / 2]); var path = d3.geo.path() .projection(projection); var mapContainer = d3.select("#usaMap").append("svg") .attr("width", width) .attr("height", height); d3.json("/data/output.json", function(error, us) { mapContainer.insert("path", ".graticule") .datum(topojson.feature(us, us.objects.roads)) .attr("class", "land") .attr("d", path); });
Create an angular application using Yeoman
That app should have two routes, main and aboutUs, create them using the generator
Include d3 using bower
Insert the d3 code into a directive
Insert the directive into the aboutUs route
If you were not able to install Yeoman please clone the workshop repo
git clone https://github.com/climboid/workshop.git
mkdir finalApp cd finalApp
yo angular
bower install d3 // include file in index.html
yo angular:route contactUs yo angular:route aboutUs
// // create the routes // // app.js $routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' }) .when('/contactUs', { templateUrl: 'views/contactUs.html', controller: 'ContactUsCtrl' }) .when('/aboutUs', { templateUrl: 'views/aboutUs.html', controller: 'AboutUsCtrl' }) .otherwise({ redirectTo: '/' }); // // crete the controllers // // scripts/controllers/main.js 'use strict'; angular.module('finalApp') .controller('ContactUsCtrl', function ($scope) { }); //scripts/controllers/aboutus.js 'use strict'; angular.module('finalApp') .controller('AboutUsCtrl', function ($scope) { }); // // create the view files // // views/contactus.html // views/aboutus.html
yo angular:directive chart
// scripts/directives/chart.js 'use strict'; angular.module('finalApp') .directive('chart', function () { return { restrict: 'E', link: function (scope, element) { } }; });
//aboutUs.html <chart></chart>
'use strict'; angular.module('finalApp') .directive('chart', function () { return { restrict: 'E', link: function (scope, element) { // // code goes here // // into what DOM node should we insert the directive? } }; });