The JavaScript Promise
[CodeStock 2015 edition]
A Full Stack Nirvana
{{Sponsor slide goes here}}
DOGUHAN ULUCA
JavaScript Specialty Lead
Excella Consulting
@duluca
techtalkdc.com
JavaScript && Promises?
explainJavaScriptPromises()
.then(function(result) {
console.log(result);
talkAboutFullStackJS();
});
function explainJSPromises() {
var deferred = Q.defer();
//some time consuming op
return deferred.promise;
}
//time consuming operation
$http.get(`google.com/search?=
javascript async promises`)
.then(function(wisdom) {
deferred.resolve(wisdom);
});
explainJavaScriptPromises()
.then(function(result) {
console.log(result);
talkAboutFullStackJS();
});
What is The JavaScript Promise?
ease of use
happiness
effectiveness
-
idea
-
JavaScript
-
...
-
profit
stack is key
Presentation
API
Business
Persistence
Best Practices
IDE
Patterns
Libraries
TESTING
What if?
Everything was same or very similar
Same language
No Context Switch
Full Stack Nirvana
Going Full Stack
"[T]he foundation of running node-style code to build powerful server solutions is not going away.
It is the future of the web."
Eran Hammer - WalMart Labs, Web Services Lead
Node-style... what?
thin
fast
non-blocking
modularized
i/o
easy
High Performance
PayPal
Improved response times by 35%
which led to
200% increase in concurrent requests handled
High Levels of Scalability & Stability
WalMart
Node.JS since 2013
WalMart
In 2014
1.5 billion page views
during Black Friday
During
Black Friday
they chose
to deploy
new features
Maintainability
Malleability
PayPal
2x increase in
developer productivity
Developer Happiness
Skill share
Code share
Same tools
No
Context
Switching
The right syrup can fulfill this promise
stack
syrup
Anatomy of
A Hapi LEBRON
The Right Stack
Angular
Hapi.JS
LevelDB
Browserify
NPM
Max Ogden
Open Web Programmer
http://lebron.technology/
Angular.JS
Hapi.JS
Node.JS
LevelDB
Best Practices
WS
npm
Browserify
mocha && protractor
simple
approachable
Why not something more popular?
Sand bags of complexity
Goal
80% functionality
with 20% of the effort
Mongo
Express
Angular
Node
Mongo
+ Great for large databases
+ ORM features with Mongoose
+ Analytics using Jaspersoft
- Requires major installation
- Infrastructure
LevelDB
+ Fast key, value store
+ No installation
+ No infrastructure
- No ORM
- Only for basic data storage
Express
+ Most supported Node web app framework
+ Lightweight to get off the ground
- No built in error handling
- Can be tedious
Hapi.JS
- Less help available
- Initial boilerplate
+ Consistency
+ Configurability
+ Separate business logic from transport layer
Different libraries
Different contexts
leads to
Dependency Injection
var encrypt = require('encryption');
var guid = require('guid');
...
define(['other-encryption',
'other-guid'],
function (encrypt, guid) {
...
});
Browserify
brings NPM to the browser
var encrypt = require('encryption');
var guid = require('guid');
...
File Structure
|-Excella.Lean.Api
|-Excella.Lean.Core
|---Exceptions
|---Models
|-Excella.Lean.Core.Composition
|---Modules
|-Excella.Lean.Dal
|---EntityFramework
|---Migrations
|-Excella.Lean.Domain:
|---Events
|-----Impl
|---Shared
|-----Impl
|-Excella.Lean.Fakes
|-Excella.Lean.ServiceReferences
|-Excella.Lean.Tests
|---Ui
|-----ModuleA
|-------PageObjects
|-------TestCases
|-Excella.Lean.Web
|---Composition
|---Content
|-----themes
|-------base
|---------images
|---Controllers
|---Core
|---Filters
|---Images
|---Models
|---Script
|-----app
|-------core
|---------helpers
|-------modules
|---------baseModule
|-----------landingPage
|---------eventsModule
|-----------eventDetails
|-----------eventsLanding
|-----lib
|-----tests
|-------core
|---------helpers
|-------other
|---Views
|-----Aat
|-----Home
|-----Shared
|-app
|---components
|---directives
|---services
|---styles
|-node_modules
|-public
|---css
|---favicons
|---fonts
|---images
|---js
|-server
|---controllers
|---models
|---services
|-shared
|-tests
Angular
Separation of concerns
Maximize concurrency
1.4+
Component based architecture
2.0
Standards based Web Components
If you didn't deploy
It never happened
Gulp.js
var gulp = require('gulp');
gulp.task('build-js', function () {
return gulp.src('app/app.js')
.pipe(browserify({
insertGlobals : true,
debug : !process.env.production || true
}))
.pipe(gulp.dest('./public/js'))
});
gulp.task('default', ['build-js']);
gulp.task('watch', function () {
gulp.watch('./app/**/*.js', ['default']);
});
CodeShip.io
Modulus.io
Dig Deeper
Working Full Stack Example
Real-time
Mobile first
Highly scalable
Special Thanks To
Kevin Groat
Alex Hoffman
Emmanuel Apau
Brian Palladino
Thank You!
Presented in JavaScript