new silver bullet isomorphic javascript: trust teamwork...

25
As true as steel to your desire You come with just an idea - we make great software for you! Trust Teamwork Transparency Isomorphic Javascript: new silver bullet Vitaliy Medvedev, Arcadia

Upload: others

Post on 20-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

As true as steel to your desire

You come with just an idea -we make great software for you!

TrustTeamwork

Transparency

Isomorphic Javascript: new silver bullet

Vitaliy Medvedev, Arcadia

Page 2: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

About me

Vitaliy Medvedev

Leading Software Engineer at JSC “Arcadia Inc.”

5+ years of experience in software development

[email protected]

http://twitter.com/imevs

Page 3: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Where JS works

● client● server● desktop● mobile● quadcopters

Page 4: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Single page application (SPA)

JSON(AJAX/WebSockets)

HTML/CSS/JS PHP/C#/Java/NodeJs

Frontend (MVC)

AnimationValidation

TemplatingRouting

Backend (MVC)

PersistenceAuthentication

Heavy calculations

Page 5: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

SPA problems

● loading time● search engine indexing● logic duplication

o different languages - different ecosystemso cross-functional restrictions

Page 6: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Page 7: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

1. Solution!

Page 8: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

What to do?

1. Write in the same language on both sides2. Use same code on both sides

Page 9: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Isomorphic? WAT?!

● cross-platform

● multi-platform

● heteromorphic

● ....

Page 10: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Who invented isomorphism?

History:1. 18 Oct 2011

Scaling Isomorphic Javascript Code

2. 01 Apr 2012Yahoo! Mojito Framework

3. 08 Nov 2013The future of web apps is — ready? — isomorphic JavaScript

Page 11: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

2. Let’s do isomorphism!

Page 12: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Using scripts

var module = require(‘./jquery’);

<script src="script.js" [async] [defer]></script>

require([‘jquery’], function ($) {// do smth

})

Page 13: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Differences between client & server JS

● Global objectsglobal / window

● Different available apilocalStorage, historyApi, WebGL, Canvas, FileSystem

● Differences in API behaviorcookies, websockets, webworkers

Page 14: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Differences between client & server JS

● Environment

● Script loading

● Available api

● Engine version

Page 15: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Diving into isomorphism

● Understand that you can write as isomorphic● Code kinds

o Code that should not work at frontend side

o Code that should not work at backend side

o Independent of environment

o Dependent of environment

Page 16: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Diving into isomorphism

● Abstraction from environmentbrowserify, typescript

● Environment specific unit testskarma, mocha, phantomjs

● Static code analysisjslint, jshint, eslint, tslint

Page 17: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Code before isomorphism

Page 18: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Simple isomorphic module

(function (exports) {exports.isomorphicSum = function (a, b) {

return a + b;};

})(typeof exports ? exports : window)

Page 19: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

What is isomorphic code good for?

1. Templating (handlebarsjs)2. Business logic:

o validationo filteringo calculations

3. Using common libraries (jquery, undescore)

Page 20: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Isomorphic libraries

● jquery● undescore● backbonejs● lodash● cryptojs● handlebarsjs● async

Page 21: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

3. What’s next?

Page 22: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Full stack javascript frameworks

Page 23: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Profit

✓ decrease loading time✓ search engine indexing✓ decrease logic duplication✓ better code design✓ code consistency

Page 25: new silver bullet Isomorphic Javascript: Trust Teamwork ...2014.secrus.org/2014/files/111_medvedev.pdf · © Copyright JSC “Arcadia, Inc.” Useful links Learning resourсes: 1

© Copyright JSC “Arcadia, Inc.”

Q & A