volt 2015

82
ISOMORPHIC APP DEVELOPMENT WITH RUBY AND VOLT

Upload: ryanstout

Post on 03-Aug-2015

160 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Volt 2015

ISOMORPHIC APP DEVELOPMENT WITH RUBY AND VOLT

Page 2: Volt 2015

@RYANSTOUT

Page 3: Volt 2015

COMPLEXITY IN WEB DEVELOPMENT

Page 4: Volt 2015
Page 5: Volt 2015
Page 6: Volt 2015
Page 7: Volt 2015

COMPLEXITY IN 2004

Server Client

ViewsControllers

Models

Routes/Auth

Page 8: Volt 2015

COMPLEXITY IN 2005

Server Client

ViewsControllers

Models

Routes/Auth

Ajax

Page 9: Volt 2015

COMPLEXITY IN 2006

Server Client

ViewsControllers

Models

Routes/Auth

Ajax

REST

Random JS

Page 10: Volt 2015

COMPLEXITY IN 2007

Server Client

ViewsControllers

Models

Routes/Auth

Ajax

REST

Random JS

Page 11: Volt 2015

COMPLEXITY IN 2009

Server Client

ViewsControllers

Models

Routes/AuthREST

Asset Packing

Ajax

Random JS

Page 12: Volt 2015

COMPLEXITY IN 2011

Server Client

Views

Controllers

ViewsControllers

Models

Models

Routes/Auth

Ajax

RESTAsset Packing

Page 13: Volt 2015

COMPLEXITY IN 2012

Server Client

Views

Controllers

ViewsControllers

Models

Models

Routes/Auth

Ajax

REST

Asset Loading

Asset Packing

Page 14: Volt 2015

COMPLEXITY IN 2013

Server Client

ViewsControllers

Models

Routes/AuthREST

Routes/Auth

Asset Packing

Views

Controllers

Models

Ajax

Asset Loading

Page 15: Volt 2015

COMPLEXITY IN 2015

Server Client

ViewsControllers

Models

Routes/AuthREST

Asset Packing

Routes/Auth

Views

Controllers

Models

Ajax

Asset Loading

Page 16: Volt 2015

COMPLEXITY IN 2004

Server Client

ViewsControllers

Models

Routes/Auth

Page 17: Volt 2015

COMPLEXITY IN 2015

Server Client

ViewsControllers

Models

Routes/AuthREST

Asset Packing

Routes/Auth

Views

Controllers

Models

Ajax

Asset Loading

Page 18: Volt 2015

THE SEA OF COMPLEXITY

Page 19: Volt 2015
Page 20: Volt 2015
Page 21: Volt 2015

WHAT’S THE SOLUTION?Turbo-links

…just kidding :-)

Page 22: Volt 2015
Page 23: Volt 2015

ISOMORPHIC“similar in form”

Page 24: Volt 2015

ISOMORPHICSharing code between

client and server

Page 25: Volt 2015

Server Shared Client

Routes/Auth

Views

Controllers

Models

Ajax

Asset Loading

COMPLEXITY IN 2015

Controllers

Models

Routes/AuthREST

Asset Packing

Views

Auto Sync

Page 26: Volt 2015

ISOMORPHICSharing code between

client and server

Page 27: Volt 2015

WHAT IS VOLT?

Page 28: Volt 2015

WHAT IS VOLT?Isomorphic Web Framework

(for ruby!)

Page 29: Volt 2015

HOW?

Page 30: Volt 2015

OPALRuby to JavaScript compiler

Page 31: Volt 2015

VOLTShare controllers, models, views, and

routes between client and server

Page 32: Volt 2015

VOLTSame code runs on the client and the server!

Page 33: Volt 2015

VOLTSame code runs on the client and the server!!

Page 34: Volt 2015

VOLTSame code runs on the

client and the server!!!!

Page 35: Volt 2015

VOLTReactive Bindings for the DOM

Page 36: Volt 2015

VOLTAutomatic Data Syncing

Page 37: Volt 2015

VOLTBuild apps as nested components

Page 38: Volt 2015

OPAL

Page 39: Volt 2015

PERCEPTIONCompiling to JS adds complexity

Page 40: Volt 2015

JavaScript Compiled Ruby

Base Language

Debugging Complexity

Base Language

FalsenessWTF’s

File SizeNo Std Lib

COMPLEXITYPerformance

JS Bridge

Type Coersionthis

Page 41: Volt 2015

JavaScript Compiled Ruby

Base LanguageDebugging

COMPLEXITY

Base Language

FalsenessWTF’s

No Std LibType Coersion

this

Page 42: Volt 2015
Page 43: Volt 2015

WTF’sthis parseInt new type coercion

semicolon insertion typeof == vs === case fall-through broken comparators

“string” instanceof String == false undefined

Page 44: Volt 2015

PERCEPTION“Experimenting with @opalrb - every time I

expected to find an issue, nothing happened. Maybe it'll be time to retire coffeescript soon…”

- Sidu Ponnappa

Page 45: Volt 2015

TRANSPILINGlocal variables => local variables instance variables => object properties methods => function on object with $ prefix classes => prototypes

Page 46: Volt 2015

DEBUGGING IN OPALTranspiling

Source Maps Framework Black Boxing

RubySpecs Opal-IRB

Page 47: Volt 2015

TRANSPILINGclass User def initialize(name, age) @name = name @byear = Time.now.year - age end def welcome “Hi #{@name}, you were born in #{@byear}" end end puts User.new('Ryan', 29).welcome

Page 48: Volt 2015

def.name = def.birth_year = nil;def.$initialize = function(name, age) { var self = this; self.name = name; return self.byear = $scope.get('Time').$now().$year()['$-'](age);}; return (def.$welcome_message = function() { var self = this; return "Hi " + (self.name) + ", you were born in " + (self.byear); }, nil) && 'welcome_message';

Page 49: Volt 2015

def.name = def.birth_year = nil;def.$initialize = function(name, age) { var self = this; self.name = name; return self.byear = $scope.get('Time').$now().$year()['$-'](age);}; return (def.$welcome_message = function() { var self = this; return "Hi " + (self.name) + ", you were born in " + (self.byear); }, nil) && 'welcome_message';

Page 50: Volt 2015

def.name = def.birth_year = nil;def.$initialize = function(name, age) { var self = this; self.name = name; return self.byear = $scope.get('Time').$now().$year()['$-'](age);}; return (def.$welcome_message = function() { var self = this; return "Hi " + (self.name) + ", you were born in " + (self.byear); }, nil) && 'welcome_message';

Page 51: Volt 2015

def.name = def.birth_year = nil;def.$initialize = function(name, age) { var self = this; self.name = name; return self.byear = $scope.get('Time').$now().$year()['$-'](age);}; return (def.$welcome_message = function() { var self = this; return "Hi " + (self.name) + ", you were born in " + (self.byear); }, nil) && 'welcome_message';

Page 52: Volt 2015

return self.$puts($scope.get('User').$new("Ryan", 29).$welcome());

puts User.new('Ryan', 29).welcome

Page 53: Volt 2015

SOURCE MAPS

Page 54: Volt 2015

FRAMEWORK BLACK BOXING

Page 55: Volt 2015

OPAL-IRB

Page 56: Volt 2015

RUBYSPECS

Page 57: Volt 2015

0Kb

400Kb

800Kb

1,200Kb

1,600Kb

jQuery 2.0.3 Bootstrap+JS Angular Opal+Volt Ember

Uncompressed Minified Minified+Deflate

FILE SIZE

Page 58: Volt 2015

0Kb

28Kb

55Kb

83Kb

110Kb

jQuery 2.0.3 Bootstrap Angular Opal+Volt Ember

MIN+DEFLATE

Page 59: Volt 2015

PERFORMANCE

Class+Method Call 100x Array Push JSON.stringify vs to_json

JS Opal

benchmarks: https://github.com/ryanstout/opal_benchmarks

Page 60: Volt 2015

JS BRIDGEdef my_alert(msg) `alert(msg);` end

Page 61: Volt 2015

JavaScript Compiled Ruby

Base Language

Debugging Complexity

Base Language

FalsenessWTF’s

File SizeNo Std Lib

COMPLEXITYPerformance

JS Bridge

Type Coersionthis

Page 62: Volt 2015

JavaScript Compiled Ruby

Base LanguageDebugging

COMPLEXITY

Base Language

FalsenessWTF’s

No Std LibType Coersion

this

Page 63: Volt 2015

VOLT

Page 64: Volt 2015

COLLECTIONSpage store

params local_store

cookies

Page 65: Volt 2015

MVCController

View

Model

Page 66: Volt 2015

MVVMController/ ViewModel ViewModel

Page 67: Volt 2015

DEMO

Page 68: Volt 2015

COMPONENTSClient code + Assets + Server Code

Can be packaged as Gems Can provide “tags”

<:pagination page="{{ params._page }}" />

Page 69: Volt 2015

EXAMPLE COMPONENTSField Error Messages

Pagination File Upload

Google Maps Login/Signup Templates

Page 70: Volt 2015

TASKSclass CompleteTask < Volt::TaskHandler def complete store._todos.each do |todo| todo._complete = true end end end

Page 71: Volt 2015

VALIDATIONS & PERMISSIONS

Page 72: Volt 2015

VALIDATIONS

class Post < Volt::Model validate :name, length: 4 validate :username, unique: trueend

Page 73: Volt 2015

PERMISSIONSclass Post < Volt::Model own_by_user permissions do # Only allow owner or admin deny unless owner? || user.admin? endend

Page 74: Volt 2015

PERMISSIONSclass Post < Volt::Model own_by_user permissions(:update, :delete) do # Only allow owner to update, or admins deny unless owner? || user.admin? endend

Page 75: Volt 2015

PERMISSIONSclass Post < Volt::Model own_by_user permissions(:update, :delete) do # Only allow owner to update, or admins deny unless owner? || user.admin? end permissions(:read) do # Only the owner can see unpublished posts deny :notes if !published? && !owner? endend

Page 76: Volt 2015

RECAPAuto-Sync

Less HTTP/REST One Language Components

Single Framework Centralized State

Unified Router

Page 77: Volt 2015

RECAP

Page 78: Volt 2015

RECAP

Page 79: Volt 2015

GETTING STARTED WITH VOLTVideo Tutorials

Docs Gitter Chat

Page 80: Volt 2015

ROAD MAPData Provider API

Rails Integration (for legacy :-) Render HTML First (for SEO/Load Time)

RubyMotion Integration

Page 81: Volt 2015

Thanks

Page 82: Volt 2015

voltframework.com Thanks!

images: https://www.flickr.com/photos/haquintero/14694249897

https://www.flickr.com/photos/38535102@N04/12273961146

@RYANSTOUT & @VOLTFRAMEWORK