Top Banner
REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181
29

REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

Jan 11, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

REAL WORLD SPAA K N O C K O U T C A S E S T U D Y

Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181

Page 2: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

HI, I’M CORY.

@housecor

Page 3: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

What monthly payment would you

like?

Page 4: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.
Page 5: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

JAVASCRIPT CONFIGURATION OBJECT PATTERN

Page 6: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

CONFIG OBJECT PATTERN: A JUSTIFICATIONSeparation of concerns 

Caching 

Minimizes string parsing overhead

Code coloring 

Syntax checking

Reusable

Reduced payload 

Less abstraction

More at bitnative.com/2013/10/06/javascript-configuration-object-pattern/

Page 8: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

STAY DRY BY MAPPING

http://jsfiddle.net/housecor/uAe3k

Page 9: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

DATABINDING ADVANTAGES

Discoverability

Clarity

Less Code – Separation of tightly bound concerns without a strong interface abstracts rather than clarifies.

Page 10: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.
Page 11: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

AND PICK A LANGUAGE?!

Page 12: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

AND A TESTING FRAMEWORK…

Page 13: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.
Page 14: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

NETWORK TRANSPORT

AJAX

Go 2-way:

WebSocket

AJAX Long-polling

Adobe® Flash® Socket

AJAX multipart streaming

Forever Iframe

JSONP Polling

Or punt:

Page 15: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

SERVICE LAYER

WebAPI

Page 16: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

UTILITY LIBRARIES

Page 17: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

DATA

Page 18: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

NOSQL?

Page 19: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

CROSS BROWSER TESTING

Many options: http://bit.ly/16cXevo

XP-More

Page 20: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

WebAPI

ORMLite

MSTest

KnockoutJS Durandal RequireJS

KendoUI Knockout.Mapping Knockout-Kendo

Toastr jQuery QUnit

Page 21: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

1. Convention

2. Composition

<div data-bind=“compose: ‘viewmodels/vehicle’></div><!-- ko compose: ‘viewmodels/vehicle’ --><!-- /ko -->

3. Dependency Management

4. Routing

Page 22: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

REQUIREJS

• Utilizes AMD pattern

• Dynamically load JS

• Inject dependencies

• Watch for circular dependencies

Page 23: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

Tech Description Used for…jQuery (1.9 branch)

DOM manipulation library Hardly anything. Ajax calls.

Knockout Two-way binding, templating MVVM framework

Two way bindings, validation

Knockout-Kendo Custom Knockout binding library for KendoUI

Integrates KendoUI with Knockout via custom bindings.

Knockout mapping Converts JSON into an observable Knockout viewmodel

Saves time and keeps viewmodels lean. Simply say: ko.mapping.toJSON to convert all fields on a JS object into observables

KendoUI Web HTML5 UI component library Dialogs (though Durandal could handle this), comboboxes

Json2.js JSON serialization Serializing JS objects to JSON string in older browsers that don’t have native support

Toastr Notifications Showing save confirmations. Can also be used to show errors though not currently.

Durandal Convention based SPA framework for composing views/viewmodels with Knockout. Handles routing, transitions, project structure, etc. Makes Knockout competitive with Google’s AngularJS

Databinding views and viewmodels together via compose binding. Potentially useful for: 1. Routing if we ever start loading

separate pages without a postback2. Dialogs/notifications if we eliminate

KendoUI.3. Many other things. See docs.

RequireJS Dependency management – Bundled with Durandal

Page 24: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

DOM WEIGHT

Traditional: Every element is rendered on the server and thus on the client.

Client-side: Elements are rendered real-time as needed.

Page 25: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

KEY: CENTRALIZED AJAX CALLS

View

ViewModel

Service

AJAX service

Page 26: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.
Page 27: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

WHY?

Responsive

Rich Interactivity

Separation of concerns

Efficient

Simple - Less abstraction Debugging No compile wait

Faster page load

Page 28: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

WHY NOT?

Proprietary business logic

Low interactivity

Slower page load

Page is rarely called

Complex – Too many choices!

Debugging pain Runtime errors Cryptic One mistake and nothing loads

Page 29: REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | @housecor | speakerrate.com/talks/27181.

SPA EXPERIENCE COMPLETE

Back to the real world.

Cory House

bitnative.com

@housecor

speakerrate.com/talks/27181